From f31053f6327f7bd2d469b71f139ae32a550ed5a2 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Thu, 11 Jun 2015 21:32:46 +0300 Subject: [PATCH] API: Added A Skeleton Route For Email Validation --- SE_API/API.py | 26 ++++++++++++++++++++++++-- SE_API/Validation_Utils.py | 10 ++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/SE_API/API.py b/SE_API/API.py index 56c5583..04286ba 100644 --- a/SE_API/API.py +++ b/SE_API/API.py @@ -43,7 +43,29 @@ def page_not_found(e): def wellcomePage(): return app.send_static_file('index.html') -@app.route('/api/validatation/sendmail/', methods=['POST']) +@app.route('/api/validation/confirm/') +@auto.doc() +def confirm_user_to_campus(validation_token): + """ + This Function is will re + :param validation_token: 'seToken|email_suffix' + :return: + 200 - redirect to home + new cookie + 403 - Invalid Token + """ + #TODO + token = str(validation_token).split('|')[0] + email_sufix = '@'+str(validation_token).split('|')[1] + + if is_user_token_valid(token): + return Response(status=200, response=json.dumps({'token': token, 'suffix': email_sufix})) + else: + return Response(response=json.dumps({'message': 'Not A Valid Token!'}), + status=403, + mimetype="application/json") + + +@app.route('/api/validation/sendmail/', methods=['POST']) @auto.doc() def send_activation(token): """ @@ -146,7 +168,7 @@ def oauth(oauth_token): else: tempEmail = user_data["email"] - user = User(username=user_data["login"], name=tempName, avatar_url=user_data["avatar_url"], email=tempEmail, isLecturer=False, accsessToken=oauth_token, seToken=str(uuid.uuid4())) + user = User(username=user_data["login"], name=tempName, avatar_url=user_data["avatar_url"], email=tempEmail, isLecturer=False, accessToken=oauth_token, seToken=str(uuid.uuid4())) db.put(user) db.save return cookieMonster(user.seToken) diff --git a/SE_API/Validation_Utils.py b/SE_API/Validation_Utils.py index 836e4d1..f9754da 100644 --- a/SE_API/Validation_Utils.py +++ b/SE_API/Validation_Utils.py @@ -13,8 +13,9 @@ def is_user_token_valid(token): return False def send_validation_email(token, email, name): + emailSuffix = str(email).split('@')[1] message = mail.EmailMessage(sender="SE-Hub Support ", - subject="SE-Hub Activate Account") + subject="SE-Hub Activate Account") message.to = email @@ -22,8 +23,8 @@ def send_validation_email(token, email, name): 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. + http://se-hub.appspot.com/api/validation/confirm/"""+token+"""|"""+emailSuffix+""" + to get access to your Campus :) Please let us know if you have any questions. @@ -35,6 +36,7 @@ def send_validation_email(token, email, name):
+
@@ -42,7 +44,7 @@ def send_validation_email(token, email, name):

Dear """+name+""":

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

+ http://se-hub.appspot.com/api/validation/confirm/"""+token+"""|"""+emailSuffix+""" to access you virtual class.