def registration(): form = RegistrationForm() if form.validate_on_submit(): db_sess = db_session.create_session() if db_sess.query(Users).filter(Users.email == form.email.data).first(): return render_template('registration.html', title='Registration', form=form, message='Такой пользователь уже зарегистрирован.') user = Users() user.email = form.email.data user.surname = form.surname.data user.name = form.name.data user.age = form.age.data user.position = form.position.data user.speciality = form.speciality.data user.address = form.address.data user.set_password(form.password_1.data) db_sess.add(user) db_sess.commit() login_user(user, remember=True) db_sess.close() return redirect('/') return render_template('registration.html', title='Registration', form=form)
def add_data(form): session = create_session() user = Users() user.email = form.email.data user.name = form.name.data user.surname = form.surname.data user.password = hash_password(form.password.data) session.add(user) session.commit()