Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @app.route('/login', methods=('GET', 'POST'))
- def login():
- form = LoginForm(request.form)
- if form.validate_on_submit():
- user = User.query.filter_by(email=form.email.data).first()
- if user and check_password_hash(user.password, form.password.data):
- session['user.id'] = user.id
- flash('Welcome %s' % user.username)
- return redirect(url_for('index'))
- return render_template("login.html", form=form)
- class User(UserMixin,db.Model):
- id = db.Column(db.Integer, primary_key = True, autoincrement=True)
- username = db.Column(db.String(64), index = True, unique = True)
- email = db.Column(db.String(120), index = True, unique = True)
- password = db.Column(db.String(120), index = True)
- role = db.Column(db.SmallInteger, default=ROLE_USER)
- def __init__(self, id, username, email, password, role):
- self.id = id
- self.username = username
- self.password = password
- self.email = email
- self.role = role
- def set_password(self, password):
- self.pw_hash = generate_password_hash(password)
- def check_password(self, password):
- return check_password_hash(self.pw_hash, password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement