user.py 文件源码

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

项目:Albireo 作者: lordfriend 项目源码 文件源码
def update_email(self, new_email):
        from server import app, mail
        session = SessionManager.Session()
        try:
            user = session.query(User).filter(User.id == self.id).one()
            if user.email is not None and user.email_confirmed:
                # send notification mail
                subject = '[{0}] Email Address Update Notification'.format(app.config['SITE_NAME'])
                email_content = render_template('email-change-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)
            # update
            user.email = new_email
            user.email_confirmed = False
            self.email = new_email
            self.email_confirmed = False
            # send email
            self.send_confirm_email()
            session.commit()
            return json_resp({'message': 'ok'})
        except IntegrityError:
            raise ClientError('duplicate email')
        except NoResultFound:
            raise ServerError('user not found')
        finally:
            SessionManager.Session.remove()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号