当前位置: 首页>>代码示例>>Python>>正文


Python UserMgr.get方法代码示例

本文整理汇总了Python中bookie.models.auth.UserMgr.get方法的典型用法代码示例。如果您正苦于以下问题:Python UserMgr.get方法的具体用法?Python UserMgr.get怎么用?Python UserMgr.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bookie.models.auth.UserMgr的用法示例。


在下文中一共展示了UserMgr.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: login

# 需要导入模块: from bookie.models.auth import UserMgr [as 别名]
# 或者: from bookie.models.auth.UserMgr import get [as 别名]
def login(request):
    """Login the user to the system

    If not POSTed then show the form
    If error, display the form with the error message
    If successful, forward the user to their /recent

    Note: the came_from stuff we're not using atm. We'll clean out if we keep
    things this way

    """
    login_url = route_url("login", request)
    referrer = request.url
    if referrer == login_url:
        referrer = u"/"  # never use the login form itself as came_from

    came_from = request.params.get("came_from", referrer)

    message = u""
    login = u""
    password = u""

    if "form.submitted" in request.params:
        login = request.params["login"]
        password = request.params["password"]

        LOG.debug(login)
        auth = UserMgr.get(username=login)
        LOG.debug(auth)
        LOG.debug(UserMgr.get_list())

        if auth and auth.validate_password(password) and auth.activated:
            # We use the Primary Key as our identifier once someone has
            # authenticated rather than the username.  You can change what is
            # returned as the userid by altering what is passed to remember.
            headers = remember(request, auth.id, max_age=60 * 60 * 24 * 30)
            auth.last_login = datetime.utcnow()

            # log the successful login
            AuthLog.login(login, True)

            # we're always going to return a user to their own /recent after a
            # login
            return HTTPFound(location=request.route_url("user_bmark_recent", username=auth.username), headers=headers)

        # log the right level of problem
        if auth and not auth.validate_password(password):
            message = "Your login attempt has failed."
            AuthLog.login(login, False, password=password)

        elif auth and not auth.activated:
            message = "User account deactivated. Please check your email."
            AuthLog.login(login, False, password=password)
            AuthLog.disabled(login)

        elif auth is None:
            message = "Failed login"
            AuthLog.login(login, False, password=password)

    return {"message": message, "came_from": came_from, "login": login, "password": password}
开发者ID:EdwardNavarro,项目名称:Bookie,代码行数:62,代码来源:auth.py

示例2: invite_user

# 需要导入模块: from bookie.models.auth import UserMgr [as 别名]
# 或者: from bookie.models.auth.UserMgr import get [as 别名]
def invite_user(request):
    """Invite a new user into the system.

    :param username: user that is requested we invite someone
    :param email: email address of the new user

    """
    params = request.params

    email = params.get('email', None)
    user = request.user

    if not email:
        # try to get it from the json body
        email = request.json_body.get('email', None)

    if not email:
        # if still no email, I give up!
        request.response.status_int = 406
        return {
            'username': user.username,
            'error': "Please submit an email address"
        }

    # first see if the user is already in the system
    exists = UserMgr.get(email=email)
    if exists:
        request.response.status_int = 406
        return {
            'username': exists.username,
            'error': "This user is already a Bookie user!"
        }

    new_user = user.invite(email)
    if new_user:
        LOG.error(new_user.username)
        # then this user is able to invite someone
        # log it
        AuthLog.reactivate(new_user.username)

        # and then send an email notification
        # @todo the email side of things
        settings = request.registry.settings
        msg = InvitationMsg(new_user.email,
                            "Enable your Bookie account",
                            settings)

        msg.send(request.route_url('reset',
            username=new_user.username,
            reset_key=new_user.activation.code))
        return {
            'message': 'You have invited: ' + new_user.email
        }
    else:
        # you have no invites
        request.response.status_int = 406
        return {
            'username': user.username,
            'error': "You have no invites left at this time."
        }
开发者ID:cambot,项目名称:Bookie,代码行数:62,代码来源:api.py

示例3: suspend_acct

# 需要导入模块: from bookie.models.auth import UserMgr [as 别名]
# 或者: from bookie.models.auth.UserMgr import get [as 别名]
def suspend_acct(request):
    """Reset a user account to enable them to change their password"""
    params = request.params
    user = request.user

    # we need to get the user from the email
    email = params.get('email', None)

    if email is None and hasattr(request, 'json_body'):
        # try the json body
        email = request.json_body.get('email', None)

    if user is None and email is None:
        request.response.status_int = 406
        return {
            'error':  "Please submit an email address",
        }

    if user is None and email is not None:
        user = UserMgr.get(email=email)

    if user is None:
        request.response.status_int = 404
        return {
            'error':  "Please submit a valid address",
            'email': email
        }

    # check if we've already gotten an activation for this user
    if user.activation is not None:
        request.response.status_int = 406
        return {
            'error':  """You've already marked your account for reactivation.
Please check your email for the reactivation link. Make sure to
check your spam folder.""",
            'username': user.username,
        }

    # mark them for reactivation
    user.reactivate("FORGOTTEN")

    # log it
    AuthLog.reactivate(user.username)

    # and then send an email notification
    # @todo the email side of things
    settings = request.registry.settings
    msg = ReactivateMsg(user.email,
                        "Activate your Bookie account",
                        settings)

    msg.send(request.route_url('reset',
                         username=user.username,
                         reset_key=user.activation.code))

    return {
        'message':  """Your account has been marked for reactivation. Please
                    check your email for instructions to reset your
                    password""",
    }
开发者ID:cambot,项目名称:Bookie,代码行数:62,代码来源:api.py

示例4: test_get_username

# 需要导入模块: from bookie.models.auth import UserMgr [as 别名]
# 或者: from bookie.models.auth.UserMgr import get [as 别名]
 def test_get_username(self):
     """Fetching the user by the username"""
     user = UserMgr.get(username='admin')
     eq_(user.id, 1,
         "Should have a user id of 1: " + str(user.id))
     eq_(user.username, 'admin',
         "Should have a username of admin: " + user.username)
开发者ID:Cfhansen,项目名称:Bookie,代码行数:9,代码来源:test_model.py

示例5: signup_process

# 需要导入模块: from bookie.models.auth import UserMgr [as 别名]
# 或者: from bookie.models.auth.UserMgr import get [as 别名]
def signup_process(request):
    """Process the signup request

    If there are any errors drop to the same template with the error
    information.

    """
    params = request.params
    email = params.get('email', None)

    if not email:
        # if still no email, I give up!
        return {
            'errors': {
                'email': 'Please supply an email address to sign up.'
            }
        }

    # first see if the user is already in the system
    exists = UserMgr.get(email=email)
    if exists:
        return {
            'errors': {
                'email': 'The user has already signed up.'
            }
        }

    new_user = UserMgr.signup_user(email, 'signup')
    if new_user:
        # then this user is able to invite someone
        # log it
        AuthLog.reactivate(new_user.username)

        # and then send an email notification
        # @todo the email side of things
        settings = request.registry.settings

        # Add a queue job to send the user a notification email.
        tasks.email_signup_user.delay(
            new_user.email,
            "Enable your Bookie account",
            settings,
            request.route_url(
                'reset',
                username=new_user.username,
                reset_key=new_user.activation.code
            )
        )

        # And let the user know they're signed up.
        return {
            'message': 'Thank you for signing up from: ' + new_user.email
        }
    else:
        return {
            'errors': {
                'email': 'There was an unknown error signing up.'
            }
        }
开发者ID:Cfhansen,项目名称:Bookie,代码行数:61,代码来源:auth.py

示例6: test_get_id

# 需要导入模块: from bookie.models.auth import UserMgr [as 别名]
# 或者: from bookie.models.auth.UserMgr import get [as 别名]
 def test_get_id(self):
     """Fetching user by the id"""
     # the migration adds an initial admin user to the system
     user = UserMgr.get(user_id=1)
     eq_(user.id, 1,
         "Should have a user id of 1: " + str(user.id))
     eq_(user.username, 'admin',
         "Should have a username of admin: " + user.username)
开发者ID:Cfhansen,项目名称:Bookie,代码行数:10,代码来源:test_model.py

示例7: test_get_bad_user

# 需要导入模块: from bookie.models.auth import UserMgr [as 别名]
# 或者: from bookie.models.auth.UserMgr import get [as 别名]
    def test_get_bad_user(self):
        """We shouldn't get a hit if the user is inactive"""
        user = UserMgr.get(username=u'noexist')

        self.assertEqual(
            user,
            None,
            "Should not find a non-existant user: " + str(user))
开发者ID:BraindeadCrew,项目名称:Bookie,代码行数:10,代码来源:test_model.py

示例8: user

# 需要导入模块: from bookie.models.auth import UserMgr [as 别名]
# 或者: from bookie.models.auth.UserMgr import get [as 别名]
 def user(self):
     # <your database connection, however you get it, the below line
     # is just an example>
     # dbconn = self.registry.settings['dbconn']
     user_id = unauthenticated_userid(self)
     if user_id is not None:
         # this should return None if the user doesn't exist
         # in the database
         user = UserMgr.get(user_id=user_id)
         return user
开发者ID:BraindeadCrew,项目名称:Bookie,代码行数:12,代码来源:access.py

示例9: account_activate

# 需要导入模块: from bookie.models.auth import UserMgr [as 别名]
# 或者: from bookie.models.auth.UserMgr import get [as 别名]
def account_activate(request):
    """Reset a user after being suspended

    :param username: required to know what user we're resetting
    :param activation: code needed to activate
    :param password: new password to use for the user

    """
    params = request.params

    username = params.get('username', None)
    activation = params.get('code', None)
    password = params.get('password', None)
    new_username = params.get('new_username', None)

    if username is None and activation is None and password is None:
        # then try to get the same fields out of a json body
        json_body = request.json_body
        username = json_body.get('username', None)
        activation = json_body.get('code', None)
        password = json_body.get('password', None)
        new_username = json_body.get('new_username', None)

    if not UserMgr.acceptable_password(password):
        request.response.status_int = 406
        return {
            'error': "Come on, pick a real password please",
        }

    res = ActivationMgr.activate_user(username, activation, password)

    if res:
        # success so respond nicely
        AuthLog.reactivate(username, success=True, code=activation)

        # if there's a new username and it's not the same as our current
        # username, update it
        if new_username and new_username != username:
            try:
                user = UserMgr.get(username=username)
                user.username = new_username
            except IntegrityError, exc:
                request.response.status_int = 500
                return {
                    'error': 'There was an issue setting your new username',
                    'exc': str(exc)
                }

        return {
            'message': "Account activated, please log in.",
            'username': username,
        }
开发者ID:cambot,项目名称:Bookie,代码行数:54,代码来源:api.py

示例10: account

# 需要导入模块: from bookie.models.auth import UserMgr [as 别名]
# 或者: from bookie.models.auth.UserMgr import get [as 别名]
def account(request):
    """Index of account page

    You can only load your own account page. If you try to view someone else's
    you'll just end up with your own.

    """
    # if auth fails, it'll raise an HTTPForbidden exception
    with ReqAuthorize(request):
        user = UserMgr.get(username=request.user.username)

        return {
            'user': user,
            'username': user.username,
        }
开发者ID:BraindeadCrew,项目名称:Bookie,代码行数:17,代码来源:accounts.py

示例11: user

# 需要导入模块: from bookie.models.auth import UserMgr [as 别名]
# 或者: from bookie.models.auth.UserMgr import get [as 别名]
    def user(self):
        # <your database connection, however you get it, the below line
        # is just an example>
        # dbconn = self.registry.settings['dbconn']
        LOG.debug('in Request with Attribute')
        user_id = unauthenticated_userid(self)
        LOG.debug(user_id)
        if user_id is not None:
            LOG.debug('user_id is not none')

            # this should return None if the user doesn't exist
            # in the database
            user = UserMgr.get(user_id=user_id)
            LOG.debug(user)
            return user
开发者ID:aldeka,项目名称:Bookie,代码行数:17,代码来源:access.py

示例12: home

# 需要导入模块: from bookie.models.auth import UserMgr [as 别名]
# 或者: from bookie.models.auth.UserMgr import get [as 别名]
def home(request):
    """Inital / view for now until we find a better one"""
    rdict = request.matchdict
    username = rdict.get('username', None)

    if not username:
        return HTTPFound(location=request.route_url("bmark_recent"))
    else:
        # we need to see if we have a user by this name
        user = UserMgr.get(username=username)

        if not user:
            return HTTPNotFound()
        else:
            return HTTPFound(location=request.route_url("user_bmark_recent",
                                                        username=username))
开发者ID:aldeka,项目名称:Bookie,代码行数:18,代码来源:__init__.py

示例13: del_user

# 需要导入模块: from bookie.models.auth import UserMgr [as 别名]
# 或者: from bookie.models.auth.UserMgr import get [as 别名]
def del_user(request):
    """Remove a bad user from the system via the api.

    For admin use only.

    Removes all of a user's bookmarks before removing the user.

    """
    mdict = request.matchdict

    # Submit a username.
    del_username = mdict.get('username', None)

    if del_username is None:
        LOG.error('No username to remove.')
        request.response.status_int = 400
        return _api_response(request, {
            'error': 'Bad Request: No username to remove.',
        })

    u = UserMgr.get(username=del_username)

    if not u:
        LOG.error('Username not found.')
        request.response.status_int = 404
        return _api_response(request, {
            'error': 'User not found.',
        })

    try:
        # Delete all of the bmarks for this year.
        Bmark.query.filter(Bmark.username == u.username).delete()
        DBSession.delete(u)
        return _api_response(request, {
            'success': True,
            'message': 'Removed user: ' + del_username
        })
    except Exception, exc:
        # There might be cascade issues or something that causes us to fail in
        # removing.
        LOG.error(exc)
        request.response.status_int = 500
        return _api_response(request, {
            'error': 'Bad Request: ' + str(exc)
        })
开发者ID:BraindeadCrew,项目名称:Bookie,代码行数:47,代码来源:api.py

示例14: reset_password

# 需要导入模块: from bookie.models.auth import UserMgr [as 别名]
# 或者: from bookie.models.auth.UserMgr import get [as 别名]
def reset_password(username, password):
    """Reset a user's password"""
    require('hosts', provided_by=[sample])
    require('ini', provided_by=[sample])

    parse_ini(env["ini_file"])

    import transaction
    from bookie.models import initialize_sql
    initialize_sql(dict(env.ini.items('app:main')))

    from bookie.models import DBSession
    from bookie.models.auth import UserMgr
    sess = DBSession()

    u = UserMgr.get(username=username)
    u.password = password
    sess.flush()
    transaction.commit()
开发者ID:aldeka,项目名称:Bookie,代码行数:21,代码来源:admin.py

示例15: reset

# 需要导入模块: from bookie.models.auth import UserMgr [as 别名]
# 或者: from bookie.models.auth.UserMgr import get [as 别名]
def reset(request):
    """Once deactivated, allow for changing the password via activation key"""
    rdict = request.matchdict
    params = request.params

    # This is an initial request to show the activation form.
    username = rdict.get('username', None)
    activation_key = rdict.get('reset_key', None)
    user = ActivationMgr.get_user(username, activation_key)

    if user is None:
        # just 404 if we don't have an activation code for this user
        raise HTTPNotFound()

    if 'code' in params:
        # This is a posted form with the activation, attempt to unlock the
        # user's account.
        username = params.get('username', None)
        activation = params.get('code', None)
        password = params.get('new_password', None)
        new_username = params.get('new_username', None)
        error = None

        if not UserMgr.acceptable_password(password):
            # Set an error message to the template.
            error = "Come on, pick a real password please."
        else:
            res = ActivationMgr.activate_user(username, activation, password)
            if res:
                # success so respond nicely
                AuthLog.reactivate(username, success=True, code=activation)

                # if there's a new username and it's not the same as our current
                # username, update it
                if new_username and new_username != username:
                    try:
                        user = UserMgr.get(username=username)
                        user.username = new_username
                    except IntegrityError, exc:
                        error = 'There was an issue setting your new username'
            else:
                AuthLog.reactivate(username, success=False, code=activation)
                error = 'There was an issue attempting to activate this account.'
开发者ID:Cfhansen,项目名称:Bookie,代码行数:45,代码来源:auth.py


注:本文中的bookie.models.auth.UserMgr.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。