Commits

Matthew Turk  committed 1713241

Adding something to email when new users are created

  • Participants
  • Parent commits 7731b65

Comments (0)

Files changed (2)

File ythub/send_email.py

 yt data hub
 """
 
-def send_message(subject, dest, contents):
-    msg = MIMEText(contents)
-    msg['Subject'] = subject
-    msg['From'] = smtp_address
-    msg['To'] = dest
-    s = smtplib.SMTP_SSL(smtp_host)
-    s.set_debuglevel(True)
-    s.login(smtp_address, smtp_pass)
-    s.sendmail(smtp_address, [dest], msg.as_string())
-    s.close()
+new_user_notice = r"""
+Hi there!
 
+A new user has been created on the yt Data Hub:
+
+Username: %(username)s
+Name:     %(name)s
+E-mail:   %(email)s
+
+Thanks,
+
+yt data hub
+"""

File ythub/views.py

     MinimalStaticOutput, MinimalProjectionData
 from ythub.authentication import require_api_key
 from math import ceil
-from ythub.send_email import send_message, pw_recovery_template
+from ythub.send_email import pw_recovery_template, new_user_notice
 from ythub.database import db_session, ses_conn
+from ythub.local_config import admin_emails
 
 from ythub.authentication import \
     register_user, login_user, login_required, logout_user, \
     projects.sort(key = lambda a: -getattr(a[1], "created", 0))
     return render_template("index.html", data = data, projects = projects)
 
-@app.route("/create_user/", methods=["GET", "POST"])
+@app.route("/create_user", methods=["GET", "POST"])
 def create_user():
     error = None
     if request.method == 'POST':
         if user:
             login_user(request.form.get('username'),
                        request.form.get('password'))
+            email_subject = "New yt Data Hub User"
+            email_body = new_user_notice % {'username':user.username,
+                                            'name':user.name,
+                                            'email':user.email}
+            ses_conn.send_email(
+                "data@yt-project.org", 
+                 email_subject, email_body, admin_emails)
             flash('Registration successful.')
             return redirect('/')
         else: