def login(): form = LoginForm() if form.validate_on_submit(): user_name = form.username.data password = form.password.data user_model = UserModel(db.get_connection()) exists = user_model.exists(user_name, password) print(exists) if (exists[0]): session['username'] = user_name session['user_id'] = exists[1] current_user_mode = exists[2] return redirect("/index") return render_template('login.html', title='Авторизация', form=form)
def register(): form = RegisterForm() if form.validate_on_submit(): name = form.username.data password = form.password.data passwordagain = form.password_again.data email = form.email.data user_type = form.mode.data if password == passwordagain: um = UserModel(db.get_connection()) um.insert(name, password, email, user_type) exi = um.exists(name, password) session['username'] = name session['user_id'] = exi[1] return redirect("/succes_register") else: return redirect("/passw_dont_match") return render_template('register.html', form=form)