Advertisement
Guest User

Untitled

a guest
Apr 15th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. class LoginForm(Form):
  2. #username and password text boxes and a submit button
  3. username = StringField('username', validators=[DataRequired()])
  4. password = PasswordField('password', validators=[DataRequired()])
  5. submit = SubmitField('Log In')
  6.  
  7. # Response to a POST triggered by clicking the submit button
  8. def post(self):
  9. # Check that the submit button was clicked (not necessary: it's the only button, but hey)
  10. if self.submit.data:
  11. session = Database.DataSession()
  12. # Validate username and password
  13. if session.query(User).filter(and_(User.username==self.username.data, User.password == self.password.data)).count() > 0:
  14. session['valid'] = True
  15. return redirect("/main")
  16. else:
  17. return redirect("/")
  18.  
  19. # Response to a GET request
  20. def get(self):
  21. return render_template('login.html',
  22. title='Sign In',
  23. year=datetime.now().year,
  24. form=self)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement