From 494e71ad397eacfeca469a50172b4e915706336c Mon Sep 17 00:00:00 2001 From: hyvenet Date: Tue, 26 Aug 2025 12:07:29 +0100 Subject: [PATCH] Fixed failing signups and made oauth settings work Fixed the signup form so it no longer fails, and made the oauth login buttons only appear when they have been enabled in the settings.json file --- config/example-settings.json | 7 ++++--- main.py | 8 +++----- templates/login.html | 4 ++++ templates/signup.html | 9 ++++++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/config/example-settings.json b/config/example-settings.json index 612a479..e50a598 100644 --- a/config/example-settings.json +++ b/config/example-settings.json @@ -2,12 +2,12 @@ "branding":{ "name":"AiThingy" }, - "auth_mode":"code", + "signup_mode":"code", "default_role":"none", "default_permissions":[ "createChat" ], - "auth_codes":[ + "signup_codes":[ { "name":"code1", "code":"a1b2c3", @@ -29,5 +29,6 @@ "enabled":"true", "client_id":"client_id", "client_secret":"client_secret" - } + }, + "mongo_password":"yourMongoPassword" } \ No newline at end of file diff --git a/main.py b/main.py index 7ce6cbb..0b9b94b 100644 --- a/main.py +++ b/main.py @@ -23,7 +23,7 @@ github_token_endpoint = "https://github.com/login/oauth/access_token" github_user_endpoint = "https://api.github.com/user" mongoUser = 'root' -mongoPassword = '39zj6bNT5gaXbmuOBAYn5pZRO' +mongoPassword = settings["mongo_password"] mongoHost = 'localhost' mongoPort = '27017' mongoDatabase = 'database' @@ -156,7 +156,7 @@ def createChat(): def signup(): token = request.cookies.get('auth_token', 'none') if (token == 'none'): - return render_template('signup.html', appName=appName, githubUrl=github_auth_endpoint) + return render_template('signup.html', appName=appName, githubUrl=github_auth_endpoint, githublogin=settings["github_oauth"]["enabled"], oauthlogin=settings["oauth_login"]) # Index page # If logged in return home menu (Or logout if token is expired), @@ -165,7 +165,7 @@ def signup(): def index(): token = request.cookies.get('auth_token', 'none') if (token == 'none'): - return render_template('login.html', appName=appName, githubUrl=github_auth_endpoint) + return render_template('login.html', appName=appName, githubUrl=github_auth_endpoint, githublogin=settings["github_oauth"]["enabled"], oauthlogin=settings["oauth_login"]) else: user = usersCollection.find_one({'tokens.token': token}, {"_id":1,"tokens":{"$elemMatch": {"token":token}}}) if (user): @@ -312,13 +312,11 @@ def handleSignup(): creationDate = int(datetime.now().timestamp()) accessCode = request.json['access_code'] displayName = request.json['displayname'] - # Check if details are taken sameUsername = usersCollection.count_documents({"username":username}) sameEmail = usersCollection.count_documents({"email":email}) if (sameUsername != 0 ) or ( sameEmail != 0): return jsonify("User already exists") - # Check for appropriate role codeFound = False if (settings["signup_mode"] == "none"): diff --git a/templates/login.html b/templates/login.html index 6fc997c..924f001 100644 --- a/templates/login.html +++ b/templates/login.html @@ -154,13 +154,17 @@

Sign into {{ appName }}

Log in:

+ {% if oauthlogin == "true" %}
+ {% if githublogin == "true" %} Github logo Sign in with Github + {% endif %}
Or
+ {% endif %}
diff --git a/templates/signup.html b/templates/signup.html index 34fdb6e..e7a9df4 100644 --- a/templates/signup.html +++ b/templates/signup.html @@ -154,13 +154,17 @@

Sign up to {{ appName }}

Please fill out your details:

+ {% if oauthlogin == "true" %}
+ {% if githublogin == "true" %} Github logo Sign up with Github + {% endif %}
Or
+ {% endif %}
@@ -168,7 +172,7 @@
- Sign Up + Sign Up @@ -200,8 +204,7 @@ } else if (result == "Signups have been disabled" || result == "An error occured") { document.getElementById("somethingwrongtext").style = "display: block;" } else { - document.cookie = `auth_token=${result}`; - window.location.reload(); + window.location = "{{ url_for('index') }}"; } } catch (error) { console.error(error.message)