Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
6005CEM/cw2_1
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
34 lines (28 sloc)
1.23 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user_roles = db.Table( | |
'user_roles', | |
db.Column('user_id', db.Integer, db.ForeignKey('user.id')), | |
db.Column('role_id', db.Integer, db.ForeignKey('role.id')) | |
) | |
# Define User and Role models | |
class Role(db.Model, RoleMixin): | |
id = db.Column(db.Integer, primary_key=True) | |
name = db.Column(db.String(80), unique=True) | |
description = db.Column(db.String(255)) | |
fs_uniquifier = db.Column(db.String(255), unique=True) | |
class User(db.Model, UserMixin): | |
id = db.Column(db.Integer, primary_key=True) | |
email = db.Column(db.String(255), unique=True) | |
password = db.Column(db.String(255)) | |
active = db.Column(db.Boolean()) | |
fs_uniquifier = db.Column(db.String(255), unique=True) | |
roles = db.relationship('Role', secondary='user_roles', backref=db.backref('users', lazy='dynamic')) | |
@app.route('/login_user', methods=['GET', 'POST']) | |
def login(): | |
if request.method == 'POST': | |
email = request.form['email'] | |
password = request.form['password'] | |
user = user_datastore.find_user(email=email) | |
if user and bcrypt.checkpw(password.encode('utf-8'), user.password): | |
session["user"] = user.id | |
return render_template('home.html') | |
return render_template('login.html') |