def token_login(token): """View function that handles passwordless login via a token""" try: user, next = login_by_token(token) except PasswordlessLoginError, e: if e.user: send_login_instructions(e.user, e.next) do_flash(str(e), 'error') return redirect(request.referrer or url_for('login'))
def confirm_email(token): """View function which handles a email confirmation request.""" after_this_request(_commit) try: user = confirm_by_token(token) except ConfirmationError, e: _logger.debug('Confirmation error: %s' % e) if e.user: send_confirmation_instructions(e.user) do_flash(str(e), 'error') confirm_error_url = get_url(_security.confirm_error_view) return redirect(confirm_error_url or url_for('send_confirmation'))
def login(): """View function for login view""" form = LoginForm(request.form, csrf_enabled=not app.testing) user, msg, confirm_url = None, None, None if request.json: form = LoginForm(MultiDict(request.json), csrf_enabled=not app.testing) if form.validate_on_submit(): try: user = _security.auth_provider.authenticate(form) except ConfirmationError, e: msg = str(e) confirm_url = url_for('send_confirmation', email=e.user.email) except BadCredentialsError, e: msg = str(e) form.password.errors.append(msg)