Updated login

This commit is contained in:
Tracker-Friendly 2023-11-20 17:24:58 +00:00
parent 8cef8c88fb
commit 11895bc784
3 changed files with 48 additions and 16 deletions

View File

@ -37,7 +37,7 @@ def verify_bcrypt(passphrase, hashed_password):
@app.route('/') @app.route('/')
def index(): def index():
if 'passwordhash' in request.cookies and request.cookies.get('passwordhash'): if 'passwordhash' in request.cookies and request.cookies.get('passwordhash'):
return redirect("/account/dashboard") return render_template('dashboard.html')
else: else:
return render_template('index.html') return render_template('index.html')
@ -51,14 +51,14 @@ def login():
if passwordhash: if passwordhash:
is_password_valid = verify_bcrypt(password_to_check, passwordhash) is_password_valid = verify_bcrypt(password_to_check, passwordhash)
if is_password_valid: if is_password_valid:
response = make_response("Logged in!") response = make_response(redirect('/account'))
response.set_cookie('passwordhash', passwordhash) response.set_cookie('passwordhash', passwordhash)
response.set_cookie('email', request.form['email']) response.set_cookie('email', request.form['email'])
return response return response
else: else:
return "Incorrect email or password" return render_template('wrong.html')
else: else:
return "Email not found in the database" return render_template('wrong.html')
@app.route('/deleteapi', methods=['POST']) @app.route('/deleteapi', methods=['POST'])
def delete(): def delete():
@ -74,7 +74,7 @@ def delete():
if result.returncode == 0: if result.returncode == 0:
# Command executed successfully # Command executed successfully
response = make_response("Email deleted!") response = make_response(redirect('/'))
response.set_cookie('passwordhash', '', expires=0) response.set_cookie('passwordhash', '', expires=0)
response.set_cookie('email', '', expires=0) response.set_cookie('email', '', expires=0)
return response return response
@ -82,20 +82,12 @@ def delete():
# Handle errors, log them, and return False # Handle errors, log them, and return False
error_message = result.stderr.decode("utf-8") error_message = result.stderr.decode("utf-8")
print(f"Error deleting email account: {error_message}") print(f"Error deleting email account: {error_message}")
return "Error deleting email account!" return render_template('err.html')
else: else:
return "Incorrect email or password" return render_template('wrong.html')
else: else:
return "Email not found in the database" return render_template('wrong.html')
@app.route('/dashboard')
def dashboard():
if 'passwordhash' in request.cookies and request.cookies.get('passwordhash'):
return render_template('dashboard.html')
else:
return redirect("/account")
@app.route('/deleteacct') @app.route('/deleteacct')
def deleteacct(): def deleteacct():

View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Error!</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
</head>
<body>
<div class="headerbar">
<a href="/">HectaMail</a>
<a href="/register">Sign up</a>
<a class="main" href="/account">Account</a>
</div>
<div class="content">
<h1>Error!</h1>
<p1>Something went wrong on our end - the mail server could be down. Please try again later.</p1>
<div class=spacer2>
<button onclick="location.href = '/account';">Go Back</button>
</div>
</div>
</body><style type="text/css"></style></html>

View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Error!</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
</head>
<body>
<div class="headerbar">
<a href="/">HectaMail</a>
<a href="/register">Sign up</a>
<a class="main" href="/account">Account</a>
</div>
<div class="content">
<h1>Error!</h1>
<p1>Incorrect Email or password!</p1>
<div class=spacer2>
<button onclick="location.href = '/account';">Go Back</button>
</div>
</div>
</body><style type="text/css"></style></html>