Просмотр исходного кода

add send email to admin.

when someone registered an account
honmaple 8 лет назад
Родитель
Сommit
252674f6e9
2 измененных файлов с 13 добавлено и 2 удалено
  1. 2 1
      forums/api/auth/views.py
  2. 11 1
      forums/api/user/models.py

+ 2 - 1
forums/api/auth/views.py

@@ -6,7 +6,7 @@
 # Author: jianglin
 # Email: xiyang0807@gmail.com
 # Created: 2016-10-28 10:26:10 (CST)
-# Last Update:星期日 2017-4-2 15:25:52 (CST)
+# Last Update:星期六 2017-4-8 12:40:29 (CST)
 #          By:
 # Description:
 # **************************************************************************
@@ -100,6 +100,7 @@ class RegisterView(MethodView):
         html = render_template('templet/email.html', confirm_url=confirm_url)
         subject = _("Please confirm  your email!")
         user.send_email(subject=subject, html=html)
+        user.send_email_to_admin()
 
 
 class ForgetView(MethodView):

+ 11 - 1
forums/api/user/models.py

@@ -6,7 +6,7 @@
 # Author: jianglin
 # Email: xiyang0807@gmail.com
 # Created: 2016-12-15 21:09:08 (CST)
-# Last Update:星期日 2017-4-2 16:27:2 (CST)
+# Last Update:星期六 2017-4-8 12:51:59 (CST)
 #          By:
 # Description:
 # **************************************************************************
@@ -156,6 +156,16 @@ class User(db.Model, UserMixin, ModelMixin, MailMixin):
         kwargs.update(recipients=[self.email])
         mail.send_email(*args, **kwargs)
 
+    def send_email_to_admin(self):
+        ''''
+        When someone registered an account,send email to admin.
+        '''
+        recipients = current_app.config['RECEIVER']
+        subject = '{} has registered an account.'.format(self.username)
+        html = '<p>username: {}</p><p>email: {}</p>'.format(self.username,
+                                                            self.email)
+        mail.send_email(subject=subject, html=html, recipients=recipients)
+
 
 class UserInfo(db.Model, ModelMixin):
     __tablename__ = 'userinfo'