Example #1
0
 def checkOTPExistance(self, skypedata, replyObj):
     """
     Check if OTP already exists for the specific email address
     """
     try:
         user = Users.get(user_id=skypedata['from']['id'][3:])
         try:
             OTP.get(user_id=user.id)
             replyObj.send_reply(skypedata, "Incorrect OTP, please send the correct one.")
             #return True
         except OTP.DoesNotExist:
             self.otp_generated = False
             self.user_registered = False
             replyObj.send_reply(skypedata, """I think you were off for a long time and the OTP would hav been expired. Can you please provide your servicenow registered email address?""")
             #return False
     except Users.DoesNotExist:
         self.user_registered = False
         self.otp_generated = False
         replyObj.send_reply(skypedata, """I think you were off for a long time or would have entered a wrong email address. Can you please provide your servicenow registered email address?""")
 def checkOTPExistance(self, skypedata, replyObj):
     """
     Check if OTP already exists for the specific email address
     """
     try:
         print('Inside checkORPexistance first try')
         user = Users.get(user_id=skypedata['from']['id'][3:])
         try:
             print('Inside checkORPexistance seconf try')
             OTP.get(user_id=user.id)
             replyObj.send_reply(skypedata, "Incorrect OTP, please send the correct one.")
         except OTP.DoesNotExist:
             print('Inside checkORPexistance first except')
             self.otp_generated = False
             self.user_registered = False
             replyObj.send_reply(skypedata, """I think you were off for a long time and the OTP would hav been expired. Can you please provide your email address?""")
     except Users.DoesNotExist:
         print('Inside checkORPexistance second except')
         self.user_registered = False
         self.otp_generated = False
         replyObj.send_reply(skypedata, """I think you were off for a long time or would have entered a wrong email address. Can you please provide your email address?""")
Example #3
0
 def verifyOTP(self, skypedata):
     """
     Verify OTP with of specific user
     """
     try:
         pattern = '[#!@$%]{{{}}}[\d]{{{}}}[!@#$%]{{{}}}'.format(os.environ.get('OTP_SPECIAL_CHARACTERS_LIMIT'), os.environ.get('OTP_DIGITS_LIMIT'), os.environ.get('OTP_SPECIAL_CHARACTERS_LIMIT'))
         # finds opt from the text entered by the user using regex
         otp = re.findall(pattern, skypedata['text'])
         #otp = re.findall(r'FUJIAMAZE+[\d]+', skypedata['text'])
         if len(otp)==1 and (otp[0] in skypedata['text'].split()): # using split coz regex gives valid(matching regex) string from an invalid(valid regex but an incorrect otp) one too. it gives @#12345@# from string !@#12345@#$
             otp_obj = OTP.get(otp=otp[0])
             user = Users.get(id=otp_obj.user_id)
             if (user and user.user_id == skypedata['from']['id'][3:]):
                 user.is_active = True
                 user.save()  # Make the user as active
                 return True
         return False
     except BaseException as e:
         return False
Example #4
0
 def createUserOTP(self, user_data, skypedata, otp):
     """
     Creates or fetches User and OTP atomically
     """
     try:
         user = Users.get_or_create(
             name=user_data['name'],
             user_id=skypedata['from']['id'][3:],
             servicenow_id=user_data['sys_id'],
             is_active=False)
         try:
             otp_obj = OTP.get(user_id=user[0].id)
             otp_obj.otp = otp
             otp_obj.save()
         except OTP.DoesNotExist:
             OTP.create(user_id=user[0].id, otp=otp)
         return True
     except Exception as e:
         return False