def update_password(self, old_pass, new_pass):
from server import app, mail
session = SessionManager.Session()
try:
user = session.query(User).filter(User.id == self.id).one()
if check_password_hash(user.password, old_pass):
user.password = UserCredential.get_pass_hash(new_pass)
session.commit()
if user.email is not None and user.email_confirmed:
# send notification mail
subject = '[{0}] Password Update Notification'.format(app.config['SITE_NAME'])
email_content = render_template('update-pass-notification.html', info={
'title': subject,
'user_name': user.name,
'site_name': app.config['SITE_NAME']
})
msg = Message(subject, recipients=[self.email], html=email_content)
try:
mail.send(msg)
except SMTPAuthenticationError:
raise ServerError('SMTP authentication failed', 500)
return True
else:
raise ClientError(ClientError.PASSWORD_INCORRECT)
except NoResultFound:
raise ServerError('user not found')
finally:
SessionManager.Session.remove()
评论列表
文章目录