Fixed signups and oauth buttons now only show if enabled

The signup form now works and the oauth buttons are only visible if they have been enabled in the settings.json file
This commit is contained in:
2025-08-26 12:16:22 +01:00
parent 349a4192e0
commit 716a4c6148
4 changed files with 17 additions and 11 deletions

View File

@@ -2,12 +2,12 @@
"branding":{ "branding":{
"name":"AiThingy" "name":"AiThingy"
}, },
"auth_mode":"code", "signup_mode":"code",
"default_role":"none", "default_role":"none",
"default_permissions":[ "default_permissions":[
"createChat" "createChat"
], ],
"auth_codes":[ "signup_codes":[
{ {
"name":"code1", "name":"code1",
"code":"a1b2c3", "code":"a1b2c3",
@@ -29,5 +29,6 @@
"enabled":"true", "enabled":"true",
"client_id":"client_id", "client_id":"client_id",
"client_secret":"client_secret" "client_secret":"client_secret"
} },
"mongo_password":"yourMongoPassword"
} }

View File

@@ -23,7 +23,7 @@ github_token_endpoint = "https://github.com/login/oauth/access_token"
github_user_endpoint = "https://api.github.com/user" github_user_endpoint = "https://api.github.com/user"
mongoUser = 'root' mongoUser = 'root'
mongoPassword = '39zj6bNT5gaXbmuOBAYn5pZRO' mongoPassword = settings["mongo_password"]
mongoHost = 'localhost' mongoHost = 'localhost'
mongoPort = '27017' mongoPort = '27017'
mongoDatabase = 'database' mongoDatabase = 'database'
@@ -156,7 +156,7 @@ def createChat():
def signup(): def signup():
token = request.cookies.get('auth_token', 'none') token = request.cookies.get('auth_token', 'none')
if (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 # Index page
# If logged in return home menu (Or logout if token is expired), # If logged in return home menu (Or logout if token is expired),
@@ -165,7 +165,7 @@ def signup():
def index(): def index():
token = request.cookies.get('auth_token', 'none') token = request.cookies.get('auth_token', 'none')
if (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: else:
user = usersCollection.find_one({'tokens.token': token}, {"_id":1,"tokens":{"$elemMatch": {"token":token}}}) user = usersCollection.find_one({'tokens.token': token}, {"_id":1,"tokens":{"$elemMatch": {"token":token}}})
if (user): if (user):
@@ -312,13 +312,11 @@ def handleSignup():
creationDate = int(datetime.now().timestamp()) creationDate = int(datetime.now().timestamp())
accessCode = request.json['access_code'] accessCode = request.json['access_code']
displayName = request.json['displayname'] displayName = request.json['displayname']
# Check if details are taken # Check if details are taken
sameUsername = usersCollection.count_documents({"username":username}) sameUsername = usersCollection.count_documents({"username":username})
sameEmail = usersCollection.count_documents({"email":email}) sameEmail = usersCollection.count_documents({"email":email})
if (sameUsername != 0 ) or ( sameEmail != 0): if (sameUsername != 0 ) or ( sameEmail != 0):
return jsonify("User already exists") return jsonify("User already exists")
# Check for appropriate role # Check for appropriate role
codeFound = False codeFound = False
if (settings["signup_mode"] == "none"): if (settings["signup_mode"] == "none"):

View File

@@ -154,13 +154,17 @@
<h1>Sign into {{ appName }}</h1> <h1>Sign into {{ appName }}</h1>
<p>Log in:</p> <p>Log in:</p>
</div> </div>
{% if oauthlogin == "true" %}
<div class="oauth-buttons"> <div class="oauth-buttons">
{% if githublogin == "true" %}
<a href="{{ githubUrl }}" class="button"> <a href="{{ githubUrl }}" class="button">
<img src="{{ url_for('static', filename='github-icon.png') }}" alt="Github logo"> <img src="{{ url_for('static', filename='github-icon.png') }}" alt="Github logo">
Sign in with Github Sign in with Github
</a> </a>
{% endif %}
</div> </div>
<div class="divider">Or</div> <div class="divider">Or</div>
{% endif %}
<div class="emaillogin"> <div class="emaillogin">
<input id="userbox" class="input" type="text" name="username" placeholder="Username"> <input id="userbox" class="input" type="text" name="username" placeholder="Username">
<input id="passbox" class="input" type="password" name="password" placeholder="Password"> <input id="passbox" class="input" type="password" name="password" placeholder="Password">

View File

@@ -154,13 +154,17 @@
<h1>Sign up to {{ appName }}</h1> <h1>Sign up to {{ appName }}</h1>
<p>Please fill out your details:</p> <p>Please fill out your details:</p>
</div> </div>
{% if oauthlogin == "true" %}
<div class="oauth-buttons"> <div class="oauth-buttons">
{% if githublogin == "true" %}
<a href="{{ githubUrl }}" class="button"> <a href="{{ githubUrl }}" class="button">
<img src="{{ url_for('static', filename='github-icon.png') }}" alt="Github logo"> <img src="{{ url_for('static', filename='github-icon.png') }}" alt="Github logo">
Sign up with Github Sign up with Github
</a> </a>
{% endif %}
</div> </div>
<div class="divider">Or</div> <div class="divider">Or</div>
{% endif %}
<div class="emaillogin"> <div class="emaillogin">
<input id="userbox" class="input" type="text" name="username" placeholder="Username"> <input id="userbox" class="input" type="text" name="username" placeholder="Username">
<input id="displaybox" class="input" type="text" name="display" placeholder="Display name"> <input id="displaybox" class="input" type="text" name="display" placeholder="Display name">
@@ -168,7 +172,7 @@
<input id="passbox" class="input" type="password" name="password" placeholder="Password"> <input id="passbox" class="input" type="password" name="password" placeholder="Password">
<input id="codebox" class="input" type="password" name="password" placeholder="Signup Code"> <input id="codebox" class="input" type="password" name="password" placeholder="Signup Code">
</div> </div>
<a onclick="login(document.getElementById('userbox').value, document.getElementById('passbox').value, document.getElementById('displaybox').value), document.getElementById('emailbox').value, document.getElementById('codebox').value" class="button loginbutton">Sign Up</a> <a onclick="login(document.getElementById('userbox').value, document.getElementById('passbox').value, document.getElementById('displaybox').value, document.getElementById('emailbox').value, document.getElementById('codebox').value)" class="button loginbutton">Sign Up</a>
<p id="incorrectdetailstext" style="display: none;">Incorrect signup code</p> <p id="incorrectdetailstext" style="display: none;">Incorrect signup code</p>
<p id="existingusertext" style="display: none;">User already exists</p> <p id="existingusertext" style="display: none;">User already exists</p>
<p id="somethingwrongtext" style="display: none;">Something went wrong</p> <p id="somethingwrongtext" style="display: none;">Something went wrong</p>
@@ -200,8 +204,7 @@
} else if (result == "Signups have been disabled" || result == "An error occured") { } else if (result == "Signups have been disabled" || result == "An error occured") {
document.getElementById("somethingwrongtext").style = "display: block;" document.getElementById("somethingwrongtext").style = "display: block;"
} else { } else {
document.cookie = `auth_token=${result}`; window.location = "{{ url_for('index') }}";
window.location.reload();
} }
} catch (error) { } catch (error) {
console.error(error.message) console.error(error.message)