def facebook_bind_proxy(self): if c.user is not None: fb_user = facebook.get_user_from_cookie(request.cookies, config['facebook.appid'], config['facebook.secret']) if not fb_user: h.flash(_("Failed to link Facebook account")) else: facebook_id = int(fb_user['uid']) if not User.get_byfbid(facebook_id): c.user.facebook_id = facebook_id c.user.update_logo_from_facebook() meta.Session.commit() h.flash(_("Linked to Facebook account.")) else: h.flash(_('This Facebook account is already linked to another Ututi account.')) redirect(c.redirect_to or url('frontpage'))
def _try_to_login(self, name, email, google_id=None, facebook_id=None, fb_access_token=None): assert bool(google_id) != bool(facebook_id) if google_id: user = User.get_byopenid(google_id) elif facebook_id: user = User.get_byfbid(facebook_id) if user is not None: # Existing user, log him in and proceed. if facebook_id and not user.logo: user.update_logo_from_facebook() meta.Session.commit() sign_in_user(user) redirect(c.came_from or url(controller='home', action='index')) else: # Facebook needs to be asked for the email separately. if facebook_id: name, email = self._facebook_name_and_email(facebook_id, fb_access_token) if not email: h.flash(_('Facebook did not provide your email address.')) redirect(c.came_from or url(controller='home', action='index')) # This user has never logged in using FB/Google before. user = User.get_global(email) if user is None: h.flash(_('Login failed. Please login using your username and bind your account first.')) redirect(url(controller='home', action='login')) else: # Existing user logging in using FB/Google. if google_id: h.flash(_('Your Google account "%s" has been linked to your existing Ututi account.') % email) user.openid = google_id elif facebook_id: h.flash(_('Your Facebook account "%s" has been linked to your existing Ututi account.') % email) user.facebook_id = facebook_id bind_group_invitations(user) if not user.logo: user.update_logo_from_facebook() meta.Session.commit() sign_in_user(user) redirect(c.came_from or url(controller='home', action='index'))
def link_facebook(self, registration): fb_user = facebook.get_user_from_cookie(request.cookies, config['facebook.appid'], config['facebook.secret']) if not fb_user: h.flash(_("Failed to link Facebook account")) else: facebook_id = int(fb_user['uid']) fb_access_token = fb_user['access_token'] if not User.get_byfbid(facebook_id, registration.location): registration.facebook_id = facebook_id registration.update_logo_from_facebook() name, email = self._facebook_name_and_email(facebook_id, fb_access_token) if not registration.fullname: registration.fullname = name registration.facebook_email = email meta.Session.commit() h.flash(_("Linked to Facebook account.")) else: h.flash(_('This Facebook account is already linked to another user.')) redirect(registration.url(action='personal_info'))
def _bind_user(self, user, flash=True): """Bind user to FB/Google account (retrieve info from session).""" if session.get('confirmed_openid'): if User.get_byopenid(session['confirmed_openid']): # This rarely happens, but we have to check to avoid an error. if flash: h.flash(_('This Google account is already linked to another Ututi account.')) return user.openid = session['confirmed_openid'] if flash: h.flash(_('Your Google account has been associated with your Ututi account.')) elif session.get('confirmed_facebook_id'): if User.get_byfbid(session['confirmed_facebook_id']): # This rarely happens, but we have to check to avoid an error. if flash: h.flash(_('This Facebook account is already linked to another Ututi account.')) return user.facebook_id = int(session['confirmed_facebook_id']) user.update_logo_from_facebook() if flash: h.flash(_('Your Facebook account has been associated with your Ututi account.'))