about summary refs log tree commit diff
path: root/wqflask/secure_server.py
diff options
context:
space:
mode:
authorSam2013-10-15 02:50:25 -0500
committerSam2013-10-15 02:50:25 -0500
commit57b00317168eb3a84c489c2613133170a191aef6 (patch)
tree88bc4cbe70b1199fb80021d7213971bdec9674bd /wqflask/secure_server.py
parent34c6c908ac072609a2f923946d474504d3fa0331 (diff)
downloadgenenetwork2-57b00317168eb3a84c489c2613133170a191aef6.tar.gz
* Redid mail sending service to set a ping showing it's alive
* Redid server so it wouldn't start unless mail service recently pinged

* Wrote a bunch of forgot password code

* Refactored sending email about verification and forgotten passwords
Diffstat (limited to 'wqflask/secure_server.py')
-rw-r--r--wqflask/secure_server.py40
1 files changed, 38 insertions, 2 deletions
diff --git a/wqflask/secure_server.py b/wqflask/secure_server.py
index a77abf7e..d5f1a291 100644
--- a/wqflask/secure_server.py
+++ b/wqflask/secure_server.py
@@ -1,12 +1,18 @@
 from __future__ import absolute_import, division, print_function
 
+import time
+import sys
+
 from wqflask import app
 
 from flask import Flask, render_template
 
+import redis
+Redis = redis.StrictRedis()
+
 # Setup mail
-from flask.ext.mail import Mail
-mail = Mail(app)
+#from flask.ext.mail import Mail
+#mail = Mail(app)
 
 from wqflask.model import *
 
@@ -33,8 +39,38 @@ app.wsgi_app = ProxyFix(app.wsgi_app)
 
 #print("app.config is:", app.config)
 
+
+
+def check_send_mail_running():
+    """Ensure send_mail.py is running before we start the site
+    
+    It would be really easy to accidentally run the site
+    without our mail program running
+    This will make sure our mail program is running...or at least recently run...
+
+    """
+    error_msg = "Make sure your are running send_mail.py"
+    send_mail_ping = Redis.get("send_mail:ping")
+    print("send_mail_ping is:", send_mail_ping)
+    if not send_mail_ping:
+        sys.exit(error_msg)
+
+    last_ping = time.time() - float(send_mail_ping)
+    if not (0 < last_ping < 100):
+        sys.exit(error_msg)
+
+
+    print("send_mail.py seems to be running...")
+
+
 if __name__ == '__main__':
     #create_user()
+
+
+
+    check_send_mail_running()
+
+
     app.run(host='0.0.0.0',
         port=app.config['SERVER_PORT'],
         use_debugger=False,