-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
48 lines (40 loc) · 2.29 KB
/
main.py
File metadata and controls
48 lines (40 loc) · 2.29 KB
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
from flask import Flask, request, redirect, render_template
app = Flask(__name__)
app.config['DEBUG'] = True
@app.route('/signup')
def index():
return render_template('user_signup.html',title='User Signup', username_error='',password_error='',confirm_error='',email_error='', username='', email='')
@app.route('/signup', methods=['POST'])
def signup():
name = request.form['username']
password = request.form['password']
confirm = request.form['confirm']
email = request.form['email']
username_error = ''
password_error = ''
confirm_error = ''
email_error = ''
if len(name) > 20 or " " in name:
username_error = 'Username cannot contain a space or exceed 20 characters.'
return render_template('user_signup.html',title='User Signup',username_error=username_error,password_error='',confirm_error='',email_error='',username=name,)
elif len(password) > 20 or " " in password:
password_error = 'Password cannot contain a space or exceed 20 characters.'
return render_template('user_signup.html',title='User Signup', username_error='',password_error=password_error,confirm_error='',email_error='')
elif password != confirm:
confirm_error= 'Passwords do not match.'
return render_template('user_signup.html',title='User Signup', username_error='',password_error='',confirm_error=confirm_error,email_error='',email=email,username=name)
elif email == '':
return redirect('/welcome?username={0}'.format(name))
elif "@" not in email and "." not in email:
email_error = "Enter a valid email address."
return render_template('user_signup.html',title='User Signup', username_error='',password_error='',confirm_error='',email_error=email_error,username=name,email=email)
elif len(email) > 20 or " " in email:
email_error = 'Email address cannot contain a space or exceed 20 characters.'
return render_template('user_signup.html',title='User Signup', username_error='',password_error='',confirm_error='',email_error=email_error,username=name,email=email)
else:
return redirect('/welcome?username={0}'.format(name))
@app.route('/welcome')
def welcome():
name = request.args.get('username')
return render_template('welcome.html',name=name)
app.run()