Created
May 9, 2014 10:28
-
-
Save ianseyer/f08d3f47471588e79022 to your computer and use it in GitHub Desktop.
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
roles_users = db.Table('roles_users', | |
db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), | |
db.Column('role_id', db.Integer(), db.ForeignKey('role.id'))) | |
class Role(db.Model, RoleMixin): | |
""" | |
Roles for determining User permissions and access levels. | |
Permission table: | |
Purchase Roverpass - Upload images, Leave Review | |
Claim Campsite - Edit page, Upload, Leave Review | |
Opt-In - Forces Claim | |
Sales - All + Access to hidden management auth-code table. | |
""" | |
#__tablename__ = 'roles' | |
id = db.Column(db.Integer(), primary_key=True) | |
name = db.Column(db.String(80), unique=True) | |
description = db.Column(db.String(255)) | |
class User(db.Model, UserMixin): | |
""" | |
A User of the system. | |
In order to create a User, they MUST purchase a Roverpass. | |
""" | |
#methods required by flask-login: | |
#is_authenticated() | |
#is_active() | |
#is_anonymous() | |
#get_id() | |
#it will inherit all of these from UserMixin | |
#__tablename__ = 'users' | |
id = db.Column(db.Integer, primary_key=True) | |
email = db.Column(db.String(255), unique=True) | |
password = db.Column(db.String(120)) | |
active = db.Column(db.Boolean()) | |
role = db.relationship('Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic')) |
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
@app.route('/create_user', methods=['GET', 'POST']) | |
def create_user(): | |
form = UserForm(prefix="user") | |
if request.method=='POST' and form.validate(): | |
if User.query.filter_by(email = form.email.data).first() == None: | |
user = user_datastore.create_user(email=form.email.data, | |
password=encrypt_password(form.password.data), | |
active=True,) | |
user_datastore.activate_user(user) | |
user_datastore.add_role_to_user(user, 'base_user') | |
print 'adding user to db' | |
db.session.add(user) | |
db.session.commit() | |
print "commited user" | |
return redirect('/login') | |
else: | |
return render_template('userExists.html') | |
else: | |
print "validation failed" | |
print form.errors | |
response = render_template('create_user.html', form=form) | |
return render_template('create_user.html', form=form) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment