Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. class RegistrationForm(Form):
  2. username = TextField('Username', [validators.Length(min=4, max=20)])
  3. email = TextField('Email Address', [validators.Length(min=6, max=50), validators.Email()])
  4. password = PasswordField('Password', [validators.DataRequired(), validators.EqualTo('confirm', message='Password is wrong')])
  5. confirm = PasswordField('Repeat Password')
  6. accept_tos = BooleanField('I agree to this <a href="/tos">this</a>', [validators.DataRequired()])
  7.  
  8.  
  9. @app.route("/register/", methods=['GET', 'POST'])
  10. def register_page():
  11. try:
  12. form = RegistrationForm(request.form)
  13. if request.method == 'POST' and form.validate():
  14. username = form.username.data
  15. email = form.email.data
  16. password = sha256_crypt.encrypt((str(form.password.data)))
  17.  
  18. user = User(username, password, email, 'None', 'None', 1)
  19. db.session.add(user)
  20. db.session.commit()
  21. flash('Thx for registration')
  22.  
  23. return redirect(url_for('dashboard'))
  24. return render_template("register.html", form=form)
  25.  
  26. except Exception as e:
  27. return(str(e))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement