示例#1
0
 def test_check_password(self):
     """Check password."""
     user = User.create(username='******',
                        email='*****@*****.**',
                        password='******')
     assert user.check_password('foobarbaz123') is True
     assert user.check_password('barfoobaz') is False
示例#2
0
def save_user(username, first_name, last_name, email, roles):
    # First check if user is already in DB, and create if not, and update if is
    user = User.get_by_username(username)
    if not user:
        # Create new user if not in database
        user = User.create(username=username,
                           first_name=first_name,
                           last_name=last_name,
                           email=email,
                           roles=roles)
    elif user.first_name != first_name or user.last_name != last_name or user.email != email or user.roles != roles:
        # Update user if details have changed. Username should never change
        user.first_name = first_name
        user.last_name = last_name
        user.email = email
        user.roles = roles
        user = User.update(user)
    return user