コード例 #1
0
ファイル: decorators.py プロジェクト: johnfelipe/server
        def wrapper(*args, **kwargs):
            if is_valid_request(request):
                try:
                    consumer, token, parameters = validate_token(request)
                    if (not consumer) or (not token):
                        return oauth_error_response(OAuthError(
                                "Not valid consumer or token"))
                    # If this API method requires an anointed consumer,
                    # restrict any that haven't been manually approved.
                    if require_anointed_consumer and not consumer.anointed:
                        return oauth_error_response(OAuthError(
                                "Consumer access denied."))

                    # Store the OAuthMap containing all auth info in the request
                    # global for easy access during the rest of this request.
                    flask.g.oauth_map = OAuthMap.get_from_access_token(token.key_)

                    if not util.get_current_user_id():
                        # If our OAuth provider thinks you're logged in but the
                        # identity providers we consume (Google/Facebook)
                        # disagree, we act as if our token is no longer valid.
                        return oauth_error_response(OAuthError(
                            "Unable to get current user from oauth token"))

                except OAuthError, e:
                    return oauth_error_response(e)
コード例 #2
0
        def wrapper(*args, **kwargs):
            if is_valid_request(request):
                try:
                    consumer, token, parameters = validate_token(request)
                    if consumer and token:

                        # Store the OAuthMap containing all auth info in the request global
                        # for easy access during the rest of this request.
                        flask.g.oauth_map = OAuthMap.get_from_access_token(
                            token.key_)

                        # If this API method requires an anointed consumer,
                        # restrict any that haven't been manually approved.
                        if require_anointed_consumer and not consumer.anointed:
                            flask.g.oauth_map = None

                        if not util.get_current_user_id():
                            # If our OAuth provider thinks you're logged in but the
                            # identity providers we consume (Google/Facebook) disagree,
                            # we act as if our token is no longer valid.
                            flask.g.oauth_map = None

                except OAuthError, e:
                    # OAuthErrors are ignored, treated as user that's just not logged in
                    pass
コード例 #3
0
ファイル: decorators.py プロジェクト: avh4/khan-academy
        def wrapper(*args, **kwargs):
            if is_valid_request(request):
                try:
                    consumer, token, parameters = validate_token(request)
                    if consumer and token:

                        # Store the OAuthMap containing all auth info in the request global
                        # for easy access during the rest of this request.
                        flask.g.oauth_map = OAuthMap.get_from_access_token(token.key_)

                        if not util.get_current_user_id():
                            # If our OAuth provider thinks you're logged in but the
                            # identity providers we consume (Google/Facebook) disagree,
                            # we act as if our token is no longer valid.
                            flask.g.oauth_map = None

                except OAuthError, e:
                    # OAuthErrors are ignored, treated as user that's just not logged in
                    pass
コード例 #4
0
    def get(self):
        cont = self.request_string('continue', default = "/")

        # Immediately after login we make sure this user has a UserData entity
        user_data = UserData.current()
        if user_data:

            # Update email address if it has changed
            current_google_user = users.get_current_user()
            if current_google_user and current_google_user.email() != user_data.email:
                user_data.user_email = current_google_user.email()
                user_data.put()

            # Update nickname if it has changed
            current_nickname = get_nickname_for(user_data)
            if user_data.user_nickname != current_nickname:
                user_data.user_nickname = current_nickname
                user_data.put()

            # 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.put()

            # 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)

                # First make sure user has 0 points and phantom user has some activity
                if user_data.points == 0 and phantom_data and phantom_data.points > 0:

                    # Make sure user has no students
                    if not user_data.has_students():

                        # Clear all "login" notifications
                        UserNotifier.clear_all(phantom_data)

                        # Update phantom user_data to real user_data
                        phantom_data.user_id = user_data.user_id
                        phantom_data.current_user = user_data.current_user
                        phantom_data.user_email = user_data.user_email
                        phantom_data.user_nickname = user_data.user_nickname

                        if phantom_data.put():
                            # Phantom user was just transitioned to real user
                            user_counter.add(1)
                            user_data.delete()

                        cont = "/newaccount?continue=%s" % cont
        else:

            # If nobody is logged in, clear any expired Facebook cookie that may be hanging around.
            self.delete_cookie("fbsr_" + App.facebook_app_id)
            self.delete_cookie("fbs_" + App.facebook_app_id)

            logging.critical("Missing UserData during PostLogin, with id: %s, cookies: (%s), google user: %s" % (
                    util.get_current_user_id(), os.environ.get('HTTP_COOKIE', ''), users.get_current_user()
                )
            )

        # Always delete phantom user cookies on login
        self.delete_cookie('ureg_id')

        self.redirect(cont)