-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
71 lines (65 loc) · 2.55 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
from flask import Flask, request, redirect, render_template
app = Flask(__name__)
app.config['DEBUG'] = True #Display runtime errors
#User signup home page
@app.route('/')
def index():
return render_template('index.html')
@app.route('/', methods=['POST'])
def signup():
username = request.form["user-name"]
password = request.form["user-password"]
verify = request.form["verify-password"]
email = request.form["user-email"]
#Empty string for error messages
username_error =''
password_error=''
verify_error=''
email_error=''
#Username
if username == "":
username_error = "Please fill out username box."
elif len(username) <= 3 or len(username) > 20:
username_error = "Your username can not have less 3 characters or more than 20 characters."
elif " " in username:
username_error = "Your username cannot contain any spaces."
#Password
if password == "":
password_error = "Enter a password."
elif len(password) < 3 or len(password) > 20:
password_error = "Password must be between 3 and 20 characters long."
elif " " in password:
password_error = "Your password cannot contain any spaces."
#Verify/Compare Password
if verify == "" or verify != password:
verify_error = "Passwords do not match. Please try again."
#Verify Email
if not email == "":
email_error = "Please enter a email."
if len(email) < 3 or len(email) > 20:
email_error = "Email must be between 3 and 20 characters long."
elif " " in email:
email_error = "Your email cannot contain any spaces."
elif "@" not in email:
email_error = "Please input a valid email containing a @"
elif "." not in email:
email_error = "Please input a valid email containing a . period"
#If no errors then redirect
if not username_error and not password_error and not verify_error and not email_error:
return redirect('/welcome_page?username={0}'.format(username))
#If it has errors then it displays them on same page
else:
return render_template('index.html',
username = username,
username_error = username_error,
password_error = password_error,
verify_error = verify_error,
email = email,
email_error = email_error
)
#Redirect to welcome page
@app.route("/welcome_page")
def welcome():
username = request.args.get('username')
return render_template('welcome.html', username=username)
app.run()