Merge commit 'public/master' into ceod
[public/pyceo-broken.git] / ceo / urwid / newmember.py
1 import ldap, urwid
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.userid = LdapFilterWordEdit(uwldap.uri(), uwldap.base(), 'uid',
55             {'cn':self.name, 'ou':self.program}, "UWuserid: ")
56         self.widgets = [
57             urwid.Text( "Member Information - Please Check ID" ),
58             urwid.Divider(),
59             self.userid,
60             self.name,
61             self.program,
62         ]
63     def check(self):
64         self.state['userid'] = self.userid.get_edit_text()
65         self.state['name'] = self.name.get_edit_text()
66         self.state['program'] = self.program.get_edit_text()
67
68         if len( self.state['userid'] ) < 3:
69             self.focus_widget( self.userid )
70             set_status("Username is too short")
71             return True
72         elif len( self.state['name'] ) < 4:
73             self.focus_widget( self.name )
74             set_status("Name is too short")
75             return True
76         clear_status()
77
78 class ClubInfoPage(WizardPanel):
79     def init_widgets(self):
80         self.userid = WordEdit("Username: ")
81         self.name = SingleEdit("Club Name: ")
82         self.widgets = [
83             urwid.Text( "Club Information" ),
84             urwid.Divider(),
85             self.userid,
86             self.name,
87         ]
88     def check(self):
89         self.state['userid'] = self.userid.get_edit_text()
90         self.state['name'] = self.name.get_edit_text()
91
92         if len( self.state['userid'] ) < 3:
93             self.focus_widget( self.userid )
94             set_status("Username is too short")
95             return True
96         elif len( self.state['name'] ) < 4:
97             self.focus_widget( self.name )
98             set_status("Name is too short")
99             return True
100         clear_status()
101
102 class SignPage(WizardPanel):
103     def init_widgets(self):
104         self.widgets = [
105             urwid.Text( "Machine Usage Policy" ),
106             urwid.Divider(),
107             urwid.Text( "Ensure the new member has signed the "
108                         "Machine Usage Policy. Accounts of users who have not "
109                         "signed will be suspended if discovered." ),
110         ]
111     def focusable(self):
112         return False
113
114 class PassPage(WizardPanel):
115     def init_widgets(self):
116         self.password = PassEdit("Password: ")
117         self.pwcheck = PassEdit("Re-enter: ")
118         self.widgets = [
119             urwid.Text( "Member Password" ),
120             urwid.Divider(),
121             self.password,
122             self.pwcheck,
123         ]
124     def focus_widget(self, widget):
125         self.box.set_focus( self.widgets.index( widget ) )
126     def clear_password(self):
127         self.focus_widget( self.password )
128         self.password.set_edit_text("")
129         self.pwcheck.set_edit_text("")
130     def check(self):
131         self.state['password'] = self.password.get_edit_text()
132         pwcheck = self.pwcheck.get_edit_text()
133
134         if self.state['password'] != pwcheck:
135             self.clear_password()
136             set_status("Passwords do not match")
137             return True
138         elif len(self.state['password']) < 5:
139             self.clear_password()
140             set_status("Password is too short")
141             return True
142         clear_status()
143
144 class EndPage(WizardPanel):
145     def __init__(self, state, utype='member'):
146         self.utype = utype
147         WizardPanel.__init__(self, state)
148     def init_widgets(self):
149         self.headtext = urwid.Text("")
150         self.midtext = urwid.Text("")
151         self.widgets = [
152             self.headtext,
153             urwid.Divider(),
154             self.midtext,
155         ]
156     def focusable(self):
157         return False
158     def check(self):
159         pop_window()
160     def activate(self):
161         problem = None
162         try:
163             if self.utype == 'member':
164                 members.create_member( self.state['userid'], self.state['password'], self.state['name'], self.state['program'] )
165                 members.register( self.state['userid'], terms.current() )
166             elif self.utype == 'clubuser':
167                 members.create_member( self.state['userid'], self.state['password'], self.state['name'], self.state['program'] )
168                 members.register_nonmember( self.state['userid'], terms.current() )
169             elif self.utype == 'club':
170                 members.create_club( self.state['userid'], self.state['name'] )
171             else:
172                 raise Exception("Internal Error")
173         except members.InvalidArgument, e:
174             problem = str(e)
175         except ldap.LDAPError, e:
176             problem = str(e)
177         except members.MemberException, e:
178             problem = str(e)
179
180         if problem:
181             self.headtext.set_text("Failures Occured Adding User")
182             self.midtext.set_text("The error was:\n\n%s\n\nThe account may be partially added "
183                 "and you may or may not be able to log in. Or perhaps you are not office staff. "
184                 "If this was not expected please contact systems committee." % problem)
185             return
186         else:
187             self.headtext.set_text("User Added")
188             self.midtext.set_text("Congratulations, %s has been added "
189                 "successfully. You should also rebuild the website in "
190                 "order to update the memberlist."
191                 % self.state['userid'])