Esempio n. 1
0
    def post(self):
        """Handles POST requests."""
        username = self.payload.get('username')
        agreed_to_terms = self.payload.get('agreed_to_terms')
        default_dashboard = self.payload.get('default_dashboard')
        can_receive_email_updates = self.payload.get(
            'can_receive_email_updates')
        bulk_email_signup_message_should_be_shown = False

        if can_receive_email_updates is not None:
            bulk_email_signup_message_should_be_shown = (
                user_services.update_email_preferences(
                    self.user_id, can_receive_email_updates,
                    feconf.DEFAULT_EDITOR_ROLE_EMAIL_PREFERENCE,
                    feconf.DEFAULT_FEEDBACK_MESSAGE_EMAIL_PREFERENCE,
                    feconf.DEFAULT_SUBSCRIPTION_EMAIL_PREFERENCE))
            if bulk_email_signup_message_should_be_shown:
                self.render_json({
                    'bulk_email_signup_message_should_be_shown':
                    (bulk_email_signup_message_should_be_shown)
                })
                return

        has_ever_registered = user_services.has_ever_registered(self.user_id)
        has_fully_registered_account = (
            user_services.has_fully_registered_account(self.user_id))

        if has_fully_registered_account:
            self.render_json({})
            return

        if not isinstance(agreed_to_terms, bool) or not agreed_to_terms:
            raise self.InvalidInputException(
                'In order to edit explorations on this site, you will '
                'need to accept the license terms.')
        else:
            user_services.record_agreement_to_terms(self.user_id)

        if not user_services.get_username(self.user_id):
            try:
                user_services.set_username(self.user_id, username)
            except utils.ValidationError as e:
                raise self.InvalidInputException(e)

        # Note that an email is only sent when the user registers for the first
        # time.
        if feconf.CAN_SEND_EMAILS and not has_ever_registered:
            email_manager.send_post_signup_email(self.user_id)

        user_services.generate_initial_profile_picture(self.user_id)

        if not has_ever_registered:
            # Set the default dashboard for new users.
            user_services.update_user_default_dashboard(
                self.user_id, default_dashboard)

        self.render_json({
            'bulk_email_signup_message_should_be_shown':
            (bulk_email_signup_message_should_be_shown)
        })
Esempio n. 2
0
    def test_root_redirect_rules_for_logged_in_creators(self):
        self.login(self.TEST_CREATOR_EMAIL)
        creator_user_id = self.get_user_id_from_email(self.TEST_CREATOR_EMAIL)
        # Set the default dashboard as creator dashboard.
        user_services.update_user_default_dashboard(
            creator_user_id, constants.DASHBOARD_TYPE_CREATOR)

        # Since the default dashboard has been set as creator dashboard, going
        # to '/' should redirect to the creator dashboard.
        response = self.get_html_response('/', expected_status_int=302)
        self.assertIn('creator_dashboard', response.headers['location'])
Esempio n. 3
0
    def map(item):
        user_contributions = user_services.get_user_contributions(item.id)
        user_is_creator = user_contributions and (
            user_contributions.created_exploration_ids
            or user_contributions.edited_exploration_ids)

        if user_is_creator:
            user_services.update_user_default_dashboard(
                item.id, constants.DASHBOARD_TYPE_CREATOR)
        else:
            user_services.update_user_default_dashboard(
                item.id, constants.DASHBOARD_TYPE_LEARNER)
Esempio n. 4
0
    def put(self):
        """Handles PUT requests."""
        update_type = self.payload.get('update_type')
        data = self.payload.get('data')
        bulk_email_signup_message_should_be_shown = False
        if update_type == 'user_bio':
            if len(data) > feconf.MAX_BIO_LENGTH_IN_CHARS:
                raise self.InvalidInputException(
                    'User bio exceeds maximum character limit: %s'
                    % feconf.MAX_BIO_LENGTH_IN_CHARS)

            user_services.update_user_bio(self.user_id, data)
        elif update_type == 'subject_interests':
            user_services.update_subject_interests(self.user_id, data)
        elif update_type == 'preferred_language_codes':
            user_services.update_preferred_language_codes(self.user_id, data)
        elif update_type == 'preferred_site_language_code':
            user_services.update_preferred_site_language_code(
                self.user_id, data)
        elif update_type == 'preferred_audio_language_code':
            user_services.update_preferred_audio_language_code(
                self.user_id, data)
        elif update_type == 'preferred_translation_language_code':
            user_services.update_preferred_translation_language_code(
                self.user_id, data)
        elif update_type == 'profile_picture_data_url':
            user_services.update_profile_picture_data_url(self.user_id, data)
        elif update_type == 'default_dashboard':
            user_services.update_user_default_dashboard(self.user_id, data)
        elif update_type == 'email_preferences':
            bulk_email_signup_message_should_be_shown = (
                user_services.update_email_preferences(
                    self.user_id, data['can_receive_email_updates'],
                    data['can_receive_editor_role_email'],
                    data['can_receive_feedback_message_email'],
                    data['can_receive_subscription_email']))
        else:
            raise self.InvalidInputException(
                'Invalid update type: %s' % update_type)

        self.render_json({
            'bulk_email_signup_message_should_be_shown': (
                bulk_email_signup_message_should_be_shown)
        })