def registration():
if g.user is not None and g.user.is_authenticated():
flash('Please Log out before registration')
return redirect(url_for('index'))
form = RegistrationForm()
if request.method == 'POST' and form.validate_on_submit():
""" check is it avaliable login """
if User.query.filter_by(login=form.login.data).first():
""" Create error message """
flash('Choose another login', 'error')
else:
""" Add new user to DB """
new_user = User(login=form.login.data,
password=bcrypt.generate_password_hash(form.password.data),
name=form.name.data,
surname=form.surname.data)
db.session.add(new_user)
db.session.commit()
""" Success message """
flash('Done')
return redirect(url_for("login"))
return render_template('registration.html',
title='Registration',
form=form)
评论列表
文章目录