def login(): if current_user.is_authenticated: return redirect(url_for('main.home')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email = form.email.data).first() if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember = form.remember.data) next_page = request.args.get('next') return redirect(next_page) if next_page else redirect(url_for('main.home')) else: flash("Login Unsuccesful!!!", 'danger') return render_template('login.html', title = 'Login', form = form)
def login(): form = LoginForm() if form.validate_on_submit(): # if form.email.data == '*****@*****.**' and form.password.data == 'tej': # flash(f'Logged in as {form.email.data} !!! ', category='success') # return redirect(url_for('home')) # else: user = User.query.filter_by(email=form.email.data).first() if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=form.rememberMe.data) next_page = request.args.get('next') flash(f'Logged in as {user.username} !!! ', category='success') return redirect(next_page) if next_page else redirect(url_for('main.home')) else: flash(f'Login failed', category='danger') return render_template('login.html', title="Login", form=form)
def login(): if current_user.is_authenticated: return redirect(url_for("main.home")) form = LoginForm() posts = Post.query.all() if form.validate_on_submit(): user = User.query.filter_by(email=str(form.email.data).lower()).first() if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) usersLoggedIn(user.username, user.id, user.administrator) next_page = request.args.get("next") return redirect(next_page) if next_page else redirect( url_for("main.home")) else: flash("Login unsuccessful. Please check email and password!", "danger") return render_template("login.html", title="Login", form=form, posts=posts)