feat: Add accounts pages
This commit is contained in:
parent
da417c4b63
commit
b02d8934c2
19
accounts.py
19
accounts.py
@ -74,4 +74,21 @@ def logout(token):
|
||||
db.update_tokens(user['id'], user['tokens'])
|
||||
|
||||
|
||||
return {'success': True, 'message': 'Logged out'}
|
||||
return {'success': True, 'message': 'Logged out'}
|
||||
|
||||
def login(email,password):
|
||||
# Verify email
|
||||
search = db.search_users(email)
|
||||
if search == []:
|
||||
return {'success': False, 'message': 'Invalid email'}
|
||||
user = convert_db_users(search[0])
|
||||
# Verify password
|
||||
if not verify_password(password, user['password']):
|
||||
return {'success': False, 'message': 'Invalid password'}
|
||||
|
||||
# Create a cookie
|
||||
token = generate_cookie()
|
||||
user['tokens'].append(token)
|
||||
# Update user
|
||||
db.update_tokens(user['id'], user['tokens'])
|
||||
return {'success': True, 'message': 'Logged in', 'token': token}
|
35
main.py
35
main.py
@ -48,7 +48,6 @@ def signup():
|
||||
email = request.form['email']
|
||||
domain = request.form['domain']
|
||||
password = request.form['password']
|
||||
print("New signup for " + email + " | " + domain)
|
||||
try:
|
||||
valid = validate_email(email)
|
||||
email = valid.email
|
||||
@ -63,6 +62,20 @@ def signup():
|
||||
|
||||
except EmailNotValidError as e:
|
||||
return jsonify({'success': False, 'message': 'Invalid email'}), 400
|
||||
|
||||
@app.route('/login', methods=['POST'])
|
||||
def login():
|
||||
email=request.form['email']
|
||||
password=request.form['password']
|
||||
user = accounts.login(email,password)
|
||||
if not user['success']:
|
||||
return error(user['message'])
|
||||
# Redirect to dashboard with cookie
|
||||
resp = make_response(redirect('/edit'))
|
||||
resp.set_cookie('token', user['token'])
|
||||
return resp
|
||||
|
||||
|
||||
|
||||
@app.route('/logout')
|
||||
def logout():
|
||||
@ -77,13 +90,29 @@ def logout():
|
||||
|
||||
@app.route('/<path:path>')
|
||||
def catch_all(path):
|
||||
account = "Login"
|
||||
account_link = "login"
|
||||
site = "Null"
|
||||
if 'token' in request.cookies:
|
||||
token = request.cookies['token']
|
||||
# Verify token
|
||||
user = accounts.validate_token(token)
|
||||
if not user:
|
||||
# Remove cookie
|
||||
resp = make_response(redirect('/'))
|
||||
resp.set_cookie('token', '', expires=0)
|
||||
return resp
|
||||
account = user['email']
|
||||
account_link = "account"
|
||||
site = user['domain'] + ".exampledomainnathan1"
|
||||
|
||||
# If file exists, load it
|
||||
if os.path.isfile('templates/' + path):
|
||||
return render_template(path)
|
||||
return render_template(path,account=account,account_link=account_link,site=site)
|
||||
|
||||
# Try with .html
|
||||
if os.path.isfile('templates/' + path + '.html'):
|
||||
return render_template(path + '.html')
|
||||
return render_template(path + '.html',account=account,account_link=account_link,site=site)
|
||||
return redirect('/') # 404 catch all
|
||||
|
||||
# 404 catch all
|
||||
|
34
templates/account.html
Normal file
34
templates/account.html
Normal file
@ -0,0 +1,34 @@
|
||||
<!DOCTYPE html>
|
||||
<html data-bs-theme="light" lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
|
||||
<title>shakecities</title>
|
||||
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="assets/css/styles.min.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-md bg-dark py-3" data-bs-theme="dark">
|
||||
<div class="container"><a class="navbar-brand d-flex align-items-center" href="/"><span class="bs-icon-sm bs-icon-rounded bs-icon-primary d-flex justify-content-center align-items-center me-2 bs-icon"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-bezier">
|
||||
<path fill-rule="evenodd" d="M0 10.5A1.5 1.5 0 0 1 1.5 9h1A1.5 1.5 0 0 1 4 10.5v1A1.5 1.5 0 0 1 2.5 13h-1A1.5 1.5 0 0 1 0 11.5v-1zm1.5-.5a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5h-1zm10.5.5A1.5 1.5 0 0 1 13.5 9h1a1.5 1.5 0 0 1 1.5 1.5v1a1.5 1.5 0 0 1-1.5 1.5h-1a1.5 1.5 0 0 1-1.5-1.5v-1zm1.5-.5a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5h-1zM6 4.5A1.5 1.5 0 0 1 7.5 3h1A1.5 1.5 0 0 1 10 4.5v1A1.5 1.5 0 0 1 8.5 7h-1A1.5 1.5 0 0 1 6 5.5v-1zM7.5 4a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5h-1z"></path>
|
||||
<path d="M6 4.5H1.866a1 1 0 1 0 0 1h2.668A6.517 6.517 0 0 0 1.814 9H2.5c.123 0 .244.015.358.043a5.517 5.517 0 0 1 3.185-3.185A1.503 1.503 0 0 1 6 5.5v-1zm3.957 1.358A1.5 1.5 0 0 0 10 5.5v-1h4.134a1 1 0 1 1 0 1h-2.668a6.517 6.517 0 0 1 2.72 3.5H13.5c-.123 0-.243.015-.358.043a5.517 5.517 0 0 0-3.185-3.185z"></path>
|
||||
</svg></span><span>Brand</span></a><button data-bs-toggle="collapse" class="navbar-toggler" data-bs-target="#navcol-6"><span class="visually-hidden">Toggle navigation</span><span class="navbar-toggler-icon"></span></button>
|
||||
<div class="collapse navbar-collapse flex-grow-0 order-md-first" id="navcol-6">
|
||||
<ul class="navbar-nav me-auto">
|
||||
<li class="nav-item"><a class="nav-link active" href="/signup">Create your page</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="/edit">Edit your page</a></li>
|
||||
</ul>
|
||||
<div class="d-md-none my-2"><button class="btn btn-light me-2" type="button">Button</button><button class="btn btn-primary" type="button">Button</button></div>
|
||||
</div>
|
||||
<div class="d-none d-md-block"><a class="btn btn-primary" role="button" href="/account">{{account}}</a></div>
|
||||
</div>
|
||||
</nav>
|
||||
<section style="margin-top: 50px;text-align: center;">
|
||||
<p>Email: {{account}}<br>Site: <a href="https://{{site}}" target="_blank">{{site}}</a></p><a class="btn btn-primary" role="button" href="/logout">Logout</a>
|
||||
</section>
|
||||
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
31
templates/edit.html
Normal file
31
templates/edit.html
Normal file
@ -0,0 +1,31 @@
|
||||
<!DOCTYPE html>
|
||||
<html data-bs-theme="light" lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
|
||||
<title>shakecities</title>
|
||||
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="assets/css/styles.min.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-md bg-dark py-3" data-bs-theme="dark">
|
||||
<div class="container"><a class="navbar-brand d-flex align-items-center" href="/"><span class="bs-icon-sm bs-icon-rounded bs-icon-primary d-flex justify-content-center align-items-center me-2 bs-icon"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-bezier">
|
||||
<path fill-rule="evenodd" d="M0 10.5A1.5 1.5 0 0 1 1.5 9h1A1.5 1.5 0 0 1 4 10.5v1A1.5 1.5 0 0 1 2.5 13h-1A1.5 1.5 0 0 1 0 11.5v-1zm1.5-.5a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5h-1zm10.5.5A1.5 1.5 0 0 1 13.5 9h1a1.5 1.5 0 0 1 1.5 1.5v1a1.5 1.5 0 0 1-1.5 1.5h-1a1.5 1.5 0 0 1-1.5-1.5v-1zm1.5-.5a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5h-1zM6 4.5A1.5 1.5 0 0 1 7.5 3h1A1.5 1.5 0 0 1 10 4.5v1A1.5 1.5 0 0 1 8.5 7h-1A1.5 1.5 0 0 1 6 5.5v-1zM7.5 4a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5h-1z"></path>
|
||||
<path d="M6 4.5H1.866a1 1 0 1 0 0 1h2.668A6.517 6.517 0 0 0 1.814 9H2.5c.123 0 .244.015.358.043a5.517 5.517 0 0 1 3.185-3.185A1.503 1.503 0 0 1 6 5.5v-1zm3.957 1.358A1.5 1.5 0 0 0 10 5.5v-1h4.134a1 1 0 1 1 0 1h-2.668a6.517 6.517 0 0 1 2.72 3.5H13.5c-.123 0-.243.015-.358.043a5.517 5.517 0 0 0-3.185-3.185z"></path>
|
||||
</svg></span><span>Brand</span></a><button data-bs-toggle="collapse" class="navbar-toggler" data-bs-target="#navcol-6"><span class="visually-hidden">Toggle navigation</span><span class="navbar-toggler-icon"></span></button>
|
||||
<div class="collapse navbar-collapse flex-grow-0 order-md-first" id="navcol-6">
|
||||
<ul class="navbar-nav me-auto">
|
||||
<li class="nav-item"><a class="nav-link active" href="/signup">Create your page</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="/edit">Edit your page</a></li>
|
||||
</ul>
|
||||
<div class="d-md-none my-2"><button class="btn btn-light me-2" type="button">Button</button><button class="btn btn-primary" type="button">Button</button></div>
|
||||
</div>
|
||||
<div class="d-none d-md-block"><a class="btn btn-primary" role="button" href="/account">{{account}}</a></div>
|
||||
</div>
|
||||
</nav>
|
||||
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
38
templates/login.html
Normal file
38
templates/login.html
Normal file
@ -0,0 +1,38 @@
|
||||
<!DOCTYPE html>
|
||||
<html data-bs-theme="light" lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
|
||||
<title>shakecities</title>
|
||||
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="assets/css/styles.min.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-md bg-dark py-3" data-bs-theme="dark">
|
||||
<div class="container"><a class="navbar-brand d-flex align-items-center" href="/"><span class="bs-icon-sm bs-icon-rounded bs-icon-primary d-flex justify-content-center align-items-center me-2 bs-icon"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-bezier">
|
||||
<path fill-rule="evenodd" d="M0 10.5A1.5 1.5 0 0 1 1.5 9h1A1.5 1.5 0 0 1 4 10.5v1A1.5 1.5 0 0 1 2.5 13h-1A1.5 1.5 0 0 1 0 11.5v-1zm1.5-.5a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5h-1zm10.5.5A1.5 1.5 0 0 1 13.5 9h1a1.5 1.5 0 0 1 1.5 1.5v1a1.5 1.5 0 0 1-1.5 1.5h-1a1.5 1.5 0 0 1-1.5-1.5v-1zm1.5-.5a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5h-1zM6 4.5A1.5 1.5 0 0 1 7.5 3h1A1.5 1.5 0 0 1 10 4.5v1A1.5 1.5 0 0 1 8.5 7h-1A1.5 1.5 0 0 1 6 5.5v-1zM7.5 4a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5h-1z"></path>
|
||||
<path d="M6 4.5H1.866a1 1 0 1 0 0 1h2.668A6.517 6.517 0 0 0 1.814 9H2.5c.123 0 .244.015.358.043a5.517 5.517 0 0 1 3.185-3.185A1.503 1.503 0 0 1 6 5.5v-1zm3.957 1.358A1.5 1.5 0 0 0 10 5.5v-1h4.134a1 1 0 1 1 0 1h-2.668a6.517 6.517 0 0 1 2.72 3.5H13.5c-.123 0-.243.015-.358.043a5.517 5.517 0 0 0-3.185-3.185z"></path>
|
||||
</svg></span><span>Brand</span></a><button data-bs-toggle="collapse" class="navbar-toggler" data-bs-target="#navcol-6"><span class="visually-hidden">Toggle navigation</span><span class="navbar-toggler-icon"></span></button>
|
||||
<div class="collapse navbar-collapse flex-grow-0 order-md-first" id="navcol-6">
|
||||
<ul class="navbar-nav me-auto">
|
||||
<li class="nav-item"><a class="nav-link active" href="/signup">Create your page</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="/edit">Edit your page</a></li>
|
||||
</ul>
|
||||
<div class="d-md-none my-2"><button class="btn btn-light me-2" type="button">Button</button><button class="btn btn-primary" type="button">Button</button></div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<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);">Sign in to manage your page</h4>
|
||||
</div>
|
||||
<form style="width: 80%;margin: auto;text-align: right;margin-top: 20px;" method="post"><input class="form-control" type="email" style="margin: auto;width: 100%;margin-top: 10px;" placeholder="email" name="email" required=""><input class="form-control" type="password" style="margin: auto;width: 100%;margin-top: 10px;" name="password" placeholder="Password" required="" minlength="6"><input class="btn btn-primary" type="submit" style="margin-top: 10px;"></form>
|
||||
</div>
|
||||
</section>
|
||||
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user