def _new_user_reboot(self, event=None, button=None): ''' Schedules kano-init to create a new user from scratch on next reboot, then performs the actual reboot ''' confirm = KanoDialog( title_text=_('Are you sure you want to create a new account?'), description_text=_('A reboot will be required'), button_dict=[ { 'label': _('Cancel').upper(), 'color': 'red', 'return_value': False }, { 'label': _('Create').upper(), 'color': 'green', 'return_value': True } ]) confirm.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS) if confirm.run(): os.system("sudo kano-init schedule add-user") LightDM.restart()
def delete_user(self, *args): import pam password_input = Gtk.Entry() password_input.set_visibility(False) password_input.set_alignment(0.5) confirm = KanoDialog( title_text = _('Are you sure you want to delete this account?'), description_text = _('Enter {}\'s password - A reboot will be required'.format(self.user)), widget=password_input, has_entry=True, button_dict = [ { 'label': _('Cancel').upper(), 'color': 'red', 'return_value': False }, { 'label': _('Ok').upper(), 'color': 'green', 'return_value': True } ]) confirm.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS) # Kano Dialog will return False if cancel button is clicked, or text from the entry field if Ok response=confirm.run() if response == False: return elif type(response) == str and not len(response): error = KanoDialog(title_text = _('Please enter the password for user {}'.format(self.user))) error.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS) error.run() return else: password=response # Authenticate user and schedule removal. Protect against unknown troubles. try: if pam.authenticate(self.user, password): info = KanoDialog(title_text = _('User {} scheduled for removal'.format(self.user)), \ description_text = _('Press OK to reboot')) info.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS) info.run() os.system('sudo kano-init schedule delete-user "{}"'.format(self.user)) LightDM.restart() else: error = KanoDialog(title_text = _('Incorrect password for user {}'.format(self.user))) error.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS) error.run() except Exception as e: logger.error('Error deleting account {} - {}'.format(self.user, str(e))) error = KanoDialog(title_text = _('Could not delete account {}'.format(self.user))) error.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS) error.run()
def delete_user(self, *args): import pam password_input = Gtk.Entry() password_input.set_visibility(False) password_input.set_alignment(0.5) confirm = KanoDialog( title_text=_('Are you sure you want to delete this account?'), description_text=_( 'Enter {}\'s password - A reboot will be required'.format( self.user)), widget=password_input, has_entry=True, button_dict=[{ 'label': _('Cancel').upper(), 'color': 'red', 'return_value': False }, { 'label': _('Ok').upper(), 'color': 'green', 'return_value': True }]) confirm.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS) # Kano Dialog will return False if cancel button is clicked, or text from the entry field if Ok response = confirm.run() if response == False: return elif type(response) == str and not len(response): error = KanoDialog(title_text=_( 'Please enter the password for user {}'.format(self.user))) error.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS) error.run() return else: password = response # Authenticate user and schedule removal. Protect against unknown troubles. try: if pam.authenticate(self.user, password): info = KanoDialog(title_text = _('User {} scheduled for removal'.format(self.user)), \ description_text = _('Press OK to reboot')) info.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS) info.run() os.system('sudo kano-init schedule delete-user "{}"'.format( self.user)) LightDM.restart() else: error = KanoDialog(title_text=_( 'Incorrect password for user {}'.format(self.user))) error.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS) error.run() except Exception as e: logger.error('Error deleting account {} - {}'.format( self.user, str(e))) error = KanoDialog( title_text=_('Could not delete account {}'.format(self.user))) error.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS) error.run()
def restart(self): return LightDM.restart()