Coverage for bookie.models.auth : 87%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Sample SQLAlchemy-powered model definition for the repoze.what SQL plugin.
This model definition has been taken from a quickstarted TurboGears 2 project, but it's absolutely independent of TurboGears.
"""
'tuvwxyz0123456789/&='))
def count(): """Count how many activations are in the system.""" return Activation.query.count()
def get_user(username, code): """Get the user for this code""" qry = Activation.query.\ filter(Activation.code == code).\ filter(User.username == username)
res = qry.first()
if res is not None: return res.user else: return None
def activate_user(username, code, new_pass): """Given this code get the user with this code make sure they exist"""
filter(Activation.code == code).\ filter(User.username == username)
else: return None
"""Handle activations/password reset items for users
The id is the user's id. Each user can only have one valid activation in process at a time
The code should be a random hash that is valid only one time After that hash is used to access the site it'll be removed
The created by is a system: new user registration, password reset, forgot password, etc.
"""
DateTime, default=lambda: datetime.utcnow + ACTIVATION_AGE)
"""Create a new activation"""
def _gen_activation_hash(): """Generate a random activation hash for this user account""" # for now just cheat and generate an api key, that'll work for now
"""Remove this activation"""
""" Wrapper for static/combined operations of User object"""
def count(): """Number of users in the system.""" return User.query.count()
"""Get a list of all of the user accounts"""
user_query = user_query.order_by(getattr(User, order)) else:
user_query = user_query.limit(limit)
"""Get the user instance for this information
:param user_id: integer id of the user in db :param username: string user's name :param inactive: default to only get activated true
"""
return None
def auth_groupfinder(userid, request): """Pyramid wants to know what groups a user is in
We need to pull this from the User object that we've stashed in the request object
""" user = request.user if user is not None: if user.is_admin: return 'admin' else: return 'user' return None
def acceptable_password(password): """Verify that the password is acceptable
Basically not empty, has more than 3 chars...
"""
return False
return False
def signup_user(email, signup_method): # Get this invite party started, create a new user acct.
# they need to be deactivated
# decrement the invite counter
"""Basic User def"""
Activation, cascade="all, delete, delete-orphan", uselist=False, backref='user')
"""By default a user starts out deactivated"""
"""Hash password on the fly."""
else:
# Hash a password for the first time, with a randomly-generated salt
# Make sure the hased password is an UTF-8 object at the end of the # process because SQLAlchemy _wants_ a unicode object for Unicode # fields
"""Return the password hashed"""
_set_password))
""" Check the password against existing credentials.
:param password: the password that was provided by the user to try and authenticate. This is the clear text version that we will need to match against the hashed one in the database. :type password: unicode object. :return: Whether the password is valid.
""" # the password might be null as in the case of morpace employees # logging in via ldap. We check for that here and return them as an # incorrect login else: return False
"""Return safe data to be sharing around""" [(k, v) for k, v in dict(self).iteritems() if k not in hide] )
"""In case we need to disable the login""" self.activated = False
"""Put the account through the reactivation process
This can come about via a signup or from forgotten password link
""" # if we reactivate then reinit this
"""Does the user have any invitations left"""
"""Invite a user""" raise ValueError('You must supply an email address to invite') else: # get this invite party started, create a new useracct
# decrement the invite counter
def gen_api_key(): """Generate a 12 char api key for the user to use""" |