Advertisement
Guest User

Untitled

a guest
Feb 6th, 2017
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. class User(UserMixin, db.Model):
  2.     __tablename__ = 'users'
  3.     id = db.Column(db.Integer, primary_key=True)
  4.     email = db.Column(db.String(64), unique=True, index=True)
  5.     username = db.Column(db.String(64), unique=True, index=True)
  6.     role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))
  7.     password_hash = db.Column(db.String(128))
  8.  
  9.     @property
  10.     def password(self):
  11.         raise AttributeError('password is not a readable attribute')
  12.  
  13.     @password.setter
  14.     def password(self, password):
  15.         self.password_hash = generate_password_hash(password)
  16.  
  17.     def verify_password(self, password):
  18.         return check_password_hash(self.password_hash, password)
  19.  
  20.     def __repr__(self):
  21.         return '<User %r>' % self.username
  22.  
  23. @auth.route('/register', methods=['GET', 'POST'])
  24. def register():
  25.     form = RegistrationForm()
  26.     if form.validate_on_submit():
  27.         user = User(email=form.email.data,
  28.                     username=form.username.data,
  29.                     password=form.password.data)
  30.         db.session.add(user)
  31.         flash('You can now login.')
  32.         return redirect(url_for('auth.login'))
  33.     return render_template('auth/register.html', form=form)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement