def registration(): form = RegistrationForm() if form.validate_on_submit(): db_sess = db_session.create_session() if db_sess.query(User).filter(User.email == form.email.data).first(): return render_template( 'registration.html', title='Регистрация', form=form, message='Пользователь с такой почтой уже зарегистрирован') user = User(surname=form.surname.data, name=form.name.data, age=form.age.data, position=form.position.data, speciality=form.speciality.data, address=form.address.data, email=form.email.data, city_from=form.city.data) user.set_password(form.password.data) db_sess.add(user) db_sess.commit() login_user(user) return redirect('/') return render_template('registration.html', title='Регистрация', form=form)
def post(self): args = parser.parse_args() session = db_session.create_session() user = User() user.id = args['id'] user.name = args['name'] user.email = args['email'] user.role = args['role'] user.avatar_path = args['avatar_path'] user.set_password(args['password']) session.add(user) session.commit() return jsonify({'message': 'SUCCESS'})