mirror of
https://github.com/BreizhHardware/Jellystat.git
synced 2026-01-18 16:27:20 +01:00
Refactor user creation logic in auth.js
This commit is contained in:
@@ -8,7 +8,7 @@ class Config {
|
||||
const state = this.#getConfigState(config);
|
||||
|
||||
if (state < 1) {
|
||||
return { error: "Config Details Not Found" };
|
||||
return { state: 0, error: "Config Details Not Found" };
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -39,7 +39,10 @@ class Config {
|
||||
//state 2 = configured and user and api key set
|
||||
|
||||
if (Configured.length > 0 && Configured[0].APP_USER !== null) {
|
||||
if (Configured[0].JF_API_KEY === null || (typeof Configured[0].JF_API_KEY === 'string' && Configured[0].JF_API_KEY.trim() === "")) {
|
||||
if (
|
||||
Configured[0].JF_API_KEY === null ||
|
||||
(typeof Configured[0].JF_API_KEY === "string" && Configured[0].JF_API_KEY.trim() === "")
|
||||
) {
|
||||
//check if user is configured but API is not configured then return state 1
|
||||
state = 1;
|
||||
} else {
|
||||
|
||||
@@ -57,13 +57,11 @@ router.post("/createuser", async (req, res) => {
|
||||
const { username, password } = req.body;
|
||||
const config = await new configClass().getConfig();
|
||||
|
||||
if (config.state < 2) {
|
||||
if (config.state != null && config.state < 2) {
|
||||
const user = { id: 1, username: username };
|
||||
|
||||
const hasConfig = await new configClass().getConfig();
|
||||
|
||||
let query = 'INSERT INTO app_config ("ID","APP_USER","APP_PASSWORD") VALUES (1,$1,$2)';
|
||||
if (!hasConfig.error) {
|
||||
if (config.state > 0) {
|
||||
query = 'UPDATE app_config SET "APP_USER"=$1, "APP_PASSWORD"=$2';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user