Beispiel #1
0
    def delete_all_identifying_cookies(handler):
        handler.delete_cookie('ureg_id')
        handler.delete_cookie(auth.cookies.AUTH_COOKIE_NAME)

        # Delete session cookie set by flask (used in /api/auth/token_to_session)
        handler.delete_cookie('session')

        # Delete Facebook cookie, which sets ithandler both on "www.ka.org" and ".www.ka.org"
        facebook_util.delete_fb_cookies(handler)
Beispiel #2
0
    def delete_all_identifying_cookies(handler):
        handler.delete_cookie('ureg_id')
        handler.delete_cookie(auth.cookies.AUTH_COOKIE_NAME)

        # Delete session cookie set by flask (used in /api/auth/token_to_session)
        handler.delete_cookie('session')

        # Delete Facebook cookie, which sets ithandler both on "www.ka.org" and ".www.ka.org"
        facebook_util.delete_fb_cookies(handler)
Beispiel #3
0
    def get(self):
        cont = self.request_continue_url()

        self._consume_auth_token()

        user_data = UserData.current(create_if_none=True)
        if not user_data:
            # Nobody is logged in - clear any expired Facebook cookies
            # that may be hanging around.
            facebook_util.delete_fb_cookies(self)

            logging.critical(("Missing UserData during PostLogin, " +
                              "with id: %s, cookies: (%s), google user: %s") %
                             (util.get_current_user_id_unsafe(),
                              os.environ.get('HTTP_COOKIE', ''),
                              users.get_current_user()))
            self._finish_and_redirect(cont)
            return

        first_time = not user_data.last_login

        if not user_data.has_sendable_email():

            if not user_data.is_facebook_user:
                # TODO(benkomalo): seems like there are some phantoms hitting
                # this code path at least - are there any others?
                logging.error(
                    "Non-FB users should have a valid email. User: [%s]" %
                    user_data)

            # Facebook can give us the user's e-mail if the user granted
            # us permission to see it - try to update existing users with
            # emails, if we don't already have one for them.
            fb_email = facebook_util.get_fb_email_from_cookies()
            if fb_email:
                # We have to be careful - we haven't always asked for emails
                # from facebook users, so getting an e-mail after the fact
                # may result in a collision with an existing Google or Khan
                # account. In those cases, we silently drop the e-mail.
                existing_user = \
                    user_models.UserData.get_from_user_input_email(fb_email)

                if (existing_user and
                        existing_user.user_id != user_data.user_id):
                    logging.warning("FB user gave us e-mail and it "
                                    "corresponds to an existing account. "
                                    "Ignoring e-mail value.")
                else:
                    user_data.user_email = fb_email

        # If the user has a public profile, we stop "syncing" their username
        # from Facebook, as they now have an opportunity to set it themself
        if not user_data.username:
            user_data.update_nickname()

        # Set developer and moderator to True if user is admin
        if ((not user_data.developer or not user_data.moderator) and
                users.is_current_user_admin()):
            user_data.developer = True
            user_data.moderator = True

        user_data.last_login = datetime.datetime.utcnow()
        user_data.put()

        complete_signup = self.request_bool("completesignup", default=False)
        if first_time:
            email_now_verified = None
            if user_data.has_sendable_email():
                email_now_verified = user_data.email

                # Look for a matching UnverifiedUser with the same e-mail
                # to see if the user used Google login to verify.
                unverified_user = user_models.UnverifiedUser.get_for_value(
                        email_now_verified)
                if unverified_user:
                    unverified_user.delete()

            # Note that we can only migrate phantom users right now if this
            # login is not going to lead to a "/completesignup" page, which
            # indicates the user has to finish more information in the
            # signup phase.
            if not complete_signup:
                # If user is brand new and has 0 points, migrate data.
                phantom_id = get_phantom_user_id_from_cookies()
                if phantom_id:
                    phantom_data = UserData.get_from_db_key_email(phantom_id)
                    if _upgrade_phantom_into(phantom_data, user_data):
                        cont = "/newaccount?continue=%s" % cont
        if complete_signup:
            cont = "/completesignup"

        self._finish_and_redirect(cont)
Beispiel #4
0
    def get(self):
        cont = self.request_continue_url()

        self._consume_auth_token()

        user_data = UserData.current(create_if_none=True)
        if not user_data:
            # Nobody is logged in - clear any expired Facebook cookies
            # that may be hanging around.
            facebook_util.delete_fb_cookies(self)

            logging.critical(
                ("Missing UserData during PostLogin, " +
                 "with id: %s, cookies: (%s), google user: %s") %
                (util.get_current_user_id_unsafe(),
                 os.environ.get('HTTP_COOKIE', ''), users.get_current_user()))
            self._finish_and_redirect(cont)
            return

        first_time = not user_data.last_login

        if not user_data.has_sendable_email():

            if not user_data.is_facebook_user:
                # TODO(benkomalo): seems like there are some phantoms hitting
                # this code path at least - are there any others?
                logging.error(
                    "Non-FB users should have a valid email. User: [%s]" %
                    user_data)

            # Facebook can give us the user's e-mail if the user granted
            # us permission to see it - try to update existing users with
            # emails, if we don't already have one for them.
            fb_email = facebook_util.get_fb_email_from_cookies()
            if fb_email:
                # We have to be careful - we haven't always asked for emails
                # from facebook users, so getting an e-mail after the fact
                # may result in a collision with an existing Google or Khan
                # account. In those cases, we silently drop the e-mail.
                existing_user = \
                    user_models.UserData.get_from_user_input_email(fb_email)

                if (existing_user
                        and existing_user.user_id != user_data.user_id):
                    logging.warning("FB user gave us e-mail and it "
                                    "corresponds to an existing account. "
                                    "Ignoring e-mail value.")
                else:
                    user_data.user_email = fb_email

        # If the user has a public profile, we stop "syncing" their username
        # from Facebook, as they now have an opportunity to set it themself
        if not user_data.username:
            user_data.update_nickname()

        # Set developer and moderator to True if user is admin
        if ((not user_data.developer or not user_data.moderator)
                and users.is_current_user_admin()):
            user_data.developer = True
            user_data.moderator = True

        user_data.last_login = datetime.datetime.utcnow()
        user_data.put()

        complete_signup = self.request_bool("completesignup", default=False)
        if first_time:
            email_now_verified = None
            if user_data.has_sendable_email():
                email_now_verified = user_data.email

                # Look for a matching UnverifiedUser with the same e-mail
                # to see if the user used Google login to verify.
                unverified_user = user_models.UnverifiedUser.get_for_value(
                    email_now_verified)
                if unverified_user:
                    unverified_user.delete()

            # Note that we can only migrate phantom users right now if this
            # login is not going to lead to a "/completesignup" page, which
            # indicates the user has to finish more information in the
            # signup phase.
            if not complete_signup:
                # If user is brand new and has 0 points, migrate data.
                phantom_id = get_phantom_user_id_from_cookies()
                if phantom_id:
                    phantom_data = UserData.get_from_db_key_email(phantom_id)
                    if _upgrade_phantom_into(phantom_data, user_data):
                        cont = "/newaccount?continue=%s" % cont
        if complete_signup:
            cont = "/completesignup"

        self._finish_and_redirect(cont)