Add create club account menu item
authorMichael Spang <mspang@uwaterloo.ca>
Fri, 5 Oct 2007 06:22:01 +0000 (02:22 -0400)
committerMichael Spang <mspang@uwaterloo.ca>
Fri, 5 Oct 2007 06:22:01 +0000 (02:22 -0400)
This option should probably only be used by
systems-committee, there are several steps
that need to be formed after the accout is
created.

pylib/csc/apps/urwid/main.py
pylib/csc/apps/urwid/newmember.py

index a05f9f6..fef149c 100644 (file)
@@ -54,6 +54,7 @@ def main_menu():
     menu = [
         ("New Member", new_member),
         ("Renew Membership", renew_member),
     menu = [
         ("New Member", new_member),
         ("Renew Membership", renew_member),
+        ("Create Club Account", new_club),
         ("Display Member", display_member),
         ("Search", search_members),
         ("Exit", raise_abort),
         ("Display Member", display_member),
         ("Search", search_members),
         ("Exit", raise_abort),
@@ -66,7 +67,9 @@ def push_wizard(name, pages, dimensions=(50, 10)):
     state = {}
     wiz = Wizard()
     for page in pages:
     state = {}
     wiz = Wizard()
     for page in pages:
-        wiz.add_panel( page(state) )
+        if type(page) != tuple:
+            page = (page, )
+        wiz.add_panel( page[0](state, *page[1:]) )
     push_window( urwid.Filler( urwid.Padding(
         urwid.LineBox(wiz), 'center', dimensions[0]),
         'middle', dimensions[1] ), name )
     push_window( urwid.Filler( urwid.Padding(
         urwid.LineBox(wiz), 'center', dimensions[0]),
         'middle', dimensions[1] ), name )
@@ -80,6 +83,13 @@ def new_member(*args, **kwargs):
         newmember.EndPage,
     ])
 
         newmember.EndPage,
     ])
 
+def new_club(*args, **kwargs):
+    push_wizard("New Club Account", [
+        newmember.ClubIntroPage,
+        newmember.ClubInfoPage,
+        (newmember.EndPage, "club"),
+    ], (60,15))
+
 def renew_member(*args, **kwargs):
     push_wizard("Renew Membership", [
         renew.IntroPage,
 def renew_member(*args, **kwargs):
     push_wizard("Renew Membership", [
         renew.IntroPage,
index 994de80..8e11e11 100644 (file)
@@ -16,6 +16,26 @@ class IntroPage(WizardPanel):
     def focusable(self):
         return False
 
     def focusable(self):
         return False
 
+class ClubIntroPage(WizardPanel):
+    def init_widgets(self):
+        self.widgets = [
+            urwid.Text( "Club Services" ),
+            urwid.Divider(),
+            urwid.Text( "We provide other UW clubs accounts for email and "
+                        "web hosting, free of charge. Like members, clubs "
+                        "get web hosting at %s. We can also arrange for "
+                        "uwaterloo.ca subdomains; please instruct the club "
+                        "representative to contact the systems committee "
+                        "for more information."
+                        "\n\nNote: This is not complete. Authorizing members "
+                        "to access the club account still requires manual "
+                        "intervention."
+                        % "http://csclub.uwaterloo.ca/~clubid/"
+            )
+        ]
+    def focusable(self):
+        return False
+
 class InfoPage(WizardPanel):
     def init_widgets(self):
         self.userid = WordEdit("UWdir ID: ")
 class InfoPage(WizardPanel):
     def init_widgets(self):
         self.userid = WordEdit("UWdir ID: ")
@@ -43,6 +63,30 @@ class InfoPage(WizardPanel):
             return True
         clear_status()
 
             return True
         clear_status()
 
+class ClubInfoPage(WizardPanel):
+    def init_widgets(self):
+        self.userid = WordEdit("Username: ")
+        self.name = SingleEdit("Club Name: ")
+        self.widgets = [
+            urwid.Text( "Club Information" ),
+            urwid.Divider(),
+            self.userid,
+            self.name,
+        ]
+    def check(self):
+        self.state['userid'] = self.userid.get_edit_text()
+        self.state['name'] = self.name.get_edit_text()
+
+        if len( self.state['userid'] ) < 3:
+            self.focus_widget( self.userid )
+            set_status("Username is too short")
+            return True
+        elif len( self.state['name'] ) < 4:
+            self.focus_widget( self.name )
+            set_status("Name is too short")
+            return True
+        clear_status()
+
 class SignPage(WizardPanel):
     def init_widgets(self):
         self.widgets = [
 class SignPage(WizardPanel):
     def init_widgets(self):
         self.widgets = [
@@ -86,6 +130,9 @@ class PassPage(WizardPanel):
         clear_status()
 
 class EndPage(WizardPanel):
         clear_status()
 
 class EndPage(WizardPanel):
+    def __init__(self, state, utype='member'):
+        self.type = utype
+        WizardPanel.__init__(self, state)
     def init_widgets(self):
         self.headtext = urwid.Text("")
         self.midtext = urwid.Text("")
     def init_widgets(self):
         self.headtext = urwid.Text("")
         self.midtext = urwid.Text("")
@@ -99,21 +146,27 @@ class EndPage(WizardPanel):
     def check(self):
         pop_window()
     def activate(self):
     def check(self):
         pop_window()
     def activate(self):
-        try:
-            if not members.connected(): members.connect()
-            members.new( self.state['userid'], self.state['name'], self.state['program'] )
-            problem = None
-        except members.InvalidRealName:
-            problem = "Invalid real name"
-        except InvalidArgument, e:
-            if e.argname == 'uid' and e.explanation == 'duplicate uid':
-                problem = 'Duplicate userid'
-            else:
-                raise
+        problem = None
+        if self.type == 'member':
+            try:
+                if not members.connected(): members.connect()
+                members.new( self.state['userid'], self.state['name'], self.state['program'] )
+            except members.InvalidRealName:
+                problem = "Invalid real name"
+            except InvalidArgument, e:
+                if e.argname == 'uid' and e.explanation == 'duplicate uid':
+                    problem = 'Duplicate userid'
+                else:
+                    raise
         if not problem:
             try:
                 if not accounts.connected(): accounts.connect()
         if not problem:
             try:
                 if not accounts.connected(): accounts.connect()
-                accounts.create_member( self.state['userid'], self.state['password'], self.state['name'] )
+                if self.type == 'member':
+                    accounts.create_member( self.state['userid'], self.state['password'], self.state['name'] )
+                elif self.type == 'club':
+                    accounts.create_club( self.state['userid'], self.state['name'] )
+                else:
+                    raise Exception("Internal Error")
             except accounts.NameConflict, e:
                 problem = str(e)
             except accounts.NoAvailableIDs, e:
             except accounts.NameConflict, e:
                 problem = str(e)
             except accounts.NoAvailableIDs, e:
@@ -125,10 +178,10 @@ class EndPage(WizardPanel):
             except accounts.KrbException, e:
                 problem = str(e)
         if problem:
             except accounts.KrbException, e:
                 problem = str(e)
         if problem:
-            self.headtext.set_text("Failed to add member")
+            self.headtext.set_text("Failed to add user")
             self.midtext.set_text("The error was: '%s'" % problem)
         else:
             self.midtext.set_text("The error was: '%s'" % problem)
         else:
-            self.headtext.set_text("Member Added")
+            self.headtext.set_text("User Added")
             self.midtext.set_text("Congratulations, %s has been added "
                 "successfully. Please run 'addhomedir %s'."
                 % (self.state['userid'], self.state['userid']))
             self.midtext.set_text("Congratulations, %s has been added "
                 "successfully. Please run 'addhomedir %s'."
                 % (self.state['userid'], self.state['userid']))