-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_registrations
131 lines (109 loc) · 4.98 KB
/
process_registrations
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python3
import cgi
import cgitb
import os.path
import process_form
import reg_scrub
import register
from member import Member
from reg_request_db import RegDb
debugdir = '/tmp'
cgitb.enable(display=0, logdir=debugdir)
the_form = cgi.FieldStorage()
print('''Content-type: text/html
{}'''.format(process_form.header))
try:
reg_db = RegDb(register.database)
except RuntimeError as re:
print('''<div align="center">
<h1>Internal Error</h1>
<p>The registration system is currently unavailable. Please try back later.</p>
<p><strong>Exception:</strong></br>
{the_error}
</p>
</div>
'''.format(the_error = re)
)
else:
if "act" not in the_form:
candidates = []
for candidate in reg_db.candidates():
candidates.append(process_form.candidate_template.format(
*candidate.string_values('print'),
reqid=candidate.get_reqid()))
if candidates:
print(process_form.start_form)
print('\n'.join(candidates))
print(process_form.end_form)
else:
print('<div align="center"><p><strong>No pending registration requests.</strong></p></div>')
else:
cleaned_form = reg_scrub.cleanse_and_validate(the_form)
deletions = list(var for var in cleaned_form if 'del_' in var)
modifications = list(var for var in cleaned_form if 'mod_' in var)
registrations = list(var for var in cleaned_form if 'reg_' in var)
if not (deletions or modifications or registrations):
print('<div align="center"><p><strong>No action specified, or input malformed.</strong></p></div>')
else:
if deletions:
for deletion in deletions:
reqid = (deletion.split('_'))[-1]
try:
reg_db.delete(reqid)
except RuntimeError as rte:
print("<strong>Unable to cancel request {}: {}</strong></br>".format(
reqid, rte))
else:
print("<strong>Request {} canceled.</strong></br>".format(reqid))
print("<hr>")
for mod in modifications:
reqid = (mod.split('_'))[-1]
fields = Member.ordered_field_names()
request_changed = False
for field in fields:
try:
val = cleaned_form[field+'_'+reqid]
except KeyError:
if field not in Member.optional_field_names():
print('<strong>Invalid value for field "{}"</strong></br>'.format(field))
else:
try:
altered = reg_db.modify(reqid, field, val)
except RuntimeError as rte:
print("<strong>Unable to modify request id {}: {}</strong></br>".format(
reqid, rte))
else:
if altered:
request_changed = True
print("<strong>Modified request id {}, field {}. Now: {}</strong></br>".format(
reqid, field, val))
if not request_changed:
print("<strong>No changes made to request {}.</strong></br>".format(
reqid))
print("<hr>")
for reg in registrations:
reqid = (reg.split('_'))[-1]
try:
new_member = reg_db.candidate(reqid)
except RuntimeError as rte:
print("<strong>Unable to fetch request {}: {}</strong></br>".format(
reqid, str(rte)))
else:
try:
register.add_to_member_db(new_member)
except RuntimeError as rte:
print("<strong>Unable to add member in request id {} to database: {}</strong></br>".format(
reqid, str(rte)))
else:
print("<strong>Request id {}: {} added to member db.</strong></br>".format(
reqid, new_member.name()))
if new_member.wants_shell():
try:
register.queue_for_shell(new_member)
except RuntimeError as rte:
print("<strong>Unable to add member in request id {} to shell queue.</strong></br>".format(reqid))
else:
print("<strong>Request id {}: {} added to shell request queue.</strong></br>".format(reqid, new_member['username']))
else:
print("<strong>Request id {}: No shell/email access requested.</strong></br>".format(reqid))
print(process_form.footer.format(os.path.basename(__file__)))