Пример #1
0
    def log_in_success(self):
        '''If the login process is successful, sync with kano world
        and return success dialog text.
        '''
        logger.info('login successful')

        # saving hardware info and initial Kano version
        save_hardware_info()
        save_kano_version()

        # restore on first successful login/restore
        try:
            first_sync_done = profile['first_sync_done']
        except Exception:
            first_sync_done = False

        if not first_sync_done:
            logger.info(
                "running kano-sync --sync --restore after first time login"
            )

            # When both --sync and --restore are given as options, sync occurs
            # before the restore
            cmd = '{bin_dir}/kano-sync --sync -s --restore'.format(bin_dir=bin_dir)
            run_bg(cmd)

            save_profile_variable(
                'first_sync_done',
                True,
                skip_kdesk_refresh=True
            )

        else:
            logger.info("running kano-sync --sync after non-first login")

            # sync on each successful login
            cmd = '{bin_dir}/kano-sync --sync -s'.format(bin_dir=bin_dir)
            run_bg(cmd)

        title = _("Success!")
        description = _("You're in - online features now enabled.")
        return_value = 'SUCCESS'

        return (title, description, return_value)
Пример #2
0
    def log_in_success(self):
        '''If the login process is successful, sync with kano world
        and return success dialog text.
        '''
        logger.info('login successful')

        # saving hardware info and initial Kano version
        save_hardware_info()
        save_kano_version()

        # restore on first successful login/restore
        try:
            first_sync_done = profile['first_sync_done']
        except Exception:
            first_sync_done = False

        if not first_sync_done:
            logger.info('running kano-sync --sync && --sync && --restore after first time login')

            # doing first sync and restore
            cmd1 = '{bin_dir}/kano-sync --sync -s'.format(bin_dir=bin_dir)
            cmd2 = '{bin_dir}/kano-sync --sync -s'.format(bin_dir=bin_dir)
            cmd3 = '{bin_dir}/kano-sync --restore -s'.format(bin_dir=bin_dir)
            cmd = "{} && {} && {}".format(cmd1, cmd2, cmd3)
            run_bg(cmd)

            save_profile_variable('first_sync_done', True)

        else:
            logger.info('running kano-sync --sync after non-first login')

            # sync on each successful login
            cmd = '{bin_dir}/kano-sync --sync -s'.format(bin_dir=bin_dir)
            run_bg(cmd)

        title = _("Success!")
        description = _("You're in - online features now enabled.")
        return_value = "SUCCESS"

        return (title, description, return_value)
Пример #3
0
    def log_in_success(self):
        '''If the login process is successful, sync with kano world
        and return success dialog text.
        '''
        logger.info('login successful')

        # saving hardware info and initial Kano version
        save_hardware_info()
        save_kano_version()

        # restore on first successful login/restore
        try:
            first_sync_done = profile['first_sync_done']
        except Exception:
            first_sync_done = False

        if not first_sync_done:
            logger.info(
                "running kano-sync --sync --restore after first time login")

            # When both --sync and --restore are given as options, sync occurs
            # before the restore
            cmd = '{bin_dir}/kano-sync --sync -s --restore'.format(
                bin_dir=bin_dir)
            run_bg(cmd)

        else:
            logger.info("running kano-sync --sync after non-first login")

            # sync on each successful login
            cmd = '{bin_dir}/kano-sync --sync -s'.format(bin_dir=bin_dir)
            run_bg(cmd)

        title = _("Success!")
        description = _("You're in - online features now enabled.")
        return_value = 'SUCCESS'

        return (title, description, return_value)
    def register_user_with_gui(self):
        self.data_screen.cache_emails()
        self.data_screen.cache_marketing_choice()

        self.page_control.disable_buttons()
        self.data_screen.disable_all()
        self.get_email_data()

        # Make cursor into a spinner
        watch_cursor = Gdk.Cursor(Gdk.CursorType.WATCH)
        self.win.get_window().set_cursor(watch_cursor)

        # This means no threads are needed.
        while Gtk.events_pending():
            Gtk.main_iteration()

        # Try and register the account on the server
        email = self.win.data["email"]
        secondary_email = self.win.data["secondary_email"]
        username = self.win.data["username"]
        password = self.win.data["password"]
        date_year = self.win.data["year"]
        date_month = self.win.data["month"]
        date_day = self.win.data["day"]
        marketing_enabled = self.win.data["marketing_enabled"]

        logger.info('trying to register user with data {} {} {} {} {} {} {} {}'
                    .format(
                        email, secondary_email, username, password, date_year,
                        date_month, date_day, marketing_enabled
                    )
                    )

        success, text = register_(email, username, password,
                                  date_year, date_month, date_day,
                                  secondary_email=secondary_email,
                                  marketing_enabled=marketing_enabled)

        # This should no longer be needed, since this is checked in the first screen.
        # However there is a small chance someone could take the username
        # while the user is in the process of registering
        if not success:
            if text.strip() == "Cannot register, problem: Username already registered":

                logger.info('username invalid - getting second username')
                self.collect_new_username()
                return

            else:
                logger.info('problem with registration: {}'.format(text))
                return_value = "FAIL"
                self.create_dialog(
                    title=_("Houston, we have a problem"),
                    description=str(text)
                )
                track_data('world-registration-failed', {'reason': text})

        else:
            logger.info('registration successful')

            bday_date = str(datetime.date(date_year, date_month, date_day))
            save_profile_variable('birthdate', bday_date)

            # saving hardware info and initial Kano version
            save_hardware_info()
            save_kano_version()

            # running kano-sync after registration
            logger.info('running kano-sync after successful registration')
            cmd = '{bin_dir}/kano-sync --sync -s'.format(bin_dir=bin_dir)
            run_bg(cmd)

            return_value = "SUCCEED"
            self.create_dialog(
                title=_("Profile activated!"),
                description=_("Now you can share stuff, build your character, "
                              "and connect with friends.")
            )

        self.page_control.enable_buttons()
        self.data_screen.enable_all()
        self.win.get_window().set_cursor(None)

        # Close the app if it was successful
        if return_value == "SUCCEED":
            Gtk.main_quit()
    def _on_register_button(self, widget=None):  # TODO: refactor this
        """
        """
        if not is_internet():
            self._show_not_internet_dialog()
            return

        # Get the username, password and birthday
        data = self.data_screen.get_widget_data()
        email = data['email']
        username = data['username']

        # Validate that the email address format is correct
        email_error = validate_email(email)
        if email_error:
            self._show_error_dialog(_("Incorrect Email address"), email_error)
            return

        if not self._is_username_available(username):
            self._show_username_taken_dialog(username)
            return

        # We can save the username to kano-profile
        # Don't save password as this is private
        self.data_screen.save_username_and_birthday()  # TODO: rename this
        self.data_screen.cache_emails()
        data = self.data_screen.get_widget_data()

        # This means no threads are needed.
        while Gtk.events_pending():  # TODO: why is this needed?
            Gtk.main_iteration()

        # Try and register the account on the server
        password = data['password']
        success, text = register_(email,
                                  username,
                                  password,
                                  marketing_enabled=True)

        # This should no longer be needed, since this is checked in the first
        # screen. However there is a small chance someone could take the
        # username while the user is in the process of registering
        if not success:
            if text.strip() == _("Cannot register, problem: "
                                 "Username already registered"):

                self._show_username_taken_dialog(username)

            else:
                logger.info("problem with registration: {}".format(text))
                return_value = 'FAIL'
                self._create_dialog(title=_("Houston, we have a problem"),
                                    description=str(text))
                track_data('world-registration-failed', {'reason': text})

        else:
            logger.info("registration successful")

            # saving hardware info and initial Kano version
            save_hardware_info()
            save_kano_version()

            # running kano-sync after registration
            logger.info("running kano-sync after successful registration")
            cmd = '{bin_dir}/kano-sync --sync -s'.format(bin_dir=bin_dir)
            run_bg(cmd)

            return_value = 'SUCCEED'
            self._create_dialog(
                title=_("Profile activated!"),
                description=_("Now you can share stuff, build your character, "
                              "and connect with friends."))

        self.win.get_window().set_cursor(None)

        # Close the app if it was successful
        if return_value == 'SUCCEED':
            Gtk.main_quit()
    def _on_register_button(self, widget=None):  # TODO: refactor this
        """
        """
        if not is_internet():
            self._show_not_internet_dialog()
            return

        # Get the username, password and birthday
        data = self.data_screen.get_widget_data()
        email = data['email']
        username = data['username']

        # Validate that the email address format is correct
        email_error = validate_email(email)
        if email_error:
            self._show_error_dialog(_("Incorrect Email address"), email_error)
            return

        if not self._is_username_available(username):
            self._show_username_taken_dialog(username)
            return

        # We can save the username to kano-profile
        # Don't save password as this is private
        self.data_screen.save_username_and_birthday()  # TODO: rename this
        self.data_screen.cache_emails()
        data = self.data_screen.get_widget_data()

        # This means no threads are needed.
        while Gtk.events_pending():  # TODO: why is this needed?
            Gtk.main_iteration()

        # Try and register the account on the server
        password = data['password']
        success, text = register_(email, username, password,
                                  marketing_enabled=True)

        # This should no longer be needed, since this is checked in the first
        # screen. However there is a small chance someone could take the
        # username while the user is in the process of registering
        if not success:
            if text.strip() == _("Cannot register, problem: "
               "Username already registered"):

                self._show_username_taken_dialog(username)

            else:
                logger.info("problem with registration: {}".format(text))
                return_value = 'FAIL'
                self._create_dialog(
                    title=_("Houston, we have a problem"),
                    description=str(text)
                )
                track_data('world-registration-failed', {'reason': text})

        else:
            logger.info("registration successful")

            # saving hardware info and initial Kano version
            save_hardware_info()
            save_kano_version()

            # running kano-sync after registration
            logger.info("running kano-sync after successful registration")
            cmd = '{bin_dir}/kano-sync --sync -s'.format(bin_dir=bin_dir)
            run_bg(cmd)

            return_value = 'SUCCEED'
            self._create_dialog(
                title=_("Profile activated!"),
                description=_("Now you can share stuff, build your character, "
                              "and connect with friends.")
            )

        self.win.get_window().set_cursor(None)

        # Close the app if it was successful
        if return_value == 'SUCCEED':
            Gtk.main_quit()