mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-24 02:24:20 +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)
|
||||
password_hash = db.Column(db.String(128))
|
||||
role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))
|
||||
confirmed = db.Column(db.Boolean, default=False)
|
||||
|
||||
def __repr__(self):
|
||||
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):
|
||||
s = Serializer(current_app.config['SECRET_KEY'], expiration)
|
||||
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
|
||||
def password(self):
|
||||
raise AttributeError('password is not a readable attribute')
|
||||
|
Loading…
Reference in New Issue
Block a user