Guest User

Untitled

a guest
Sep 3rd, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. # form is submitted via a POST request to the /register route
  2. @app.route('/register', methods=['GET', 'POST'])
  3. def register():
  4. # this is using a class created using WTForms
  5. form = RegForm()
  6. if request.method == 'POST':
  7. # form is validated via WTForms .validate() method
  8. if form.validate():
  9. # checks if submitted email has already been registered
  10. existing_user = User.objects(email=form.email.data).first()
  11. if existing_user is None:
  12. # the password is hashed using generate_password_hash function from werkzeug.security.
  13. hashpass = generate_password_hash(form.password.data, method='sha256')
  14. # users credentials are saved to database
  15. hey = User(form.email.data,hashpass).save()
  16. # login_user function from flask_login logs the user in
  17. login_user(hey)
  18. # user is then redirected to the dashboard route
  19. return redirect(url_for('dashboard'))
  20. return render_template('register.html', form=form)
Add Comment
Please, Sign In to add comment