def authn(): email, name = oauth.get_email(request) succ, stat = auth.try_login(email, name) if not succ: abort(400, stat) response.set_cookie("auth", stat) redirect("/")
def api_login(error=None): content = request.get_json(silent=True) username = content.get('username') password = content.get('password') if auth.try_login(username, password): new_token = auth.generate_token(username) response = {'status': 'success', 'token': new_token} return jsonify(**response) else: raise InvalidRequestData('Invalid username or password (mismatched).')
def login(error=None): """Loads the login page or performs login.""" if request.method == 'POST': username = request.form.get('username') password = request.form.get('password') if auth.try_login(username, password): session['username'] = username return redirect(url_for('home')) else: return redirect(url_for('login', error='Wrong username or password.')) else: if 'username' in session: return redirect(url_for('home')) return render_template('login.j2', error_message=error, show_menu=False, show_refresh=False)