tell ceod when it is a club rep; club reps don't need the new member email
[public/pyceo-broken.git] / ceo / urwid / newmember.py
1 import ldap, urwid #, re
2 from ceo import members, terms, remote, 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 per 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 NumberOfTermsPage(WizardPanel):
117     def init_widgets(self):
118         self.count = SingleIntEdit("Count: ")
119         self.widgets = [
120             urwid.Text("Number of Terms"),
121             urwid.Divider(),
122             urwid.Text("The member will be initially registered for this many "
123                        "consecutive terms.\n"),
124             self.count
125         ]
126     
127     def activate(self):
128         self.count.set_edit_text("1")
129         self.focus_widget(self.count)
130     
131     def check(self):
132         self.state['terms'] = terms.interval(terms.current(), self.count.value())
133         
134         if len(self.state['terms']) == 0:
135             self.focus_widget(self.count)
136             set_status("Registering for zero terms?")
137             return True
138         clear_status()
139
140 class SignPage(WizardPanel):
141     def init_widgets(self):
142         self.widgets = [
143             urwid.Text( "Machine Usage Policy" ),
144             urwid.Divider(),
145             urwid.Text( "Ensure the new member has signed the "
146                         "Machine Usage Policy. Accounts of users who have not "
147                         "signed will be suspended if discovered." ),
148         ]
149     def focusable(self):
150         return False
151
152 class PassPage(WizardPanel):
153     def init_widgets(self):
154         self.password = PassEdit("Password: ")
155         self.pwcheck = PassEdit("Re-enter: ")
156         self.widgets = [
157             urwid.Text( "Member Password" ),
158             urwid.Divider(),
159             self.password,
160             self.pwcheck,
161         ]
162     def focus_widget(self, widget):
163         self.box.set_focus( self.widgets.index( widget ) )
164     def clear_password(self):
165         self.focus_widget( self.password )
166         self.password.set_edit_text("")
167         self.pwcheck.set_edit_text("")
168     def check(self):
169         self.state['password'] = self.password.get_edit_text()
170         pwcheck = self.pwcheck.get_edit_text()
171
172         if self.state['password'] != pwcheck:
173             self.clear_password()
174             set_status("Passwords do not match")
175             return True
176         elif len(self.state['password']) < 5:
177             self.clear_password()
178             set_status("Password is too short")
179             return True
180         clear_status()
181
182 class EndPage(WizardPanel):
183     def __init__(self, state, utype='member'):
184         self.utype = utype
185         WizardPanel.__init__(self, state)
186     def init_widgets(self):
187         self.headtext = urwid.Text("")
188         self.midtext = urwid.Text("")
189         self.widgets = [
190             self.headtext,
191             urwid.Divider(),
192             self.midtext,
193         ]
194     def focusable(self):
195         return False
196     def check(self):
197         pop_window()
198     def activate(self):
199         self.headtext.set_text("Adding %s" % self.state['userid'])
200         self.midtext.set_text("Please be patient while the user is added. "
201                               "If more than a few seconds pass, check for a "
202                               "phase variance and try inverting the polarity.")
203         set_status("Contacting the gibson...")
204
205         redraw()
206
207         problem = None
208         try:
209             if self.utype == 'member':
210                 members.create_member(
211                         self.state['userid'],
212                         self.state['password'],
213                         self.state['name'],
214                         self.state['program'],
215                         self.state['email'])
216                 members.register(self.state['userid'], self.state['terms'])
217
218                 mailman_result = members.subscribe_to_mailing_list(self.state['userid'])
219                 if mailman_result.split(': ',1)[0] not in ('Subscribed', 'Already a member'):
220                     problem = mailman_result
221
222             elif self.utype == 'clubuser':
223                 members.create_member(
224                         self.state['userid'],
225                         self.state['password'],
226                         self.state['name'],
227                         self.state['program'],
228                         self.state['email'],
229                         club_rep=True)
230                 members.register_nonmember(self.state['userid'], self.state['terms'])
231             elif self.utype == 'club':
232                 members.create_club(self.state['userid'], self.state['name'])
233             else:
234                 raise Exception("Internal Error")
235         except members.InvalidArgument, e:
236             problem = str(e)
237         except ldap.LDAPError, e:
238             problem = str(e)
239         except members.MemberException, e:
240             problem = str(e)
241         except remote.RemoteException, e:
242             problem = str(e)
243
244         clear_status()
245
246         if problem:
247             self.headtext.set_text("Failures Occured Adding User")
248             self.midtext.set_text("The error was:\n\n%s\n\nThe account may be partially added "
249                 "and you may or may not be able to log in. Or perhaps you are not office staff. "
250                 "If this was not expected please contact systems committee." % problem)
251             return
252         else:
253             set_status("Strombola Delivers")
254             self.headtext.set_text("User Added")
255             self.midtext.set_text("Congratulations, %s has been added "
256                 "successfully. You should also rebuild the website in "
257                 "order to update the memberlist."
258                 % self.state['userid'])