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


Python auth.UserMgr类代码示例

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


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

示例1: login

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,代码行数:60,代码来源:auth.py

示例2: signup_process

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,代码行数:59,代码来源:auth.py

示例3: testSignupWorks

    def testSignupWorks(self):
        """Signing up stores an activation."""
        email = '[email protected]'
        UserMgr.signup_user(email, 'testcase')

        activations = Activation.query.all()

        self.assertTrue(len(activations) == 1)
        act = activations[0]

        self.assertEqual(email, act.user.email,
            "The activation email is the correct one.")
开发者ID:cambot,项目名称:Bookie,代码行数:12,代码来源:test_signup.py

示例4: account_activate

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,代码行数:52,代码来源:api.py

示例5: test_get_username

 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,代码行数:7,代码来源:test_model.py

示例6: account_activate

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)

    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)
        return {
            'message': "Account activated, please log in.",
            'username': username,
        }
    else:
        AuthLog.reactivate(username, success=False, code=activation)
        request.response.status_int = 500
        return {
            'error': "There was an issue attempting to activate this account.",
        }
开发者ID:lmorchard,项目名称:Bookie,代码行数:35,代码来源:api.py

示例7: suspend_acct

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,代码行数:60,代码来源:api.py

示例8: invite_user

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,代码行数:60,代码来源:api.py

示例9: accounts_invites

def accounts_invites(request):
    """Return a list of the accounts that aren't activated."""
    user_list = UserMgr.get_list()
    ret = {
        'users': [(u.username, u.invite_ct) for u in user_list],
    }
    return ret
开发者ID:cambot,项目名称:Bookie,代码行数:7,代码来源:api.py

示例10: test_get_id

 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,代码行数:8,代码来源:test_model.py

示例11: accounts_inactive

def accounts_inactive(request):
    """Return a list of the accounts that aren't activated."""
    user_list = UserMgr.get_list(active=False)
    ret = {
        'count': len(user_list),
        'users': [dict(h) for h in user_list],
    }
    return ret
开发者ID:cambot,项目名称:Bookie,代码行数:8,代码来源:api.py

示例12: test_get_bad_user

    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,代码行数:8,代码来源:test_model.py

示例13: _get_userlist

def _get_userlist(args):
    """Fetch a list of users from the system and output to stdout"""
    _init_sql(args)

    for user in UserMgr.get_list():
        print("{0:<10} {1:<20} {2:<50}".format(
            user.username,
            user.name,
            user.email))
开发者ID:cambot,项目名称:Bookie,代码行数:9,代码来源:usermgr.py

示例14: reset

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,代码行数:43,代码来源:auth.py

示例15: user

 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,代码行数:10,代码来源:access.py


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