2023-09-13 19:56:58 +00:00
|
|
|
const { PrismaClient } = require("@prisma/client");
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
const core = require("./core");
|
2023-09-21 00:41:57 +00:00
|
|
|
const settings = require("../settings");
|
2023-09-13 19:56:58 +00:00
|
|
|
|
|
|
|
async function userRegistration(username, password) {
|
|
|
|
if (!username) return { success: false, message: "No username provided" };
|
|
|
|
if (!password) return { success: false, message: "No password provided" };
|
|
|
|
// TODO: Admin customizable minimum password length
|
|
|
|
if (password.length < 4) return { success: false, message: "Password not long enough" };
|
|
|
|
|
|
|
|
const existing_user = await core.getUser({ username: username });
|
|
|
|
|
|
|
|
if (existing_user.success) return { success: false, message: "Username already exists" };
|
|
|
|
|
|
|
|
return { success: true };
|
|
|
|
}
|
|
|
|
|
|
|
|
async function userLogin(username, password) {
|
|
|
|
const existing_user = await core.getUser({ username: username });
|
|
|
|
|
|
|
|
if (!existing_user.success) return { success: false, message: "User does not exist" };
|
|
|
|
if (existing_user.role === "LOCKED") return { success: false, message: "Account is locked: Contact your administrator" };
|
|
|
|
|
|
|
|
return { success: true, data: existing_user.data };
|
|
|
|
}
|
|
|
|
|
2023-09-21 00:41:57 +00:00
|
|
|
module.exports = { userRegistration, userLogin };
|