Add status thing
[public/pyceo-broken.git] / ceo / urwid / newmember.py
1 import ldap, urwid #, re
2 from ceo import members, terms, uwldap
3 from ceo.urwid.widgets import *
4 from ceo.urwid.window import *
5
6 class IntroPage(WizardPanel):
7     def init_widgets(self):
8         self.widgets = [
9             urwid.Text( "Joining the Computer Science Club" ),
10             urwid.Divider(),
11             urwid.Text( "CSC membership is $2.00 for one term. Please ensure "
12                         "the fee is deposited into the safe before continuing." ),
13         ]
14     def focusable(self):
15         return False
16
17 class ClubIntroPage(WizardPanel):
18     def init_widgets(self):
19         self.widgets = [
20             urwid.Text( "Club Accounts" ),
21             urwid.Divider(),
22             urwid.Text( "We provide other UW clubs accounts for email and "
23                         "web hosting, free of charge. Like members, clubs "
24                         "get web hosting at %s. We can also arrange for "
25                         "uwaterloo.ca subdomains; please instruct the club "
26                         "representative to contact the systems committee "
27                         "for more information. Club accounts do not have "
28                         "passwords, and exist primarily to own club data. "
29                         % "http://csclub.uwaterloo.ca/~clubid/" ),
30         ]
31     def focusable(self):
32         return False
33
34 class ClubUserIntroPage(WizardPanel):
35     def init_widgets(self):
36         self.widgets = [
37             urwid.Text( "Club Rep Account" ),
38             urwid.Divider(),
39             urwid.Text( "This is for people who need access to a club account, "
40                         "but are not currently interested in full CSC membership. "
41                         "Registering a user in this way grants one term of free "
42                         "access to our machines, without any other membership "
43                         "privileges (they can't vote, hold office, etc). If such "
44                         "a user later decides to join, use the Renew Membership "
45                         "option." ),
46         ]
47     def focusable(self):
48         return False
49
50 class InfoPage(WizardPanel):
51     def init_widgets(self):
52         self.name = SingleEdit("Full name: ")
53         self.program = SingleEdit("Program of Study: ")
54         self.email = SingleEdit("Email: ")
55         self.userid = LdapFilterWordEdit(uwldap.uri(), uwldap.base(), 'uid',
56             {'cn':self.name, 'ou':self.program}, "Username: ")
57         self.widgets = [
58             urwid.Text( "Member Information" ),
59             urwid.Divider(),
60             self.userid,
61             self.name,
62             self.program,
63             self.email,
64             urwid.Divider(),
65             urwid.Text("Notes:"),
66             urwid.Text("- Make sure to check ID (watcard, drivers license)"),
67             urwid.Text("- Make sure to use UW userids for current students\n  (we check uwldap to see if you are a full member)"),
68         ]
69     def check(self):
70         self.state['userid'] = self.userid.get_edit_text()
71         self.state['name'] = self.name.get_edit_text()
72         self.state['program'] = self.program.get_edit_text()
73         self.state['email'] = self.email.get_edit_text()
74         if len( self.state['userid'] ) < 3:
75             self.focus_widget( self.userid )
76             set_status("Username is too short")
77             return True
78         elif len( self.state['name'] ) < 4:
79             self.focus_widget( self.name )
80             set_status("Name is too short")
81             return True
82         elif self.state['userid'] == self.state['name']:
83             self.focus_widget(self.name)
84             set_status("Name matches username")
85             return True
86         clear_status()
87
88 class ClubInfoPage(WizardPanel):
89     def init_widgets(self):
90         self.userid = WordEdit("Username: ")
91         self.name = SingleEdit("Club Name: ")
92         self.widgets = [
93             urwid.Text( "Club Information" ),
94             urwid.Divider(),
95             self.userid,
96             self.name,
97         ]
98     def check(self):
99         self.state['userid'] = self.userid.get_edit_text()
100         self.state['name'] = self.name.get_edit_text()
101
102         if len( self.state['userid'] ) < 3:
103             self.focus_widget( self.userid )
104             set_status("Username is too short")
105             return True
106         elif len( self.state['name'] ) < 4:
107             self.focus_widget( self.name )
108             set_status("Name is too short")
109             return True
110         elif self.state['userid'] == self.state['name']:
111             self.focus_widget(self.name)
112             set_status("Name matches username")
113             return True
114         clear_status()
115
116 class SignPage(WizardPanel):
117     def init_widgets(self):
118         self.widgets = [
119             urwid.Text( "Machine Usage Policy" ),
120             urwid.Divider(),
121             urwid.Text( "Ensure the new member has signed the "
122                         "Machine Usage Policy. Accounts of users who have not "
123                         "signed will be suspended if discovered." ),
124         ]
125     def focusable(self):
126         return False
127
128 class PassPage(WizardPanel):
129     def init_widgets(self):
130         self.password = PassEdit("Password: ")
131         self.pwcheck = PassEdit("Re-enter: ")
132         self.widgets = [
133             urwid.Text( "Member Password" ),
134             urwid.Divider(),
135             self.password,
136             self.pwcheck,
137         ]
138     def focus_widget(self, widget):
139         self.box.set_focus( self.widgets.index( widget ) )
140     def clear_password(self):
141         self.focus_widget( self.password )
142         self.password.set_edit_text("")
143         self.pwcheck.set_edit_text("")
144     def check(self):
145         self.state['password'] = self.password.get_edit_text()
146         pwcheck = self.pwcheck.get_edit_text()
147
148         if self.state['password'] != pwcheck:
149             self.clear_password()
150             set_status("Passwords do not match")
151             return True
152         elif len(self.state['password']) < 5:
153             self.clear_password()
154             set_status("Password is too short")
155             return True
156         clear_status()
157
158 class EndPage(WizardPanel):
159     def __init__(self, state, utype='member'):
160         self.utype = utype
161         WizardPanel.__init__(self, state)
162     def init_widgets(self):
163         self.headtext = urwid.Text("")
164         self.midtext = urwid.Text("")
165         self.widgets = [
166             self.headtext,
167             urwid.Divider(),
168             self.midtext,
169         ]
170     def focusable(self):
171         return False
172     def check(self):
173         pop_window()
174     def activate(self):
175         set_status("Contacting the gibson...")
176         problem = None
177         try:
178             if self.utype == 'member':
179                 members.create_member( self.state['userid'], self.state['password'], self.state['name'], self.state['program'], self.state['email'] )
180                 members.register( self.state['userid'], terms.current() )
181             elif self.utype == 'clubuser':
182                 members.create_member( self.state['userid'], self.state['password'], self.state['name'], self.state['program'], self.state['email'] )
183                 members.register_nonmember( self.state['userid'], terms.current() )
184             elif self.utype == 'club':
185                 members.create_club( self.state['userid'], self.state['name'] )
186             else:
187                 raise Exception("Internal Error")
188         except members.InvalidArgument, e:
189             problem = str(e)
190         except ldap.LDAPError, e:
191             problem = str(e)
192         except members.MemberException, e:
193             problem = str(e)
194
195         if problem:
196             self.headtext.set_text("Failures Occured Adding User")
197             self.midtext.set_text("The error was:\n\n%s\n\nThe account may be partially added "
198                 "and you may or may not be able to log in. Or perhaps you are not office staff. "
199                 "If this was not expected please contact systems committee." % problem)
200             return
201         else:
202             self.headtext.set_text("User Added")
203             self.midtext.set_text("Congratulations, %s has been added "
204                 "successfully. You should also rebuild the website in "
205                 "order to update the memberlist."
206                 % self.state['userid'])