def post(self): if not self.CheckUser(): self.ShowFrontPage() return args = self.ArgsToDict() try: global oidserver #mrk from openid.message import Message message = Message.fromPostArgs(args) oidrequest = OpenIDServer.CheckIDRequest.fromMessage(message, oidserver.op_endpoint) except: trace = ''.join(traceback.format_exception(*sys.exc_info())) self.ReportError('Error decoding login request:\n%s' % trace) return if args.has_key('yes'): logging.debug('Confirming identity to %s' % oidrequest.trust_root) if args.get('remember', '') == 'yes': logging.info('Setting cookie to remember openid login for two weeks') expires = datetime.datetime.now() + datetime.timedelta(weeks=2) expires_rfc822 = expires.strftime('%a, %d %b %Y %H:%M:%S +0000') self.response.headers.add_header( 'Set-Cookie', 'openid_remembered_%s=yes; expires=%s' % (digest(oidrequest.trust_root),expires_rfc822)) self.store_login(oidrequest, 'confirmed') set_cookie(self.response, "fb_user", "", expires=time.time() - 86400) answer = oidrequest.answer(True, identity = get_identity_url(self.request, self.get_current_user())) logging.info('answer:%s',answer) self.Respond(answer) elif args.has_key('no'): logging.debug('Login denied, sending cancel to %s' % oidrequest.trust_root) self.store_login(oidrequest, 'declined') return self.Respond(oidrequest.answer(False)) else: self.ReportError('Bad login request.')
def get(self): """Handles GET requests.""" login_url = self.create_login_url(self.request.uri) logout_url = self.create_logout_url(self.request.uri) user = self.get_current_user() if user: logging.debug('User: %s' % user) else: logging.info('no user, redirect to login url') self.redirect(login_url) oidrequest = self.GetOpenIdRequest() postargs = oidrequest.message.toPostArgs() if oidrequest else {} if oidrequest is False: # there was an error, and GetOpenIdRequest displayed it. bail out. return elif oidrequest is None: # this is a request from a browser self.ShowFrontPage() elif oidrequest.mode in ['checkid_immediate', 'checkid_setup']: if self.HasCookie(oidrequest.trust_root) and user: logging.debug('Has cookie, confirming identity to ' + oidrequest.trust_root) self.store_login(oidrequest, 'remembered') set_cookie(self.response, "fb_user", "", expires=time.time() - 86400) self.Respond(oidrequest.answer(True, identity = get_identity_url(self.request, self.get_current_user()))) elif oidrequest.immediate: self.store_login(oidrequest, 'declined') oidresponse = oidrequest.answer(False) self.Respond(oidresponse) else: if self.CheckUser(): self.Render('prompt', vars()) else: self.ShowFrontPage() elif oidrequest.mode in ['associate', 'check_authentication']: self.Respond(oidserver.handleRequest(oidrequest)) else: self.ReportError('Unknown mode: %s' % oidrequest.mode)