diff --git a/SE_API/API.py b/SE_API/API.py index d8f1be3..e7064e9 100644 --- a/SE_API/API.py +++ b/SE_API/API.py @@ -41,6 +41,39 @@ def page_not_found(e): def wellcomePage(): return app.send_static_file('index.html') +@app.route('/api/validatation/sendmail/', methods=['POST']) +@auto.doc() +def send_activation(token): + """ + This Method Will Send An Email To The User - To Confirm his Account + :param token: - seToken + :payload: JSON - {email: 'academic@email.ac.com'} + :return: + 200 - Email Sent - No Response + 400 - Bad Request + 403 - Invalid Token + """ + if not request.data: + return Response(response=json.dumps({'message': 'Bad Request'}), + status=400, + mimetype="application/json") + payload = json.loads(request.data) + if not is_user_token_valid(token): + return Response(response=json.dumps({'message': 'Not A Valid Token!'}), + status=403, + mimetype="application/json") + query = User.all() + query.filter('seToken =', token) + for u in query.run(limit=1): + try: + send_validation_email(token=token, name=u.username, email=payload["email"]) + except Exception: + return Response(response=json.dumps({'message': 'Bad Request'}), + status=400, + mimetype="application/json") + + return Response(status=200) + @app.route('/api/help') def documentation(): return auto.html() @@ -67,8 +100,8 @@ def getUserByToken(token): for u in query.run(limit=5): return Response(response=u.to_JSON(), - status=201, - mimetype="application/json") # Real response! + status=201, + mimetype="application/json") # Real response! return Response(response=json.dumps({'message' : 'No User Found'}), status=400, @@ -135,7 +168,7 @@ def get_campuses(token): .... { ... - } + }req ] code 403: Forbidden - Invalid Token diff --git a/SE_API/Validation_Utils.py b/SE_API/Validation_Utils.py index e074f13..836e4d1 100644 --- a/SE_API/Validation_Utils.py +++ b/SE_API/Validation_Utils.py @@ -1,6 +1,8 @@ __author__ = 'sagi' from google.appengine.ext import db from models.User import User +from google.appengine.api import mail + def is_user_token_valid(token): query = User.all() @@ -9,3 +11,47 @@ def is_user_token_valid(token): for u in query.run(): return True return False + +def send_validation_email(token, email, name): + message = mail.EmailMessage(sender="SE-Hub Support ", + subject="SE-Hub Activate Account") + + message.to = email + + message.body = """ + Dear """+name+""": + + To Activate your SE-Hub Account please click on the link below:
+ http://se-hub.appspot.com/api/validatation/confirm/"""+token+""" + to access you virtual class. + + Please let us know if you have any questions. + + SE-Hub (c) 2015 niptop Team. + """ + + message.html = """ + +
+
+ +
+
+
+

Hey """+name+"""- Just one More Step...

+

Dear """+name+""":

+ + To Activate your SE-Hub Account please click on the link below:
+ http://se-hub.appspot.com/api/validatation/confirm/"""+token+"""

+ + to access you virtual class. +
+

+ Please let us know if you have any questions. +
+ SE-Hub (c) 2015 niptop Team. + + + """ + + message.send()