Advertisement
Guest User

Untitled

a guest
Jan 8th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. def login():
  2. form = LoginForm()
  3. error = None
  4.  
  5. if request.method == 'GET' and request.args.get('next'):
  6. session['next'] = request.args.get('next')
  7.  
  8. if form.validate_on_submit():
  9. user = User.objects.filter(
  10. username=form.username.data
  11. ).first()
  12. if user:
  13. if bcrypt.hashpw(form.password.data, user.password) == user.password:
  14. session['username'] = form.username.data
  15. if 'next' in session:
  16. next = session.get('next')
  17. session.pop('next')
  18. return redirect(next)
  19. else:
  20. return redirect(url_for('user_app.profile',username=form.username.data))
  21. else:
  22. user = None
  23. if not user:
  24. error = 'Incorrect credentials'
  25. return render_template('user/login.html', form=form, error=error)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement