Exemple #1
0
def login():
    login_form = LoginForm()
    if login_form.validate_on_submit():
        user_name = login_form.username.data
        password = login_form.password.data
        users_model = UsersModel(db.get_connection())

        pwd = users_model.get(user_name=user_name)
        if pwd and pwd[0]:
            if check_password_hash(pwd[2], password):
                session['username'] = user_name
                session['user_id'] = pwd[0]
        return redirect("/index")
    return render_template('login.html', title='Авторизация', form=login_form)
Exemple #2
0
def sign_in():
    sign_in_form = SignInForm()
    if sign_in_form.validate_on_submit():
        user_name = sign_in_form.username.data
        password = generate_password_hash(sign_in_form.password.data)
        users_model = UsersModel(db.get_connection())
        if not users_model.get(user_name=user_name):

            user_id = users_model.insert(user_name, password)
            session['username'] = user_name
            session['user_id'] = user_id

            return redirect("/index")
    return render_template("sign_in.html",
                           title="Зарегестрироваться",
                           form=sign_in_form)