def clean_user_id(self): ''' Form validation to check if the user id already exist in the database. https://docs.djangoproject.com/en/1.6/ref/forms/validation/#cleaning-a-specific-field-attribute ''' cleaned_data = super(RegisterForm, self).clean() user_id = cleaned_data["user_id"] check_user = db.emailExists(user_id) if check_user == None: return user_id else: return None
def authenticate(username=None, password=None): # check the username/password and return a User user = db.emailExists(username) if user != None: hashed_pw = user.password #check password. if the password matches, return a #User object with associated information if bcrypt.hashpw(password, hashed_pw) == hashed_pw: user_obj = {} user_obj['user_id'] = user.user_id user_obj['password'] = user.password user_obj['admin'] = user.admin return user_obj else: return None