-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
80 lines (67 loc) · 2.53 KB
/
main.py
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
from flask import Flask, request, redirect, render_template
import cgi
import os
import jinja2
app = Flask (__name__)
app.config['DEBUG'] = True
@app.route('/validate-login')
def display_login_form():
return render_template('login_form.html')
@app.route('/validate-login', methods=['POST'])
def validate_login():
username = request.form['username']
password = request.form['password']
verify_password = request.form['verify_password']
email = request.form['email']
username_error = ''
password_error = ''
verify_password_error = ''
email_error = ''
#username character check
if len(username) < 3:
username = ''
username_error = 'Username must be more than three characters.'
elif len(username) > 20:
username = ''
username_error = 'Username must be less than twenty characters.'
else:
username = username
#password character check
if 20 < len(password) < 3:
password = ''
password_error = 'Password must be betweeen three and twenty characters.'
#password match check
if password != verify_password:
password = ''
verify_password = ''
verify_password_error = 'Password do not match.'
#email validation
if len(email) > 0:
if not (email.endswith('@') or email.startswith('@') or email.endswith('.')
or email.startswith('.')) and email.count('@') == 1 and email.count('.') == 1:
email = email
else:
email = ''
email_error = 'Must be a valid email address.'
else:
email = ''
#empty fields
if username == '':
username_error = 'Username must be between three and twenty characters.'
if password == '':
password_error = 'Password must be between three and twenty characters.'
if verify_password == '':
verify_password_error = 'Passwords do not match.'
#if conditions are met, redirects to confirmation page
if not username_error and not password_error and not verify_password_error and not email_error:
return render_template('confirmation.html', username = username)
#if conditions are met, returns to signup-form
else:
return render_template('login_form.html', username_error=username_error,
password_error=password_error, verify_password_error=verify_password_error,
email_error=email_error,
username=username,
password=password,
verify_password=verify_password,
email=email)
app.run()