49 def authenticate(self, configurationAttributes, requestParameters, step):
51 print "TwilioSMS. Authenticate for Step %s" % str(step)
52 identity = CdiUtil.bean(Identity)
53 authenticationService = CdiUtil.bean(AuthenticationService)
54 user = authenticationService.getAuthenticatedUser()
59 credentials = identity.getCredentials()
60 user_name = credentials.getUsername()
61 user_password = credentials.getPassword()
63 if StringHelper.isNotEmptyString(user_name)
and StringHelper.isNotEmptyString(user_password):
64 authenticationService.authenticate(user_name, user_password)
65 user = authenticationService.getAuthenticatedUser()
71 mobiles = user.getAttributeValues(
"mobile")
76 code = random.randint(100000, 999999)
77 identity.setWorkingParameter(
"randCode", code)
79 sid = configurationAttributes.get(
"twilio_sid").getValue2()
80 token = configurationAttributes.get(
"twilio_token").getValue2()
81 from_no = configurationAttributes.get(
"from_number").getValue2()
82 Twilio.init(sid, token)
84 if mobiles.size() == 1:
85 self.sendMessage(code, mobiles.get(0))
90 chopped +=
"," + numb[max(0, l-4) : l]
93 identity.setWorkingParameter(
"numbers", Joiner.on(
",").join(mobiles.toArray()))
94 identity.setWorkingParameter(
"choppedNos", chopped[1:])
101 session_attributes = identity.getSessionId().getSessionAttributes()
102 code = session_attributes.get(
"randCode")
103 numbers = session_attributes.get(
"numbers")
105 if step == 2
and numbers !=
None:
107 idx = ServerUtil.getFirstValue(requestParameters,
"TwilioSmsloginForm:indexOfNumber")
108 if idx !=
None and code !=
None:
109 sendToNumber = numbers.split(
",")[int(idx)]
110 self.sendMessage(code, sendToNumber)
116 form_passcode = ServerUtil.getFirstValue(requestParameters,
"passcode")
118 if form_passcode !=
None and code == form_passcode:
119 print "TwilioSMS. authenticate. 6-digit code matches with code sent via SMS" 122 facesMessages = CdiUtil.bean(FacesMessages)
123 facesMessages.setKeepMessages()
124 facesMessages.clear()
125 facesMessages.add(FacesMessage.SEVERITY_ERROR,
"Wrong code entered")