def get(self): EmailVerifyHandler.configure() email = unquote(self.get_argument("email", None)) user_id = unquote(self.get_argument("user_id", None)) verification_code = unquote( self.get_argument("verification_code", None)) if user_id == None or email == None: EmailVerifyHandler.log_error("Bad request to email handler") return EmailVerifyHandler.log_info( "Request to verify email %s with user_id %s", email, user_id) if not EmailWhitelistHandler.is_whitelisted(email): self.render( os.path.join(EmailWhitelistHandler.TEMPLATE_PATH, "email_whitelist.tpl"), cfg=JBoxCfg.nv, user_id=user_id, message= "ERROR: entered email is not whitelisted, please try again:") return if verification_code == None: record = EmailVerifyDB(user_id) record.set_email(email) base_uri = self.request.protocol + "://" + self.request.host + self.request.uri.split( '?')[0] mail_body = base_uri + '?' + urllib.urlencode( { "user_id": user_id, "email": email, "verification_code": record.get_code() }) EmailVerifyHandler.EMAIL_PLUGIN.send_email( email, EmailVerifyHandler.EMAIL_SENDER, 'JuliaBox account activation', mail_body) self.render( os.path.join(EmailWhitelistHandler.TEMPLATE_PATH, "message.tpl"), cfg=JBoxCfg.nv, message="Email sent. Please click the link in the mail.") else: record = EmailVerifyDB(user_id) if record.verify(verification_code): s = dict(error="", success="Verification OK, please log in again", info="", pending_activation=False, user_id="") self.rendertpl("index.tpl", cfg=JBoxCfg.nv, state=s) else: self.render(os.path.join(EmailWhitelistHandler.TEMPLATE_PATH, "message.tpl"), cfg=JBoxCfg.nv, message="Verification failed.")
def process_user_id(handler, user_id): EmailWhitelistHandler.configure() # Check if the user_id matches if EmailWhitelistHandler.is_whitelisted(user_id): return True # No match on user_id, create a pending email verify request if needed verify_record = EmailVerifyDB(user_id) if verify_record.is_verified(): return True handler.render(os.path.join(EmailWhitelistHandler.TEMPLATE_PATH, "email_whitelist.tpl"), cfg=JBoxCfg.nv, user_id=user_id, message="Please enter white-listed email as per tutor instructions:") return False
def process_user_id(handler, user_id): EmailWhitelistHandler.configure() # Check if the user_id matches if EmailWhitelistHandler.is_whitelisted(user_id): return True # No match on user_id, create a pending email verify request if needed verify_record = EmailVerifyDB(user_id) if verify_record.is_verified(): return True handler.render( os.path.join(EmailWhitelistHandler.TEMPLATE_PATH, "email_whitelist.tpl"), cfg=JBoxCfg.nv, user_id=user_id, message="Please enter white-listed email as per tutor instructions:" ) return False
def get(self): EmailVerifyHandler.configure() email = unquote(self.get_argument("email", None)) user_id = unquote(self.get_argument("user_id", None)) verification_code = unquote(self.get_argument("verification_code", None)) if user_id == None or email == None: EmailVerifyHandler.log_error("Bad request to email handler") return EmailVerifyHandler.log_info("Request to verify email %s with user_id %s", email, user_id) if not EmailWhitelistHandler.is_whitelisted(email): self.render(os.path.join(EmailWhitelistHandler.TEMPLATE_PATH, "email_whitelist.tpl"), cfg=JBoxCfg.nv, user_id=user_id, message="ERROR: entered email is not whitelisted, please try again:") return if verification_code == None: record = EmailVerifyDB(user_id) record.set_email(email) base_uri = self.request.protocol + "://" + self.request.host + self.request.uri.split('?')[0] mail_body = base_uri + '?' + urllib.urlencode({ "user_id": user_id, "email": email, "verification_code": record.get_code() }) EmailVerifyHandler.EMAIL_PLUGIN.send_email(email, EmailVerifyHandler.EMAIL_SENDER, 'JuliaBox account activation', mail_body) self.render(os.path.join(EmailWhitelistHandler.TEMPLATE_PATH, "message.tpl"), cfg=JBoxCfg.nv, message="Email sent. Please click the link in the mail.") else: record = EmailVerifyDB(user_id) if record.verify(verification_code): s = dict(error="", success="Verification OK, please log in again", info="", pending_activation=False, user_id="") self.rendertpl("index.tpl", cfg=JBoxCfg.nv, state=s) else: self.render(os.path.join(EmailWhitelistHandler.TEMPLATE_PATH, "message.tpl"), cfg=JBoxCfg.nv, message="Verification failed.")