Example #1
0
    def __init__(self, request, response):
        # 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.user = current_user_services.get_current_user(self.request)
        self.user_id = current_user_services.get_user_id(
            self.user) if self.user else None

        if self.user_id:
            email = current_user_services.get_user_email(self.user)
            user_settings = user_services.get_or_create_user(
                self.user_id, email)
            self.username = user_settings.username

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

        self.is_moderator = rights_manager.Actor(self.user_id).is_moderator()
        self.is_admin = rights_manager.Actor(self.user_id).is_admin()
        self.is_super_admin = user_services.is_super_admin(
            self.user_id, self.request)

        self.values['is_moderator'] = self.is_moderator
        self.values['is_admin'] = self.is_admin
        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
Example #2
0
File: base.py Project: miyucy/oppia
    def __init__(self, request, response):
        # 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.user = current_user_services.get_current_user(self.request)
        self.user_id = current_user_services.get_user_id(
            self.user) if self.user else None

        if self.user_id:
            email = current_user_services.get_user_email(self.user)
            user_settings = user_services.get_or_create_user(
                self.user_id, email)
            self.username = user_settings.username

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

        self.is_moderator = rights_manager.Actor(self.user_id).is_moderator()
        self.is_admin = rights_manager.Actor(self.user_id).is_admin()
        self.is_super_admin = user_services.is_super_admin(
            self.user_id, self.request)

        self.values['is_moderator'] = self.is_moderator
        self.values['is_admin'] = self.is_admin
        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
Example #3
0
 def test_super_admin(self, **kwargs):
     """Checks if the user is logged in and is a super admin."""
     if not self.user_id:
         self.redirect(
             current_user_services.create_login_url(self.request.uri))
         return
     if not user_services.is_super_admin(self.user_id, self.request):
         raise self.UnauthorizedUserException(
             '%s is not a super admin of this application', self.user_id)
     return handler(self, **kwargs)
Example #4
0
 def test_super_admin(self, **kwargs):
     """Checks if the user is logged in and is a super admin."""
     if not self.user_id:
         self.redirect(
             current_user_services.create_login_url(self.request.uri))
         return
     if not user_services.is_super_admin(self.user_id, self.request):
         raise self.UnauthorizedUserException(
             '%s is not a super admin of this application', self.user_id)
     return handler(self, **kwargs)
Example #5
0
    def __init__(self, request, response):
        # 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.user = current_user_services.get_current_user(self.request)
        self.user_id = current_user_services.get_user_id(
            self.user) if self.user else None
        self.username = None
        self.user_has_started_state_editor_tutorial = False
        self.partially_logged_in = False
        self.values['profile_picture_data_url'] = None

        if self.user_id:
            email = current_user_services.get_user_email(self.user)
            user_settings = user_services.get_or_create_user(
                self.user_id, email)
            self.values['user_email'] = user_settings.email

            if self.REDIRECT_UNFINISHED_SIGNUPS and not user_settings.username:
                _clear_login_cookies(self.response.headers)
                self.partially_logged_in = True
                self.user_id = None
            else:
                self.username = user_settings.username
                self.last_agreed_to_terms = user_settings.last_agreed_to_terms
                self.values['username'] = self.username
                self.values['profile_picture_data_url'] = (
                    user_settings.profile_picture_data_url)
                if user_settings.last_started_state_editor_tutorial:
                    self.user_has_started_state_editor_tutorial = True

        self.is_moderator = rights_manager.Actor(self.user_id).is_moderator()
        self.is_admin = rights_manager.Actor(self.user_id).is_admin()
        self.is_super_admin = user_services.is_super_admin(
            self.user_id, self.request)

        self.values['is_moderator'] = self.is_moderator
        self.values['is_admin'] = self.is_admin
        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
Example #6
0
    def __init__(self, request, response):
        # 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.user = current_user_services.get_current_user(self.request)
        self.user_id = current_user_services.get_user_id(
            self.user) if self.user else None
        self.username = None
        self.user_has_started_state_editor_tutorial = False
        self.partially_logged_in = False
        self.values['profile_picture_data_url'] = None

        if self.user_id:
            email = current_user_services.get_user_email(self.user)
            user_settings = user_services.get_or_create_user(
                self.user_id, email)
            self.values['user_email'] = user_settings.email

            if (self.REDIRECT_UNFINISHED_SIGNUPS and not
                    user_services.has_fully_registered(self.user_id)):
                _clear_login_cookies(self.response.headers)
                self.partially_logged_in = True
                self.user_id = None
            else:
                self.username = user_settings.username
                self.values['username'] = self.username
                self.values['profile_picture_data_url'] = (
                    user_settings.profile_picture_data_url)
                if user_settings.last_started_state_editor_tutorial:
                    self.user_has_started_state_editor_tutorial = True

        self.is_moderator = rights_manager.Actor(self.user_id).is_moderator()
        self.is_admin = rights_manager.Actor(self.user_id).is_admin()
        self.is_super_admin = user_services.is_super_admin(
            self.user_id, self.request)

        self.values['is_moderator'] = self.is_moderator
        self.values['is_admin'] = self.is_admin
        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