def __init__(self, win, prev_screen=None, first_boot=False): Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL) self.win = win self.win.set_main_widget(self) self.win.set_decorated(True) self.win.set_size_request(self.width, -1) self.first_boot = first_boot self.heading = Heading(_("Login"), _("Enter your username and password")) self.pack_start(self.heading.container, False, False, 10) if force_login: self.add_username_as_label() else: align = Gtk.Alignment(xscale=0, xalign=0.5) self.pack_start(align, False, False, 15) self.labelled_entries = LabelledEntries([ {"heading": _("Username"), "subheading": ""}, {"heading": _("Password"), "subheading": ""} ]) self.labelled_entries.set_spacing(15) self.username_entry = self.labelled_entries.get_entry(0) self.password_entry = self.labelled_entries.get_entry(1) align.add(self.labelled_entries) self.password_entry.set_visibility(False) for entry in self.labelled_entries.get_entries(): entry.connect("key_release_event", self.enable_kano_button) entry.connect("key-release-event", self.activate) self.button_box = KanoButtonBox( _("Login").upper(), _("Create New"), _("Forgotten password?") ) self.button_box.set_spacing(40) self.button_box.set_margin_left(80) self.button_box.set_margin_bottom(30) self.kano_button = self.button_box.kano_button self.button_box.set_orange_button_cb(self.go_to_registration) self.button_box.set_orange_button2_cb(self.reset_password_screen) self.kano_button.connect("button_release_event", self.activate) self.kano_button.connect("key-release-event", self.activate) self.pack_start(self.button_box, False, False, 20) self.kano_button.set_sensitive(False) if not force_login: self.username_entry.grab_focus() else: self.password_entry.grab_focus() self.win.show_all()
def __init__(self, win, prev_screen=None, first_boot=False): Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL) self.win = win self.win.set_main_widget(self) self.win.set_decorated(True) self.win.set_size_request(self.width, -1) self.first_boot = first_boot self.heading = Heading(_("Login"), _("Enter your username and password")) self.pack_start(self.heading.container, False, False, 10) if force_login: self.add_username_as_label() else: align = Gtk.Alignment(xscale=0, xalign=0.5) self.pack_start(align, False, False, 15) self.labelled_entries = LabelledEntries([{ 'heading': _("Username"), 'subheading': "" }, { 'heading': _("Password"), 'subheading': "" }]) self.labelled_entries.set_spacing(15) self.username_entry = self.labelled_entries.get_entry(0) self.password_entry = self.labelled_entries.get_entry(1) align.add(self.labelled_entries) self.password_entry.set_visibility(False) for entry in self.labelled_entries.get_entries(): entry.connect('key_release_event', self.enable_kano_button) entry.connect('key-release-event', self.activate) self.button_box = KanoButtonBox(_("LOGIN"), _("Create New"), _("Forgot your password?"), _("Or your username?")) self.button_box.set_spacing(40) self.button_box.set_margin_left(70) self.button_box.set_margin_right(70) self.button_box.set_margin_bottom(30) self.kano_button = self.button_box.kano_button self.button_box.set_orange_button_cb(self.go_to_registration) self.button_box.set_orange_button2_cb(self.reset_password_screen) self.button_box.set_orange_button3_cb(self.recover_username_screen) self.kano_button.connect('button_release_event', self.activate) self.kano_button.connect('key-release-event', self.activate) self.pack_start(self.button_box, False, False, 20) self.kano_button.set_sensitive(False) if not force_login: self.username_entry.grab_focus() else: self.password_entry.grab_focus() self.win.show_all()
class Login(Gtk.Box): width = 550 def __init__(self, win, prev_screen=None, first_boot=False): Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL) self.win = win self.win.set_main_widget(self) self.win.set_decorated(True) self.win.set_size_request(self.width, -1) self.first_boot = first_boot self.heading = Heading(_("Login"), _("Enter your username and password")) self.pack_start(self.heading.container, False, False, 10) if force_login: self.add_username_as_label() else: align = Gtk.Alignment(xscale=0, xalign=0.5) self.pack_start(align, False, False, 15) self.labelled_entries = LabelledEntries([ {"heading": _("Username"), "subheading": ""}, {"heading": _("Password"), "subheading": ""} ]) self.labelled_entries.set_spacing(15) self.username_entry = self.labelled_entries.get_entry(0) self.password_entry = self.labelled_entries.get_entry(1) align.add(self.labelled_entries) self.password_entry.set_visibility(False) for entry in self.labelled_entries.get_entries(): entry.connect("key_release_event", self.enable_kano_button) entry.connect("key-release-event", self.activate) self.button_box = KanoButtonBox( _("Login").upper(), _("Create New"), _("Forgotten password?") ) self.button_box.set_spacing(40) self.button_box.set_margin_left(80) self.button_box.set_margin_bottom(30) self.kano_button = self.button_box.kano_button self.button_box.set_orange_button_cb(self.go_to_registration) self.button_box.set_orange_button2_cb(self.reset_password_screen) self.kano_button.connect("button_release_event", self.activate) self.kano_button.connect("key-release-event", self.activate) self.pack_start(self.button_box, False, False, 20) self.kano_button.set_sensitive(False) if not force_login: self.username_entry.grab_focus() else: self.password_entry.grab_focus() self.win.show_all() def add_username_as_label(self): '''This replaces the username entry with a label containing the username. ''' username = get_mixed_username() title_label = Gtk.Label(_(" Username: "******"bold_label") self.username_label.get_style_context().add_class("desc_label") hbox = Gtk.Box() hbox.pack_start(title_label, False, False, 0) hbox.pack_start(self.username_label, False, False, 0) vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) vbox.pack_start(hbox, False, False, 0) align = Gtk.Alignment(xscale=0, xalign=0.5) align.add(vbox) # Needs adjustment align.set_padding(0, 0, 100, 0) self.pack_start(align, False, False, 15) self.labelled_entries = LabelledEntries( [{"heading": _("Password"), "subheading": ""}] ) self.password_entry = self.labelled_entries.get_entry(0) vbox.pack_start(self.labelled_entries, False, False, 15) def enable_kano_button(self, widget=None, event=None): '''This enables the login button if both the username entry and password entry are non empty. This is linked to the key-release-event on the password and username entries. ''' text0 = self.get_username_input() text1 = self.password_entry.get_text() if text0 != "" and text1 != "": self.kano_button.set_sensitive(True) else: self.kano_button.set_sensitive(False) def get_username_input(self): '''Get the username text from the username entry or label. ''' if force_login: text = self.username_label.get_text() else: text = self.username_entry.get_text() return text def repack(self): self.win.remove_main_widget() self.win.set_main_widget(self) def go_to_registration(self, widget, event, args=[]): '''Go to the first registration screen. ''' self.win.remove_main_widget() RegistrationScreen1(self.win) def activate(self, widget, event): if not hasattr(event, 'keyval') or event.keyval == 65293: watch_cursor = Gdk.Cursor(Gdk.CursorType.WATCH) self.win.get_window().set_cursor(watch_cursor) self.kano_button.start_spinner() self.kano_button.set_sensitive(False) thread = threading.Thread(target=self.log_user_in) thread.start() def log_user_in(self): if not is_internet(): title = _("You don't have internet!") description = _( "Connect with wifi or ethernet and try again" ) return_value = 0 else: (title, description, return_value) = self.log_user_in_with_internet() GObject.idle_add(self.show_login_status_dialog, title, description, return_value) def log_user_in_with_internet(self): '''If we know the user has internet, attempt to login. ''' username_text = self.get_username_input() password_text = self.password_entry.get_text() success, text = login_(username_text, password_text) if not success: logger.info('problem with login: {}'.format(text)) title = _("Houston, we have a problem") description = text return_value = "FAIL" else: (title, description, return_value) = self.log_in_success() return (title, description, return_value) 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) def show_login_status_dialog(self, title, description, return_value): '''Show a dialog with the title, description and that returns the return_value. Since this is used at the end of the login process, we also reset the cursor and kano button spinner. ''' kdialog = KanoDialog(title, description, {_("OK"): {"return_value": return_value}}, parent_window=self.win) response = kdialog.run() if response == "SUCCESS": if self.first_boot: self.win.remove_main_widget() SwagScreen(self.win) else: sys.exit(0) # If the login didn't work, try again. self.win.get_window().set_cursor(None) self.kano_button.stop_spinner() self.kano_button.set_sensitive(True) if not force_login: self.username_entry.grab_focus() def reset_password_screen(self, button, event, args): self.win.remove_main_widget() ResetPassword(self.win)
class Login(Gtk.Box): width = 550 def __init__(self, win, prev_screen=None, first_boot=False): Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL) self.win = win self.win.set_main_widget(self) self.win.set_decorated(True) self.win.set_size_request(self.width, -1) self.first_boot = first_boot self.heading = Heading(_("Login"), _("Enter your username and password")) self.pack_start(self.heading.container, False, False, 10) if force_login: self.add_username_as_label() else: align = Gtk.Alignment(xscale=0, xalign=0.5) self.pack_start(align, False, False, 15) self.labelled_entries = LabelledEntries([{ 'heading': _("Username"), 'subheading': "" }, { 'heading': _("Password"), 'subheading': "" }]) self.labelled_entries.set_spacing(15) self.username_entry = self.labelled_entries.get_entry(0) self.password_entry = self.labelled_entries.get_entry(1) align.add(self.labelled_entries) self.password_entry.set_visibility(False) for entry in self.labelled_entries.get_entries(): entry.connect('key_release_event', self.enable_kano_button) entry.connect('key-release-event', self.activate) self.button_box = KanoButtonBox(_("LOGIN"), _("Create New"), _("Forgot your password?"), _("Or your username?")) self.button_box.set_spacing(40) self.button_box.set_margin_left(70) self.button_box.set_margin_right(70) self.button_box.set_margin_bottom(30) self.kano_button = self.button_box.kano_button self.button_box.set_orange_button_cb(self.go_to_registration) self.button_box.set_orange_button2_cb(self.reset_password_screen) self.button_box.set_orange_button3_cb(self.recover_username_screen) self.kano_button.connect('button_release_event', self.activate) self.kano_button.connect('key-release-event', self.activate) self.pack_start(self.button_box, False, False, 20) self.kano_button.set_sensitive(False) if not force_login: self.username_entry.grab_focus() else: self.password_entry.grab_focus() self.win.show_all() def add_username_as_label(self): '''This replaces the username entry with a label containing the username. ''' username = get_mixed_username() title_label = Gtk.Label(_(" Username: "******"Password"), 'subheading': "" }]) self.password_entry = self.labelled_entries.get_entry(0) vbox.pack_start(self.labelled_entries, False, False, 15) def enable_kano_button(self, widget=None, event=None): '''This enables the login button if both the username entry and password entry are non empty. This is linked to the key-release-event on the password and username entries. ''' text0 = self.get_username_input() text1 = self.password_entry.get_text() if text0 != "" and text1 != "": self.kano_button.set_sensitive(True) else: self.kano_button.set_sensitive(False) def get_username_input(self): '''Get the username text from the username entry or label. ''' if force_login: text = self.username_label.get_text() else: text = self.username_entry.get_text() return text def repack(self): self.win.remove_main_widget() self.win.set_main_widget(self) def go_to_registration(self, widget, event, args=[]): '''Go to the first registration screen. ''' self.win.remove_main_widget() RegistrationScreen(self.win) def activate(self, widget, event): if not hasattr(event, 'keyval') or event.keyval == 65293: watch_cursor = Gdk.Cursor(Gdk.CursorType.WATCH) self.win.get_window().set_cursor(watch_cursor) self.kano_button.start_spinner() self.kano_button.set_sensitive(False) thread = threading.Thread(target=self.log_user_in) thread.start() def log_user_in(self): if not is_internet(): title = _("You don't have internet!") description = _("Connect with wifi or ethernet and try again") return_value = 0 else: (title, description, return_value) = self.log_user_in_with_internet() GObject.idle_add(self.show_login_status_dialog, title, description, return_value) def log_user_in_with_internet(self): '''If we know the user has internet, attempt to login. ''' username_text = self.get_username_input() password_text = self.password_entry.get_text() success, text = login_(username_text, password_text) if not success: logger.info("problem with login: {}".format(text)) title = _("Houston, we have a problem") description = text return_value = 'FAIL' else: (title, description, return_value) = self.log_in_success() return (title, description, return_value) 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 show_login_status_dialog(self, title, description, return_value): '''Show a dialog with the title, description and that returns the return_value. Since this is used at the end of the login process, we also reset the cursor and kano button spinner. ''' kdialog = KanoDialog(title, description, {_("OK"): { 'return_value': return_value }}, parent_window=self.win) response = kdialog.run() if response == 'SUCCESS': if self.first_boot: self.win.remove_main_widget() SwagScreen(self.win) else: sys.exit(0) # If the login didn't work, try again. self.win.get_window().set_cursor(None) self.kano_button.stop_spinner() self.kano_button.set_sensitive(True) if not force_login: self.username_entry.grab_focus() def reset_password_screen(self, button, event, args): self.win.remove_main_widget() ResetPassword(self.win) def recover_username_screen(self, button, event, args): self.win.remove_main_widget() RecoverUsername(self.win)