def get_user(self, id=None): try: id = int(id) except (ValueError, TypeError): abort(404) user = User.get_byid(id) if user is None: abort(404) redirect(user.url())
def google_verify(self): openid_session = session.get("openid_session", {}) openid_store = None # stateless cons = Consumer(openid_session, openid_store) info = cons.complete(request.params, url('google_verify', qualified=True)) display_identifier = info.getDisplayIdentifier() if info.status == consumer.SUCCESS: identity_url = info.identity_url if 'linking_to_user' in session: user = User.get_byid(session.pop('linking_to_user')) if not User.get_byopenid(identity_url): user.openid = identity_url meta.Session.commit() h.flash(_('Linked to Google account.')) else: h.flash(_('This Google account is already linked to another Ututi account.')) redirect(url(controller='profile', action='login_settings')) name = '%s %s' % (request.params.get('openid.ext1.value.firstname'), request.params.get('openid.ext1.value.lastname')) email = request.params.get('openid.ext1.value.email') return self._try_to_login(name, email, google_id=identity_url) elif info.status == consumer.FAILURE and display_identifier: # In the case of failure, if info is non-None, it is the # URL that we were verifying. We include it in the error # message to help the user figure out what happened. fmt = _("Verification of %s failed: %s") message = fmt % (display_identifier, cgi.escape(info.message)) elif info.status == consumer.CANCEL: message = _('Verification cancelled') elif info.status == consumer.SETUP_NEEDED: if info.setup_url: message = _('<a href=%s>Setup needed</a>') % ( quoteattr(info.setup_url),) else: # This means auth didn't succeed, but you're welcome to try # non-immediate mode. message = _('Setup needed') else: message = _('Authentication failed: %s') % info.message # TODO: log info.status and info.message h.flash(message) redirect(c.came_from or url(controller='federation', action='index'))