building login

This commit is contained in:
Tristan Smith 2024-09-22 14:07:54 -04:00
parent 7a008bb795
commit 3d4a06df18
11 changed files with 49 additions and 41 deletions

View file

@ -22,6 +22,7 @@
<a href="/about/">About</a> <a href="/about/">About</a>
<a href="/blog/">Blog</a> <a href="/blog/">Blog</a>
<a href="/contact/">Contact</a> <a href="/contact/">Contact</a>
<a href="/login/">Login</a>
</td> </td>
</tr> </tr>

View file

@ -22,6 +22,7 @@
<a href="/about/">About</a> <a href="/about/">About</a>
<a href="/blog/">Blog</a> <a href="/blog/">Blog</a>
<a href="/contact/">Contact</a> <a href="/contact/">Contact</a>
<a href="/login/">Login</a>
</td> </td>
</tr> </tr>

View file

@ -22,6 +22,7 @@
<a href="/about/">About</a> <a href="/about/">About</a>
<a href="/blog/">Blog</a> <a href="/blog/">Blog</a>
<a href="/contact/">Contact</a> <a href="/contact/">Contact</a>
<a href="/login/">Login</a>
</td> </td>
</tr> </tr>

View file

@ -22,6 +22,7 @@
<a href="/about/">About</a> <a href="/about/">About</a>
<a href="/blog/">Blog</a> <a href="/blog/">Blog</a>
<a href="/contact/">Contact</a> <a href="/contact/">Contact</a>
<a href="/login/">Login</a>
</td> </td>
</tr> </tr>

View file

@ -22,6 +22,7 @@
<a href="/about/">About</a> <a href="/about/">About</a>
<a href="/blog/">Blog</a> <a href="/blog/">Blog</a>
<a href="/contact/">Contact</a> <a href="/contact/">Contact</a>
<a href="/login/">Login</a>
</td> </td>
</tr> </tr>

View file

@ -41,7 +41,7 @@
<br> <br>
<input type="submit" value="Reset Password"> <input type="submit" value="Reset Password">
</form> </form>
</div> </div>
</td> </td>
</tr> </tr>

View file

@ -22,6 +22,7 @@
<a href="/about/">About</a> <a href="/about/">About</a>
<a href="/blog/">Blog</a> <a href="/blog/">Blog</a>
<a href="/contact/">Contact</a> <a href="/contact/">Contact</a>
<a href="/login/">Login</a>
</td> </td>
</tr> </tr>

View file

@ -22,6 +22,7 @@
<a href="/about/">About</a> <a href="/about/">About</a>
<a href="/blog/">Blog</a> <a href="/blog/">Blog</a>
<a href="/contact/">Contact</a> <a href="/contact/">Contact</a>
<a href="/login/">Login</a>
</td> </td>
</tr> </tr>

View file

@ -22,6 +22,7 @@
<a href="/about/">About</a> <a href="/about/">About</a>
<a href="/blog/">Blog</a> <a href="/blog/">Blog</a>
<a href="/contact/">Contact</a> <a href="/contact/">Contact</a>
<a href="/login/">Login</a>
</td> </td>
</tr> </tr>

View file

@ -56,7 +56,7 @@ EXPIRATION=$(($(date +%s) + 3600))
sqlite3 $DB_PATH "UPDATE users SET reset_token='$TOKEN', reset_expires=$EXPIRATION WHERE username='$USERNAME';" sqlite3 $DB_PATH "UPDATE users SET reset_token='$TOKEN', reset_expires=$EXPIRATION WHERE username='$USERNAME';"
# Send reset link email # Send reset link email
RESET_LINK="https://monotreme.org/cgi-bin/reset_password.cgi?token=$TOKEN" RESET_LINK="https://monotreme.org/cgi-bin/reset_password.cgi?token=$TOKEN"
EMAIL_BODY=$(cat <<EOF EMAIL_BODY=$(cat <<EOF
From: info@monotreme.org From: info@monotreme.org
To: $EMAIL To: $EMAIL

View file

@ -1,44 +1,44 @@
#!/bin/bash #!/bin/bash
echo "Content-type: text/html" echo "Content-type: text/html"
echo "" echo ""
# Extract token from query string # Extract token from query string
TOKEN=$(echo "$QUERY_STRING" | sed -n 's/^.*token=\([^&]*\).*$/\1/p') TOKEN=$(echo "$QUERY_STRING" | sed -n 's/^.*token=\([^&]*\).*$/\1/p')
# Check if the token exists and is valid (not expired) # Check if the token exists and is valid (not expired)
DB_PATH="/var/lib/monotreme/data/monotreme.db" DB_PATH="/var/lib/monotreme/data/monotreme.db"
VALID_TOKEN=$(sqlite3 $DB_PATH "SELECT COUNT(*) FROM users WHERE reset_token='$TOKEN' AND reset_expires > strftime('%s','now');") VALID_TOKEN=$(sqlite3 $DB_PATH "SELECT COUNT(*) FROM users WHERE reset_token='$TOKEN' AND reset_expires > strftime('%s','now');")
if [ "$VALID_TOKEN" -eq 0 ]; then if [ "$VALID_TOKEN" -eq 0 ]; then
cat <<EOF
<html>
<head><title>Invalid Token</title></head>
<body>
<h1>Invalid or expired token!</h1>
<a href="/login/forgot/">Request a new reset link</a>
</body>
</html>
EOF
exit 1
fi
# Display reset form
cat <<EOF cat <<EOF
<html> <html>
<head><title>Invalid Token</title></head> <head><title>Reset Your Password</title></head>
<body> <body>
<h1>Invalid or expired token!</h1> <h1>Reset Your Password</h1>
<a href="/login/forgot/">Request a new reset link</a> <form action="/cgi-bin/reset_password_confirm.cgi" method="post">
</body> <input type="hidden" name="token" value="$TOKEN">
</html> <label for="password">New Password:</label>
EOF <input type="password" id="password" name="password" required>
exit 1 <br>
fi <label for="confirm_password">Confirm Password:</label>
<input type="password" id="confirm_password" name="confirm_password" required>
# Display reset form <br>
cat <<EOF <input type="submit" value="Reset Password">
<html> </form>
<head><title>Reset Your Password</title></head> </body>
<body> </html>
<h1>Reset Your Password</h1> EOF
<form action="/cgi-bin/reset_password_confirm.cgi" method="post">
<input type="hidden" name="token" value="$TOKEN">
<label for="password">New Password:</label>
<input type="password" id="password" name="password" required>
<br>
<label for="confirm_password">Confirm Password:</label>
<input type="password" id="confirm_password" name="confirm_password" required>
<br>
<input type="submit" value="Reset Password">
</form>
</body>
</html>
EOF