Beispiel #1
0
def login():
	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('home'))
		else:
			flash('Email or Password is Incorrect!', 'danger')
	return render_template('login.html', title='Login', form=form)
Beispiel #2
0
def account():
	form = ChangePassword()
	if form.validate_on_submit():
		user = User.query.filter_by(id=current_user.id).first()
		if user and bcrypt.check_password_hash(user.password, form.old_password.data):
			message = 'Successfully updated your password!'
			send_email('Password changed!', '*****@*****.**', [user.email], message, message)
			flash('Password updated successfully!', 'success')
			return redirect(url_for('account'))
		else:
			flash('Old password is incorrect!', 'danger')
	return render_template('account.html', title='Login', form=form)
def login():
    if current_user.is_authenticated:
        return redirect("/")

    form = login_form()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user)
            return redirect("/")

    return render_template("login.html", form=form)
Beispiel #4
0
    def validate_email(form, field):

        user = User.query.filter_by(email=field.data).first()

        if user == None:
            raise ValueError("Your credentials do not match with our records")

        if form.password.data == "" or bcrypt.check_password_hash(
                user.password, form.password.data) == False:
            raise ValueError("Your credentials do not match with our records")

        if user.email_verified_at == None:
            raise ValueError("You must validate your email before login")
Beispiel #5
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']
        user = User.query.filter_by(email=email).first()
        if user and bcrypt.check_password_hash(user.password, password):
            login_user(user, remember=True)
            return make_response({'data': 'redirect'})
        else:
            return make_response({'data': 'true'})
    else:
        return render_template('login.html')
Beispiel #6
0
 def validate_current_password(form, field):
     if not bcrypt.check_password_hash(current_user.password, field.data):
         raise ValueError("You must provide your current password")