def Login():
    if request.method == 'POST':
        email = str(request.form['email'])
        password = str(request.form['password'])
        button = request.form['button']
        if button == "Login":
            if email == "":
                return redirect(url_for("Error"))
            password2 = db.getPassword(email)
            broname = db.getUser(email)
            if password2 == password:
                return redirect(url_for("restaurantSearch", broname=broname))
            else:
                return redirect(url_for("Login"))
        if button == 'Signup':
            return redirect(url_for("Signup"))
    else:
        return render_template('Login.html')
def user(broname): 
    if request.method == 'POST':
        newBroname = request.form['newBroname']
        oldPassword = str(request.form['oldPassword'])
        newPassword = str(request.form['newPassword'])
        button = request.form['button']
        if button == 'newName':
            db.changeBroname(broname, newBroname)
            return redirect(url_for("user", broname=newBroname))
        if button == 'newPass':
            email = db.getEmail(broname)
            oldPassword2 = db.getPassword(email)
            if oldPassword2 == oldPassword:
                db.changePassword(broname, newPassword)
                return redirect(url_for("Login"))
            else:
                return redirect(url_for("user", broname=broname))
    else:
        return render_template('user.html')   
示例#3
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        email = form.email.data
        unhashedPassword = form.password.data
        hashedPassword = db.getPassword(email)

        print("PASSWORDS", file=sys.stderr)
        print(unhashedPassword, file=sys.stderr)
        print(hashedPassword, file=sys.stderr)

        if bcrypt.check_password_hash(hashedPassword[0].decode(),
                                      unhashedPassword):
            signedIn = User(email)
            login_user(signedIn)
            return redirect(url_for('browse'))
        else:
            flash(
                'Incorrect login information. Try again or register for an account',
                'error')
            return redirect(url_for('login'))

    return render_template('login.html', title='Login', form=form)