def login_view(): form = LoginForm(request.form) if request.method == 'POST' and form.validate(): user = load_user(form.data['shortname']) login_user(user) return redirect(url_for('index_view')) return render_template_with_models('login.html', form=form)
def login_view(): """ Renders a login page and redirects to the index on completion """ form = LoginForm(request.form) if request.method == 'POST' and form.validate(): user = get_user(form.data['shortname']) login_user(user) return redirect(url_for('admin.index')) return render_template_with_models('login.html', form=form)
def login(): ''' Wraps flask-login's login method. ''' form = LoginForm(request.form) if request.method == 'POST': if not form.validate(): flash('Invalid login information. Please try again.') else: email, password = request.form['email'], request.form['password'] if not User_.objects(email=email, password=password): flash("Incorrect credentials. Please try again.") else: admin = User(form.email.data, form.password.data) login_user(admin) return redirect(url_for('posts.admin')) return render_template('login.html', form=form)
def login(): err = '' status = 200 form = LoginForm(request.form) if request.method == 'POST' and form.validate(): user = mongo.db.users.find_one({'username': form.username.data}) if user and check_password_hash(user["password"], form.password.data): session["username"] = user["username"] session["authenticated"] = True session["isAdmin"] = user["admin"] if 'admin' in user else None return redirect(form.redirect.data) else: err = "Invalid username or password" if err: status = 401 redirect_url = request.args.get('redirect', '/') return make_response(render_template('login.html', err=err, redirect=redirect_url), status)