def login(username, password, two_factor=None): """View helper function for logging in a user. Either authenticates a user and returns a ``Response`` or raises an ``AuthError``. :raises: AuthError on a bad login :returns: Redirect response to settings page on successful login. """ username = username.strip().lower() password = password.strip() if username and password: user = get_user( username=username, password=password ) if user: if not user.is_registered: raise LoginNotAllowedError('User is not registered.') if not user.is_claimed: raise LoginNotAllowedError('User is not claimed.') if 'twofactor' in settings.ADDONS_REQUESTED: tfa = user.get_addon('twofactor') if tfa and tfa.is_confirmed and not tfa.verify_code(two_factor): raise TwoFactorValidationError('Two-Factor auth does not match.') return authenticate(user, response=goback()) raise PasswordIncorrectError('Incorrect password attempt.')
def login(username, password): """View helper function for logging in a user. Either authenticates a user and returns a ``Response`` or raises an ``AuthError``. :raises: AuthError on a bad login :returns: Redirect response to settings page on successful login. """ username = username.strip().lower() password = password.strip() if username and password: user = get_user(username=username, password=password) if user: if not user.is_registered: raise LoginNotAllowedError('User is not registered.') if not user.is_claimed: raise LoginNotAllowedError('User is not claimed.') if user.is_disabled: raise LoginDisabledError('User is disabled.') if user_requires_two_factor_verification(user): return authenticate_two_factor(user) return authenticate(user, response=goback()) raise PasswordIncorrectError('Incorrect password attempt.')
def login(username, password, two_factor=None): """View helper function for logging in a user. Either authenticates a user and returns a ``Response`` or raises an ``AuthError``. :raises: AuthError on a bad login :returns: Redirect response to settings page on successful login. """ username = username.strip().lower() password = password.strip() if username and password: user = get_user(username=username, password=password) if user: if not user.is_registered: raise LoginNotAllowedError('User is not registered.') if not user.is_claimed: raise LoginNotAllowedError('User is not claimed.') if user.is_disabled: raise LoginDisabledError('User is disabled.') if 'twofactor' in settings.ADDONS_REQUESTED: tfa = user.get_addon('twofactor') if tfa and tfa.is_confirmed and not tfa.verify_code( two_factor): raise TwoFactorValidationError( 'Two-Factor auth does not match.') return authenticate(user, response=goback()) raise PasswordIncorrectError('Incorrect password attempt.')
def login(username, password): """View helper function for logging in a user. Either authenticates a user and returns a ``Response`` or raises an ``AuthError``. :raises: AuthError on a bad login :returns: Redirect response to settings page on successful login. """ username = username.strip().lower() password = password.strip() if username and password: user = get_user( username=username, password=password ) if user: if not user.is_registered: raise LoginNotAllowedError('User is not registered.') if not user.is_claimed: raise LoginNotAllowedError('User is not claimed.') if user.is_disabled: raise LoginDisabledError('User is disabled.') if user_requires_two_factor_verification(user): return authenticate_two_factor(user) return authenticate(user, response=goback()) raise PasswordIncorrectError('Incorrect password attempt.')