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