mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Add email confirmation
This commit is contained in:
parent
ae11e04c6c
commit
11a3e7551f
@ -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')
|
||||||
|
Loading…
Reference in New Issue
Block a user