Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User(UserMixin, db.Model):
- __tablename__ = 'users'
- id = db.Column(db.Integer, primary_key=True)
- email = db.Column(db.String(64), unique=True, index=True)
- username = db.Column(db.String(64), unique=True, index=True)
- role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))
- password_hash = db.Column(db.String(128))
- @property
- def password(self):
- raise AttributeError('password is not a readable attribute')
- @password.setter
- def password(self, password):
- self.password_hash = generate_password_hash(password)
- def verify_password(self, password):
- return check_password_hash(self.password_hash, password)
- def __repr__(self):
- return '<User %r>' % self.username
- @auth.route('/register', methods=['GET', 'POST'])
- def register():
- form = RegistrationForm()
- if form.validate_on_submit():
- user = User(email=form.email.data,
- username=form.username.data,
- password=form.password.data)
- db.session.add(user)
- flash('You can now login.')
- return redirect(url_for('auth.login'))
- return render_template('auth/register.html', form=form)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement