feat: Add error page
All checks were successful
Build Docker / Build Main Image (push) Successful in 22s
Build Docker / Build SLDs Image (push) Successful in 27s

This commit is contained in:
Nathan Woodburn 2023-11-17 23:36:09 +11:00
parent 25e546d7c5
commit cb6dda7fca
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
3 changed files with 76 additions and 16 deletions

View File

@ -33,8 +33,12 @@ def generate_cookie():
# Create a new user # Create a new user
def create_user(email, domain, password): def create_user(email, domain, password):
if len(email) < 4 or len(domain) < 4 or len(password) < 4: if len(email) < 4:
return {'success': False, 'message': 'Invalid email, domain, or password'} return {'success': False, 'message': 'Unfortunatly your email is not valid'}
if len(domain) < 4:
return {'success': False, 'message': 'We only allow domains with 4 or more characters'}
if len(password) < 4:
return {'success': False, 'message': 'Your password is not complex enough'}
# Hash password # Hash password
@ -52,13 +56,13 @@ def create_user(email, domain, password):
# Check if user exists # Check if user exists
if db.search_users(email) != []: if db.search_users(email) != []:
return {'success': False, 'message': 'User already exists'} return {'success': False, 'message': 'It looks like someone already is using that email address'}
if db.search_users_domain(domain) != []: if db.search_users_domain(domain) != []:
return {'success': False, 'message': 'Domain already exists'} return {'success': False, 'message': 'Someone has already claimed that domain'}
db.add_user(email, domain, hashed_password, token) db.add_user(email, domain, hashed_password, token)
return {'success': True, 'message': 'User created', 'token': token} return {'success': True, 'message': 'Congrats on creating an account', 'token': token}
def validate_token(token): def validate_token(token):
search = db.search_users_token(token) search = db.search_users_token(token)
@ -83,11 +87,11 @@ def login(email,password):
# Verify email # Verify email
search = db.search_users(email) search = db.search_users(email)
if search == []: if search == []:
return {'success': False, 'message': 'Invalid email'} return {'success': False, 'message': 'Sorry, we couldn\'t find your account<br>Check your email and password'}
user = convert_db_users(search[0]) user = convert_db_users(search[0])
# Verify password # Verify password
if not verify_password(password, user['password']): if not verify_password(password, user['password']):
return {'success': False, 'message': 'Invalid password'} return {'success': False, 'message': 'Sorry, we couldn\'t find your account<br>Check your email and password'}
# Create a cookie # Create a cookie
token = generate_cookie() token = generate_cookie()

16
main.py
View File

@ -35,7 +35,7 @@ def assets(path):
def error(message): def error(message):
return jsonify({'success': False, 'message': message}), 400 return render_template('error.html', message=message)
@app.route('/') @app.route('/')
def index(): def index():
@ -67,10 +67,8 @@ def signup():
password = request.form['password'] password = request.form['password']
# Verify domain # Verify domain
if domain.startswith('_') or domain.endswith('_'):
return error('Invalid domain')
if not re.match("^[a-z0-9]*$", domain): if not re.match("^[a-z0-9]*$", domain):
return error('Invalid domain') return error('Sorry domain can only contain lowercase letters and numbers')
try: try:
valid = validate_email(email) valid = validate_email(email)
@ -106,7 +104,7 @@ def edit():
token = request.cookies['token'] token = request.cookies['token']
if not accounts.validate_token(token): if not accounts.validate_token(token):
return error('Invalid token') return error('Sorry we had an issue verifying your account')
# Verify token # Verify token
user = accounts.validate_token(token) user = accounts.validate_token(token)
if not user: if not user:
@ -163,7 +161,7 @@ def edit():
def send_edit(): def send_edit():
token = request.cookies['token'] token = request.cookies['token']
if not accounts.validate_token(token): if not accounts.validate_token(token):
return error('Invalid token') return error('Sorry we had an issue verifying your account')
# Verify token # Verify token
user = accounts.validate_token(token) user = accounts.validate_token(token)
if not user: if not user:
@ -199,7 +197,7 @@ def send_edit():
def logout(): def logout():
token = request.cookies['token'] token = request.cookies['token']
if not accounts.logout(token)['success']: if not accounts.logout(token)['success']:
return error('Invalid token') return error('Sorry we had an issue verifying your account')
# Remove cookie # Remove cookie
resp = make_response(redirect('/')) resp = make_response(redirect('/'))
@ -216,7 +214,7 @@ def claim():
def hnschat(): def hnschat():
token = request.cookies['token'] token = request.cookies['token']
if not accounts.validate_token(token): if not accounts.validate_token(token):
return error('Invalid token') return error('Sorry we had an issue verifying your account')
# Verify token # Verify token
user = accounts.validate_token(token) user = accounts.validate_token(token)
if not user: if not user:
@ -231,7 +229,7 @@ def hnschat():
def save_hnschat(): def save_hnschat():
token = request.cookies['token'] token = request.cookies['token']
if not accounts.validate_token(token): if not accounts.validate_token(token):
return error('Invalid token') return error('Sorry we had an issue verifying your account')
# Verify token # Verify token
user = accounts.validate_token(token) user = accounts.validate_token(token)
if not user: if not user:

58
templates/error.html Normal file
View File

@ -0,0 +1,58 @@
<!DOCTYPE html>
<html data-bs-theme="light" lang="en" style="background: #000000;">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>ShakeCities</title>
<meta name="twitter:description" content="Unlock web ownership's future with ShakeCities! Create your free, secure Handshake domain site. Integrate crypto payments, explore HNSChat, and join us in shaping the decentralized web!">
<meta name="description" content="Unlock web ownership's future with ShakeCities! Create your free, secure Handshake domain site. Integrate crypto payments, explore HNSChat, and join us in shaping the decentralized web!">
<meta name="twitter:card" content="summary">
<meta property="og:type" content="website">
<meta property="og:image" content="https://shakecities.com/assets/img/alexander-slattery-LI748t0BK8w-unsplash.webp">
<meta property="og:title" content="ShakeCities">
<meta name="twitter:title" content="ShakeCities">
<meta name="twitter:image" content="https://shakecities.com/assets/img/alexander-slattery-LI748t0BK8w-unsplash.webp">
<meta property="og:description" content="Unlock web ownership's future with ShakeCities! Create your free, secure Handshake domain site. Integrate crypto payments, explore HNSChat, and join us in shaping the decentralized web!">
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png">
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNSW.png" media="(prefers-color-scheme: dark)">
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png">
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNSW.png" media="(prefers-color-scheme: dark)">
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png">
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png">
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png">
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/styles.min.css">
</head>
<body style="background: #000000;width: 95%;margin: auto;">
<section>
<section style="height: 15vh;background: url(&quot;assets/img/alexander-slattery-LI748t0BK8w-unsplash.webp&quot;) bottom / cover no-repeat;min-height: 130px;"></section>
<section class="d-print-none d-lg-none d-xl-none d-xxl-none" style="width: 30vw;border-radius: 50%;background: #000000;padding: 20px;height: 30vw;margin: auto;margin-top: -15vw;display: flex;"><a href="/"><img class="img-fluid" src="assets/img/HNSW.png" width="100%"></a></section>
<section class="d-print-none d-lg-none d-xl-none d-xxl-none" style="display: block;width: 100%;text-align: center;margin-top: 10px;">
<div style="display: inline-block;margin: auto;"><a class="btn btn-primary" role="button" style="margin: 10px;" href="/signup">Create your page</a><a class="btn btn-primary" role="button" style="margin: 10px;" href="/{{account_link}}">{{account_link_name}}</a></div>
</section>
<section class="d-none d-print-block d-lg-block d-xl-block d-xxl-block" style="display: block;">
<div style="width: 100%;text-align: right;margin-top: -4em;"></div>
</section>
<section class="d-none d-print-block d-lg-block d-xl-block d-xxl-block" style="width: 15vw;border-radius: 50%;background: #000000;padding: 20px;height: 15vw;margin: auto;display: flex;margin-top: -6vw;"><a href="/"><img class="img-fluid" src="assets/img/HNSW.png" width="100%"></a></section>
<section class="d-none d-print-block d-lg-block d-xl-block d-xxl-block" style="height: 3em;"></section>
</section>
<section style="width: 50%;margin: auto;margin-top: 50px;">
<div class="card bg-dark" style="padding-bottom: 40px;">
<div class="card-body">
<h4 class="card-title" style="color: rgb(255,255,255);">Sorry we ran into an error</h4>
<p style="color: rgb(255,255,255);text-align: center;">{{message | safe}}</p>
</div><a class="btn btn-primary" role="button" style="margin: 10px;" href="javascript:history.back()">Back</a>
</div>
</section>
<section style="margin: 20px;height: 40px;text-align: center;margin-top: 40px;">
<div>
<p style="color: #ffffff;">Copyright © ShakeCities 2023</p>
</div>
</section>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/script.min.js"></script>
</body>
</html>