Guest User

Untitled

a guest
Jan 17th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. from __future__ import with_statement
  2. from sqlite3 import dbapi2 as sqlite3
  3. from flask import Flask, request, session, g, redirect, url_for, abort, \
  4. render_template, flash
  5. from conf import appconf.cfg
  6. from flaskext.bcrypt import bcrypt_init, generate_password_hash, \
  7. check_password_hash
  8. from flaskext.wtf import Form, TextField, TextAreaField, PasswordField, \
  9. SubmitField, Required, ValidationError, validators
  10. from wtforms import Form, BooleanField, TextField, validators
  11.  
  12. import os
  13.  
  14. app = Flask(__name__)
  15. app.config.from_object(appconf.cfg)
  16.  
  17. bcrypt_init(app)
  18.  
  19.  
  20.  
  21. class LoginForm (wtf.Form):
  22.  
  23. email = wtf.TextField("Email",[validators.Length(min=8, max=40)])
  24. password = wtfPasswordField("Password",[validators.Length(min=6, max=20)])
  25. submit = SubmitField("Let me in")
  26. forgotPassword = TextField("Email")
  27.  
  28. def validate_email(self,email):
  29. check_user = Users.query.filter_by(email = email.data).first()
  30. if check_user is None: #if there is no one by that email
  31. raise ValidationError, "Nope, nobody by that email"
  32.  
  33.  
  34. def connect_db():
  35. return sqlite3.connect(app.config['DATABASE'])
  36.  
  37.  
  38. @app.before_request
  39. def before_request():
  40. g.db = connect_db()
  41.  
  42.  
  43. @app.after_request
  44. def after_request(response):
  45. g.db.close()
  46. return response
  47.  
  48.  
  49. @app.route('/')
  50. def index():
  51. return render_template('index.html')
  52.  
  53.  
  54. @app.route('/login')
  55. def login():
  56. return render_template('login.html')
  57.  
  58. if __name__ == '__main__':
  59. app.run()
Add Comment
Please, Sign In to add comment