Remind users that club accounts are free.
[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 cup 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 ClubNoPayPage(WizardPanel):
35     def init_widgets(self):
36         self.widgets = [
37             urwid.Text( "Club representative accounts are free. Please ensure "
38                         "that no money was paid for this account." ),
39         ]
40     def focusable(self):
41         return False
42
43 class ClubUserIntroPage(WizardPanel):
44     def init_widgets(self):
45         self.widgets = [
46             urwid.Text( "Club Rep Account" ),
47             urwid.Divider(),
48             urwid.Text( "This is for people who need access to a club account, "
49                         "but are not currently interested in full CSC membership. "
50                         "Registering a user in this way grants one term of free "
51                         "access to our machines, without any other membership "
52                         "privileges (they can't vote, hold office, etc). If such "
53                         "a user later decides to join, use the Renew Membership "
54                         "option." ),
55         ]
56     def focusable(self):
57         return False
58
59 class InfoPage(WizardPanel):
60     def init_widgets(self):
61         self.name = SingleEdit("Full name: ")
62         self.program = SingleEdit("Program of Study: ")
63         self.email = SingleEdit("Email: ")
64         self.userid = LdapFilterWordEdit(uwldap.uri(), uwldap.base(), 'uid',
65             {'cn':self.name, 'ou':self.program}, "Username: ")
66         self.widgets = [
67             urwid.Text( "Member Information" ),
68             urwid.Divider(),
69             self.userid,
70             self.name,
71             self.program,
72             self.email,
73             urwid.Divider(),
74             urwid.Text("Notes:"),
75             urwid.Text("- Make sure to check ID (watcard, drivers license)"),
76             urwid.Text("- Make sure to use UW userids for current students\n  (we check uwldap to see if you are a full member)"),
77         ]
78     def check(self):
79         self.state['userid'] = self.userid.get_edit_text()
80         self.state['name'] = self.name.get_edit_text()
81         self.state['program'] = self.program.get_edit_text()
82         self.state['email'] = self.email.get_edit_text()
83         if len( self.state['userid'] ) < 3:
84             self.focus_widget( self.userid )
85             set_status("Username is too short")
86             return True
87         elif len( self.state['name'] ) < 4:
88             self.focus_widget( self.name )
89             set_status("Name is too short")
90             return True
91         elif self.state['userid'] == self.state['name']:
92             self.focus_widget(self.name)
93             set_status("Name matches username")
94             return True
95         clear_status()
96
97 class ClubInfoPage(WizardPanel):
98     def init_widgets(self):
99         self.userid = WordEdit("Username: ")
100         self.name = SingleEdit("Club Name: ")
101         self.widgets = [
102             urwid.Text( "Club Information" ),
103             urwid.Divider(),
104             self.userid,
105             self.name,
106         ]
107     def check(self):
108         self.state['userid'] = self.userid.get_edit_text()
109         self.state['name'] = self.name.get_edit_text()
110
111         if len( self.state['userid'] ) < 3:
112             self.focus_widget( self.userid )
113             set_status("Username is too short")
114             return True
115         elif len( self.state['name'] ) < 4:
116             self.focus_widget( self.name )
117             set_status("Name is too short")
118             return True
119         elif self.state['userid'] == self.state['name']:
120             self.focus_widget(self.name)
121             set_status("Name matches username")
122             return True
123         clear_status()
124
125 class NumberOfTermsPage(WizardPanel):
126     def init_widgets(self):
127         self.count = SingleIntEdit("Count: ")
128         self.widgets = [
129             urwid.Text("Number of Terms"),
130             urwid.Divider(),
131             urwid.Text("The member will be initially registered for this many "
132                        "consecutive terms.\n"),
133             self.count
134         ]
135     
136     def activate(self):
137         self.count.set_edit_text("1")
138         self.focus_widget(self.count)
139     
140     def check(self):
141         self.state['terms'] = terms.interval(terms.current(), self.count.value())
142         
143         if len(self.state['terms']) == 0:
144             self.focus_widget(self.count)
145             set_status("Registering for zero terms?")
146             return True
147         clear_status()
148
149 class SignPage(WizardPanel):
150     def init_widgets(self):
151         self.widgets = [
152             urwid.Text( "Machine Usage Policy" ),
153             urwid.Divider(),
154             urwid.Text( "Ensure the new member has signed the "
155                         "Machine Usage Policy. Accounts of users who have not "
156                         "signed will be suspended if discovered." ),
157         ]
158     def focusable(self):
159         return False
160
161 class PassPage(WizardPanel):
162     def init_widgets(self):
163         self.password = PassEdit("Password: ")
164         self.pwcheck = PassEdit("Re-enter: ")
165         self.widgets = [
166             urwid.Text( "Member Password" ),
167             urwid.Divider(),
168             self.password,
169             self.pwcheck,
170         ]
171     def focus_widget(self, widget):
172         self.box.set_focus( self.widgets.index( widget ) )
173     def clear_password(self):
174         self.focus_widget( self.password )
175         self.password.set_edit_text("")
176         self.pwcheck.set_edit_text("")
177     def check(self):
178         self.state['password'] = self.password.get_edit_text()
179         pwcheck = self.pwcheck.get_edit_text()
180
181         if self.state['password'] != pwcheck:
182             self.clear_password()
183             set_status("Passwords do not match")
184             return True
185         elif len(self.state['password']) < 5:
186             self.clear_password()
187             set_status("Password is too short")
188             return True
189         clear_status()
190
191 class EndPage(WizardPanel):
192     def __init__(self, state, utype='member'):
193         self.utype = utype
194         WizardPanel.__init__(self, state)
195     def init_widgets(self):
196         self.headtext = urwid.Text("")
197         self.midtext = urwid.Text("")
198         self.widgets = [
199             self.headtext,
200             urwid.Divider(),
201             self.midtext,
202         ]
203     def focusable(self):
204         return False
205     def check(self):
206         pop_window()
207     def activate(self):
208         self.headtext.set_text("Adding %s" % self.state['userid'])
209         self.midtext.set_text("Please be patient while the user is added. "
210                               "If more than a few seconds pass, check for a "
211                               "phase variance and try inverting the polarity.")
212         set_status("Contacting the gibson...")
213
214         redraw()
215
216         problem = None
217         try:
218             if self.utype == 'member':
219                 members.create_member(
220                         self.state['userid'],
221                         self.state['password'],
222                         self.state['name'],
223                         self.state['program'],
224                         self.state['email'])
225                 members.register(self.state['userid'], self.state['terms'])
226
227                 mailman_result = members.subscribe_to_mailing_list(self.state['userid'])
228                 if mailman_result.split(': ',1)[0] not in ('Subscribed', 'Already a member', 'Disabled'):
229                     problem = mailman_result
230
231             elif self.utype == 'clubuser':
232                 members.create_member(
233                         self.state['userid'],
234                         self.state['password'],
235                         self.state['name'],
236                         self.state['program'],
237                         self.state['email'],
238                         club_rep=True)
239                 members.register_nonmember(self.state['userid'], self.state['terms'])
240             elif self.utype == 'club':
241                 members.create_club(self.state['userid'], self.state['name'])
242             else:
243                 raise Exception("Internal Error")
244         except members.InvalidArgument, e:
245             problem = str(e)
246         except ldap.LDAPError, e:
247             problem = str(e)
248         except members.MemberException, e:
249             problem = str(e)
250         except remote.RemoteException, e:
251             problem = str(e)
252
253         clear_status()
254
255         if problem:
256             self.headtext.set_text("Failures Occured Adding User")
257             self.midtext.set_text("The error was:\n\n%s\n\nThe account may be partially added "
258                 "and you may or may not be able to log in. Or perhaps you are not office staff. "
259                 "If this was not expected please contact systems committee." % problem)
260             return
261         else:
262             set_status("Strombola Delivers")
263             self.headtext.set_text("User Added")
264             self.midtext.set_text("Congratulations, %s has been added "
265                 "successfully. You should also rebuild the website in "
266                 "order to update the memberlist."
267                 % self.state['userid'])