Skip to content
Snippets Groups Projects
Commit 11a3e755 authored by Stephan Porada's avatar Stephan Porada :speech_balloon:
Browse files

Add email confirmation

parent ae11e04c
No related branches found
No related tags found
No related merge requests found
...@@ -22,16 +22,31 @@ class User(UserMixin, db.Model): ...@@ -22,16 +22,31 @@ class User(UserMixin, db.Model):
username = db.Column(db.String(64), unique=True, index=True) username = db.Column(db.String(64), unique=True, index=True)
password_hash = db.Column(db.String(128)) password_hash = db.Column(db.String(128))
role_id = db.Column(db.Integer, db.ForeignKey('roles.id')) role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))
confirmed = db.Column(db.Boolean, default=False)
def __repr__(self): def __repr__(self):
return '<User %r>' % self.username return '<User %r>' % self.username
password_hash = db.Column(db.String(128)) def generate_confirmation_token(self, expiration=3600):
s = Serializer(current_app.config['SECRET_KEY'], expiration)
return s.dumps({'confirm': self.id}).decode('utf-8')
def generate_reset_token(self, expiration=3600): def generate_reset_token(self, expiration=3600):
s = Serializer(current_app.config['SECRET_KEY'], expiration) s = Serializer(current_app.config['SECRET_KEY'], expiration)
return s.dumps({'reset': self.id}).decode('utf-8') return s.dumps({'reset': self.id}).decode('utf-8')
def confirm(self, token):
s = Serializer(current_app.config['SECRET_KEY'])
try:
data = s.loads(token.encode('utf-8'))
except:
return False
if data.get('confirm') != self.id:
return False
self.confirmed = True
db.session.add(self)
return True
@property @property
def password(self): def password(self):
raise AttributeError('password is not a readable attribute') raise AttributeError('password is not a readable attribute')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment