user.py 文件源码

python
阅读 57 收藏 0 点赞 0 评论 0

项目:Albireo 作者: lordfriend 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号