Package pyanaconda :: Package iw :: Module account_gui
[hide private]
[frames] | no frames]

Source Code for Module pyanaconda.iw.account_gui

  1  # 
  2  # account_gui.py: gui root password and crypt algorithm dialog 
  3  # 
  4  # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005,  Red Hat Inc. 
  5  #               2006, 2007, 2008 
  6  # All rights reserved. 
  7  # 
  8  # This program is free software; you can redistribute it and/or modify 
  9  # it under the terms of the GNU General Public License as published by 
 10  # the Free Software Foundation; either version 2 of the License, or 
 11  # (at your option) any later version. 
 12  # 
 13  # This program is distributed in the hope that it will be useful, 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 16  # GNU General Public License for more details. 
 17  # 
 18  # You should have received a copy of the GNU General Public License 
 19  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 20  # 
 21   
 22  import gtk 
 23  import string 
 24  from pyanaconda import gui 
 25  from iw_gui import * 
 26  from pyanaconda.flags import flags 
 27  from pyanaconda.constants import * 
 28  import pwquality 
 29  from pyanaconda import _isys 
 30   
 31  import gettext 
 32  _ = lambda x: gettext.ldgettext("anaconda", x) 
 33   
34 -class AccountWindow (InstallWindow):
35 - def getScreen(self, anaconda):
36 self.anaconda = anaconda 37 self.intf = anaconda.intf 38 39 (self.xml, self.align) = gui.getGladeWidget("account.glade", 40 "account_align") 41 self.icon = self.xml.get_widget("icon") 42 self.capslock = self.xml.get_widget("capslock") 43 self.pwlabel = self.xml.get_widget("pwlabel") 44 self.pw = self.xml.get_widget("pw") 45 self.confirmlabel = self.xml.get_widget("confirmlabel") 46 self.confirm = self.xml.get_widget("confirm") 47 48 # load the icon 49 gui.readImageFromFile("root-password.png", image=self.icon) 50 51 # connect hotkeys 52 self.pwlabel.set_text_with_mnemonic(_("Root _Password:")) 53 self.pwlabel.set_mnemonic_widget(self.pw) 54 self.confirmlabel.set_text_with_mnemonic(_("_Confirm:")) 55 self.confirmlabel.set_mnemonic_widget(self.confirm) 56 57 # watch for Caps Lock so we can warn the user 58 self.intf.icw.window.connect("key-release-event", 59 lambda w, e: self.handleCapsLockRelease(w, e, self.capslock)) 60 61 # we might have a root password already 62 if not self.anaconda.users.rootPassword['isCrypted']: 63 self.pw.set_text(self.anaconda.users.rootPassword['password']) 64 self.confirm.set_text(self.anaconda.users.rootPassword['password']) 65 66 # pressing Enter in confirm == clicking Next 67 vbox = self.xml.get_widget("account_box") 68 self.confirm.connect("activate", lambda widget, 69 vbox=vbox: self.ics.setGrabNext(1)) 70 71 # set initial caps lock label text 72 self.setCapsLockLabel() 73 74 return self.align
75
76 - def focus(self):
77 self.pw.grab_focus()
78
79 - def passwordError(self):
80 self.pw.set_text("") 81 self.confirm.set_text("") 82 self.pw.grab_focus() 83 raise gui.StayOnScreen
84
85 - def handleCapsLockRelease(self, window, event, label):
86 if event.keyval == gtk.keysyms.Caps_Lock and \ 87 event.state & gtk.gdk.LOCK_MASK: 88 self.setCapsLockLabel()
89
90 - def setCapsLockLabel(self):
91 if _isys.isCapsLockEnabled(): 92 self.capslock.set_text("<b>" + _("Caps Lock is on.") + "</b>") 93 self.capslock.set_use_markup(True) 94 else: 95 self.capslock.set_text("")
96
97 - def getNext (self):
98 pw = self.pw.get_text() 99 confirm = self.confirm.get_text() 100 101 if not pw or not confirm: 102 self.intf.messageWindow(_("Error with Password"), 103 _("You must enter your root password " 104 "and confirm it by typing it a second " 105 "time to continue."), 106 custom_icon="error") 107 self.passwordError() 108 109 if pw != confirm: 110 self.intf.messageWindow(_("Error with Password"), 111 _("The passwords you entered were " 112 "different. Please try again."), 113 custom_icon="error") 114 self.passwordError() 115 116 if len(pw) < 6: 117 self.intf.messageWindow(_("Error with Password"), 118 _("The root password must be at least " 119 "six characters long."), 120 custom_icon="error") 121 self.passwordError() 122 123 try: 124 settings = pwquality.PWQSettings() 125 settings.read_config() 126 settings.check(pw, None, "root") 127 except pwquality.PWQError as (e, msg): 128 ret = self.intf.messageWindow(_("Weak Password"), 129 _("You have provided a weak password: %s") % msg, 130 type="custom", custom_icon="error", 131 default=0, 132 custom_buttons=[_("Cancel"), _("_Use Anyway")]) 133 if ret == 0: 134 self.passwordError() 135 136 legal = string.digits + string.ascii_letters + string.punctuation + " " 137 for letter in pw: 138 if letter not in legal: 139 self.intf.messageWindow(_("Error with Password"), 140 _("Requested password contains " 141 "non-ASCII characters, which are " 142 "not allowed."), 143 custom_icon="error") 144 self.passwordError() 145 146 self.anaconda.users.rootPassword["password"] = self.pw.get_text() 147 self.anaconda.users.rootPassword["isCrypted"] = False 148 149 return None
150