|
10 | 10 |
|
11 | 11 | PASSWORD_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+?'
|
12 | 12 | NEW_PASSWORD_LENGTH = 13;
|
| 13 | +ISSUE_MAP = {'hw':'Homework', 'proj': 'Project', 'test': 'Test'} |
| 14 | + |
13 | 15 |
|
14 | 16 | @lm.user_loader
|
15 | 17 | def load_user(id):
|
@@ -55,7 +57,7 @@ def login():
|
55 | 57 |
|
56 | 58 | user = User.query.filter_by(email = email).first()
|
57 | 59 | if user is None:
|
58 |
| - flash('The email "{0}" is not stored in our databases.'.format(email)) |
| 60 | + flash('The email "{0}" is not stored in our database.'.format(email)) |
59 | 61 | return redirect(url_for('login'))
|
60 | 62 |
|
61 | 63 | if not user.verify_password(password):
|
@@ -174,12 +176,47 @@ def learn():
|
174 | 176 | if request.method=='POST': #Looking at the page
|
175 | 177 | info = request.form
|
176 | 178 |
|
| 179 | + ''' |
| 180 | + Server-side validation, in case bad data slips through |
| 181 | + Possible Errors: |
| 182 | + Invalid class selected |
| 183 | + 'Other' issue selected but nothing filled in |
| 184 | + Nothing in the 'title' section |
| 185 | + Nothing in the 'specific challenge' section |
| 186 | + ''' |
177 | 187 | subj = Subject.query.filter_by(title=info['subj_title']).first()
|
178 |
| - if subj != None: |
| 188 | + if subj == None: |
| 189 | + flash("Invalid subject selected. Please leave page source alone."); |
| 190 | + return redirect(url_for('learn')) |
| 191 | + else: |
179 | 192 | now = datetime.utcnow()
|
180 |
| - req = Request(title=info['title'], |
181 |
| - issue=info['issue'], |
182 |
| - body=info['challenge'], |
| 193 | + issue=info['issue'] |
| 194 | + title=info['title'] |
| 195 | + body=info['challenge'] |
| 196 | + |
| 197 | + if issue == 'other': |
| 198 | + elaboration=info['elaboration'] |
| 199 | + if elaboration == "" or elaboration == None: |
| 200 | + flash("Somehow, a blank issue type elaboration bypassed client-side validation :( Please leave page source and JS alone."); |
| 201 | + return redirect(url_for('learn')) |
| 202 | + issue_str = elaboration |
| 203 | + elif issue not in ISSUE_MAP: |
| 204 | + flash("Somehow, an invalid issue type bypassed client-side validation :( Please leave page source and JS alone."); |
| 205 | + return redirect(url_for('learn')) |
| 206 | + else: |
| 207 | + issue_str = ISSUE_MAP[issue] |
| 208 | + |
| 209 | + |
| 210 | + if title == "" or title == None: #Remember, different browsers handle blank strings differently |
| 211 | + flash("Somehow, an empty title bypassed client-side validation :( Please leave page source and JS alone."); |
| 212 | + return redirect(url_for('learn')) |
| 213 | + if body == "" or body == None: |
| 214 | + flash("Somehow, a blank body bypassed client-side validation :( Please leave page source and JS alone."); |
| 215 | + return redirect(url_for('learn')) |
| 216 | + |
| 217 | + req = Request(title=title, |
| 218 | + issue=issue_str, |
| 219 | + body=body, |
183 | 220 | extra_requests=info['requests'],
|
184 | 221 | availability=info['availability'],
|
185 | 222 | additional=info['additional_comments'],
|
@@ -216,6 +253,21 @@ def admin():
|
216 | 253 | requests=Request.query.all(),
|
217 | 254 | subjects=Subject.query.all())
|
218 | 255 |
|
| 256 | +@app.route('/manage_users', methods=['GET', 'POST']) |
| 257 | +@login_required |
| 258 | +def manage_users(): |
| 259 | + if request.method == 'POST': |
| 260 | + pass |
| 261 | + else: |
| 262 | + if g.user.role < 2: |
| 263 | + flash("You don't have the proper clearance to see this webpage.") |
| 264 | + return render_template('me.html', |
| 265 | + title="Me") |
| 266 | + return render_template('manage_users.html', |
| 267 | + users = User.query.all(), |
| 268 | + title="Manage Users") |
| 269 | + |
| 270 | + |
219 | 271 | @app.route('/termsconditions')
|
220 | 272 | def terms_and_conditions():
|
221 | 273 | return render_template('termsconditions.html',
|
|
0 commit comments