OAuth works, not quite migration
This commit is contained in:
parent
814f05dfa6
commit
5a13b2976d
|
@ -1,6 +1,6 @@
|
|||
[config]
|
||||
PORT = 8080
|
||||
SECRET_KEY = placeholder
|
||||
PORT = 8083
|
||||
SECRET_KEY = placeholdiawolhkvghuilojkvghijhvmgaer
|
||||
UPLOAD_FOLDER = uploads
|
||||
PASSWORD_REQUIREMENT = 8
|
||||
UPLOAD_LIMIT = 8
|
||||
|
|
10
main
10
main
|
@ -438,8 +438,10 @@ async def apioauth():
|
|||
userID = check_username_taken(username)
|
||||
user = get_user(userID)
|
||||
if user == "error":
|
||||
conn.execute("INSERT INTO users (username, password, created, htmldescription) VALUES (?, ?, ?, ?)",
|
||||
(username, str("OAUTH-" + sub), str(time.time()), ""))
|
||||
conn.execute("INSERT INTO users (username, password, created, htmldescription, banned) VALUES (?, ?, ?, ?, ?)",
|
||||
(username, str("OAUTH-" + sub), str(time.time()), "", "0"))
|
||||
userID = conn.execute("SELECT * FROM users WHERE lower(username) = ?",
|
||||
(username.lower(),)).fetchone()["id"]
|
||||
else:
|
||||
if user["password"] != "OAUTH-" + sub:
|
||||
return {"error": "Migration required or username taken"}, 422
|
||||
|
@ -660,8 +662,9 @@ async def login():
|
|||
conn.commit()
|
||||
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("legacy_migrate", "1")
|
||||
return response
|
||||
|
||||
#resp = await make_response(redirect("/"))
|
||||
|
@ -750,6 +753,7 @@ async def logout():
|
|||
session = request.cookies.get("session_DO_NOT_SHARE")
|
||||
resp.delete_cookie("session_DO_NOT_SHARE")
|
||||
resp.delete_cookie("prefuser")
|
||||
resp.delete_cookie("legacy_migrate")
|
||||
return resp
|
||||
|
||||
@app.errorhandler(500)
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<br>
|
||||
<a href="/">back</a>
|
||||
<br><br>
|
||||
<h1>Log in to burgercat</h1>
|
||||
<h1>Migrate from legacy account</h1>
|
||||
{% with messages = get_flashed_messages() %}
|
||||
{% if messages %}
|
||||
{% for message in messages %}
|
||||
|
@ -27,9 +27,7 @@
|
|||
<input name="password" type="password" placeholder="Password" required>
|
||||
<br>
|
||||
<br>
|
||||
<button type="submit">Log in</button>
|
||||
<br><br>
|
||||
Don't have an account? <a href="/signup">Sign up!</a>
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -121,6 +121,7 @@
|
|||
.then((response) => {
|
||||
async function doStuff2() {
|
||||
if (response.status == 200) {
|
||||
document.cookie = 'legacy_migrate=; Max-Age=0; path=/;"
|
||||
window.location.replace("/")
|
||||
} else {
|
||||
document.getElementById("text").innerText = "Failed: " + key["error"]
|
||||
|
|
|
@ -118,7 +118,7 @@
|
|||
console.log("User:", userinfoData.name)
|
||||
console.log("Sub:", userinfoData.sub);
|
||||
let preferreduser = userinfoData.name
|
||||
if (getCookie("prefuser") != "") {
|
||||
if (getCookie("prefuser") != null) {
|
||||
preferreduser = getCookie("prefuser")
|
||||
}
|
||||
document.getElementById("text").innerText = "Authenticating, " + userinfoData.name;
|
||||
|
|
Reference in New Issue