OAuth works, not quite migration

This commit is contained in:
Tracker-Friendly 2024-05-16 09:11:21 +01:00
parent 814f05dfa6
commit 5a13b2976d
5 changed files with 13 additions and 10 deletions

View File

@ -1,6 +1,6 @@
[config] [config]
PORT = 8080 PORT = 8083
SECRET_KEY = placeholder SECRET_KEY = placeholdiawolhkvghuilojkvghijhvmgaer
UPLOAD_FOLDER = uploads UPLOAD_FOLDER = uploads
PASSWORD_REQUIREMENT = 8 PASSWORD_REQUIREMENT = 8
UPLOAD_LIMIT = 8 UPLOAD_LIMIT = 8

10
main
View File

@ -438,8 +438,10 @@ async def apioauth():
userID = check_username_taken(username) userID = check_username_taken(username)
user = get_user(userID) user = get_user(userID)
if user == "error": if user == "error":
conn.execute("INSERT INTO users (username, password, created, htmldescription) VALUES (?, ?, ?, ?)", conn.execute("INSERT INTO users (username, password, created, htmldescription, banned) VALUES (?, ?, ?, ?, ?)",
(username, str("OAUTH-" + sub), str(time.time()), "")) (username, str("OAUTH-" + sub), str(time.time()), "", "0"))
userID = conn.execute("SELECT * FROM users WHERE lower(username) = ?",
(username.lower(),)).fetchone()["id"]
else: else:
if user["password"] != "OAUTH-" + sub: if user["password"] != "OAUTH-" + sub:
return {"error": "Migration required or username taken"}, 422 return {"error": "Migration required or username taken"}, 422
@ -660,8 +662,9 @@ async def login():
conn.commit() conn.commit()
conn.close() conn.close()
response = Response("""<script>window.location.href = "/";</script>""") response = Response("""<script>window.location.href = "/oauth";</script>""")
response.set_cookie("session_DO_NOT_SHARE", randomCharacters) response.set_cookie("session_DO_NOT_SHARE", randomCharacters)
response.set_cookie("legacy_migrate", "1")
return response return response
#resp = await make_response(redirect("/")) #resp = await make_response(redirect("/"))
@ -750,6 +753,7 @@ async def logout():
session = request.cookies.get("session_DO_NOT_SHARE") session = request.cookies.get("session_DO_NOT_SHARE")
resp.delete_cookie("session_DO_NOT_SHARE") resp.delete_cookie("session_DO_NOT_SHARE")
resp.delete_cookie("prefuser") resp.delete_cookie("prefuser")
resp.delete_cookie("legacy_migrate")
return resp return resp
@app.errorhandler(500) @app.errorhandler(500)

View File

@ -14,7 +14,7 @@
<br> <br>
<a href="/">back</a> <a href="/">back</a>
<br><br> <br><br>
<h1>Log in to burgercat</h1> <h1>Migrate from legacy account</h1>
{% with messages = get_flashed_messages() %} {% with messages = get_flashed_messages() %}
{% if messages %} {% if messages %}
{% for message in messages %} {% for message in messages %}
@ -27,9 +27,7 @@
<input name="password" type="password" placeholder="Password" required> <input name="password" type="password" placeholder="Password" required>
<br> <br>
<br> <br>
<button type="submit">Log in</button> <button type="submit">Login</button>
<br><br>
Don't have an account? <a href="/signup">Sign up!</a>
</form> </form>
</body> </body>
</html> </html>

View File

@ -121,6 +121,7 @@
.then((response) => { .then((response) => {
async function doStuff2() { async function doStuff2() {
if (response.status == 200) { if (response.status == 200) {
document.cookie = 'legacy_migrate=; Max-Age=0; path=/;"
window.location.replace("/") window.location.replace("/")
} else { } else {
document.getElementById("text").innerText = "Failed: " + key["error"] document.getElementById("text").innerText = "Failed: " + key["error"]

View File

@ -118,7 +118,7 @@
console.log("User:", userinfoData.name) console.log("User:", userinfoData.name)
console.log("Sub:", userinfoData.sub); console.log("Sub:", userinfoData.sub);
let preferreduser = userinfoData.name let preferreduser = userinfoData.name
if (getCookie("prefuser") != "") { if (getCookie("prefuser") != null) {
preferreduser = getCookie("prefuser") preferreduser = getCookie("prefuser")
} }
document.getElementById("text").innerText = "Authenticating, " + userinfoData.name; document.getElementById("text").innerText = "Authenticating, " + userinfoData.name;