Exemple #1
0
 def get(self):
     """Handles GET requests."""
     # The following headers are added to prevent caching of this response.
     self.response.cache_control.no_store = True
     if self.username:
         user_actions = user_services.get_user_actions_info(
             self.user_id).actions
         user_settings = user_services.get_user_settings(self.user_id,
                                                         strict=False)
         self.render_json({
             'roles':
             self.roles,
             'is_moderator': (user_services.is_moderator(self.user_id)),
             'is_curriculum_admin':
             user_services.is_curriculum_admin(self.user_id),
             'is_super_admin':
             self.current_user_is_super_admin,
             'is_topic_manager':
             (user_services.is_topic_manager(self.user_id)),
             'can_create_collections':
             bool(role_services.ACTION_CREATE_COLLECTION in user_actions),
             'preferred_site_language_code':
             (user_settings.preferred_site_language_code),
             'username':
             user_settings.username,
             'email':
             user_settings.email,
             'user_is_logged_in':
             True
         })
     else:
         self.render_json({'user_is_logged_in': False})
Exemple #2
0
    def __init__(self, request, response):  # pylint: disable=super-init-not-called
        # Set self.request, self.response and self.app.
        self.initialize(request, response)

        self.start_time = datetime.datetime.utcnow()

        # Initializes the return dict for the handlers.
        self.values = {}

        self.gae_id = current_user_services.get_current_gae_id()
        self.user_id = None
        self.username = None
        self.partially_logged_in = False

        if self.gae_id:
            user_settings = user_services.get_user_settings_by_gae_id(
                self.gae_id, strict=False)
            if user_settings is None:
                email = current_user_services.get_current_user_email()
                user_settings = user_services.create_new_user(
                    self.gae_id, email)
            self.values['user_email'] = user_settings.email
            self.user_id = user_settings.user_id

            if (self.REDIRECT_UNFINISHED_SIGNUPS
                    and not user_services.has_fully_registered(
                        user_settings.user_id)):
                _clear_login_cookies(self.response.headers)
                self.partially_logged_in = True
            else:
                self.username = user_settings.username
                self.values['username'] = self.username
                # In order to avoid too many datastore writes, we do not bother
                # recording a log-in if the current time is sufficiently close
                # to the last log-in time.
                if (user_settings.last_logged_in is None
                        or not utils.are_datetimes_close(
                            datetime.datetime.utcnow(),
                            user_settings.last_logged_in)):
                    user_services.record_user_logged_in(self.user_id)

        self.role = (feconf.ROLE_ID_GUEST
                     if self.user_id is None else user_settings.role)
        self.user = user_services.UserActionsInfo(self.user_id)

        self.is_super_admin = (
            current_user_services.is_current_user_super_admin())

        self.values['iframed'] = False
        self.values['is_moderator'] = user_services.is_at_least_moderator(
            self.user_id)
        self.values['is_admin'] = user_services.is_admin(self.user_id)
        self.values['is_topic_manager'] = (user_services.is_topic_manager(
            self.user_id))
        self.values['is_super_admin'] = self.is_super_admin

        if self.request.get('payload'):
            self.payload = json.loads(self.request.get('payload'))
        else:
            self.payload = None
Exemple #3
0
 def get(self):
     """Handles GET requests."""
     if self.username:
         user_actions = user_services.UserActionsInfo(self.user_id).actions
         user_settings = user_services.get_user_settings(
             self.user_id, strict=False)
         self.render_json({
             'is_moderator': (
                 user_services.is_at_least_moderator(self.user_id)),
             'is_admin': user_services.is_admin(self.user_id),
             'is_super_admin': (
                 current_user_services.is_current_user_super_admin()),
             'is_topic_manager': (
                 user_services.is_topic_manager(self.user_id)),
             'can_create_collections': bool(
                 role_services.ACTION_CREATE_COLLECTION in user_actions),
             'preferred_site_language_code': (
                 user_settings.preferred_site_language_code),
             'username': user_settings.username,
             'email': user_services.get_email_from_username(
                 user_settings.username),
             'user_is_logged_in': True
         })
     else:
         self.render_json({
             'user_is_logged_in': False
         })
Exemple #4
0
    def __init__(self, request, response):  # pylint: disable=super-init-not-called
        # Set self.request, self.response and self.app.
        self.initialize(request, response)

        self.start_time = datetime.datetime.utcnow()

        # Initializes the return dict for the handlers.
        self.values = {}

        if self.request.get('payload'):
            self.payload = json.loads(self.request.get('payload'))
        else:
            self.payload = None
        self.iframed = False

        auth_claims = auth_services.get_auth_claims_from_request(request)
        self.current_user_is_super_admin = (auth_claims is not None and
                                            auth_claims.role_is_super_admin)

        if (feconf.ENABLE_MAINTENANCE_MODE
                and not self.current_user_is_super_admin):
            return

        self.user_id = None
        self.username = None
        self.partially_logged_in = False
        self.user_is_scheduled_for_deletion = False

        if auth_claims:
            auth_id = auth_claims.auth_id
            user_settings = user_services.get_user_settings_by_auth_id(auth_id)
            if user_settings is None:
                # If the user settings are not yet created and the request leads
                # to signup page create a new user settings. Otherwise logout
                # the not-fully registered user.
                email = auth_claims.email
                if 'signup?' in self.request.uri:
                    user_settings = (user_services.create_new_user(
                        auth_id, email))
                else:
                    logging.error(
                        'Cannot find user %s with email %s on page %s' %
                        (auth_id, email, self.request.uri))
                    auth_services.destroy_auth_session(self.response)
                    return

            self.values['user_email'] = user_settings.email
            self.user_id = user_settings.user_id

            if user_settings.deleted:
                self.user_is_scheduled_for_deletion = user_settings.deleted
            elif (self.REDIRECT_UNFINISHED_SIGNUPS
                  and not user_services.has_fully_registered_account(
                      self.user_id)):
                self.partially_logged_in = True
            else:
                self.username = user_settings.username
                self.values['username'] = self.username
                # In order to avoid too many datastore writes, we do not bother
                # recording a log-in if the current time is sufficiently close
                # to the last log-in time.
                if (user_settings.last_logged_in is None
                        or not utils.are_datetimes_close(
                            datetime.datetime.utcnow(),
                            user_settings.last_logged_in)):
                    user_services.record_user_logged_in(self.user_id)

        self.role = (feconf.ROLE_ID_GUEST
                     if self.user_id is None else user_settings.role)
        self.user = user_services.get_user_actions_info(self.user_id)

        self.values['is_moderator'] = (user_services.is_at_least_moderator(
            self.user_id))
        self.values['is_admin'] = user_services.is_admin(self.user_id)
        self.values['is_topic_manager'] = (user_services.is_topic_manager(
            self.user_id))
        self.values['is_super_admin'] = self.current_user_is_super_admin
Exemple #5
0
    def __init__(self, request, response):  # pylint: disable=super-init-not-called
        # Set self.request, self.response and self.app.
        self.initialize(request, response)

        self.start_time = datetime.datetime.utcnow()

        # Initializes the return dict for the handlers.
        self.values = {}

        if self.request.get('payload'):
            self.payload = json.loads(self.request.get('payload'))
        else:
            self.payload = None
        self.iframed = False

        self.is_super_admin = user_services.is_current_user_super_admin()
        if feconf.ENABLE_MAINTENANCE_MODE and not self.is_super_admin:
            return

        self.gae_id = user_services.get_current_gae_id()
        self.user_id = None
        self.username = None
        self.partially_logged_in = False
        self.user_is_scheduled_for_deletion = False

        # TODO(#11462): This part should be moved to the service layer when we
        # migrate to Firebase.
        if self.gae_id:
            user_settings = user_services.get_user_settings_by_gae_id(
                self.gae_id, strict=False)
            if user_settings is None:
                # If the user settings are not yet created and the request leads
                # to signup page create a new user settings. Otherwise logout
                # the not-fully registered user.
                email = user_services.get_current_user_email()
                if 'signup?' in self.request.uri:
                    user_settings = user_services.create_new_user(
                        self.gae_id, email)
                else:
                    logging.error(
                        'Cannot find user %s with email %s on page %s' %
                        (self.gae_id, email, self.request.uri))
                    _clear_login_cookies(self.response.headers)
                    return

            self.values['user_email'] = user_settings.email
            self.user_id = user_settings.user_id

            if user_settings.deleted:
                self.user_is_scheduled_for_deletion = user_settings.deleted
            elif (self.REDIRECT_UNFINISHED_SIGNUPS
                  and not user_services.has_fully_registered_account(
                      user_settings.user_id)):
                self.partially_logged_in = True
            else:
                self.username = user_settings.username
                self.values['username'] = self.username
                # In order to avoid too many datastore writes, we do not bother
                # recording a log-in if the current time is sufficiently close
                # to the last log-in time.
                if (user_settings.last_logged_in is None
                        or not utils.are_datetimes_close(
                            datetime.datetime.utcnow(),
                            user_settings.last_logged_in)):
                    user_services.record_user_logged_in(self.user_id)

        self.role = (feconf.ROLE_ID_GUEST
                     if self.user_id is None else user_settings.role)
        self.user = user_services.UserActionsInfo(self.user_id)

        self.values['is_moderator'] = user_services.is_at_least_moderator(
            self.user_id)
        self.values['is_admin'] = user_services.is_admin(self.user_id)
        self.values['is_topic_manager'] = (user_services.is_topic_manager(
            self.user_id))
        self.values['is_super_admin'] = self.is_super_admin