This commit is contained in:
Benjamin Toby 2026-03-12 04:10:01 +00:00
parent f95770dec6
commit 355ae63651
6 changed files with 73 additions and 11 deletions

View File

@ -13,6 +13,8 @@ export default function Main() {
return null;
}
console.log("deployment_user", deployment_user);
const is_super_admin = Boolean(deployment_user.is_super_admin);
return (

View File

@ -1,3 +1,4 @@
import { NSQLITE_TURBOCI_ADMIN_USERS } from "@/src/db/types";
import { AppContext } from "@/src/pages/_app";
import { TurboCISignupFormObject } from "@/src/types";
import useStatus from "@/twui/components/hooks/useStatus";
@ -5,11 +6,17 @@ import { useContext, useState } from "react";
type Params = {
new_deployment_user?: boolean;
existing_user?: NSQLITE_TURBOCI_ADMIN_USERS;
};
export default function useSignupForm({ new_deployment_user }: Params) {
export default function useSignupForm({
new_deployment_user,
existing_user,
}: Params) {
const { pageProps } = useContext(AppContext);
const [newUser, setNewUser] = useState<TurboCISignupFormObject>({});
const [newUser, setNewUser] = useState<TurboCISignupFormObject>(
existing_user || {},
);
const { loading, setLoading } = useStatus();
const [isPasswordConfirmed, setIsPasswordConfirmed] = useState(false);

View File

@ -6,12 +6,17 @@ import fetchApi from "@/twui/components/utils/fetch/fetchApi";
import { APIReqObject } from "@/src/types";
import { APIResponseObject } from "@moduletrace/datasquirel/dist/package-shared/types";
import { useEffect } from "react";
import { NSQLITE_TURBOCI_ADMIN_USERS } from "@/src/db/types";
type Props = {
new_deployment_user?: boolean;
existing_user?: NSQLITE_TURBOCI_ADMIN_USERS;
};
export default function SignupForm({ new_deployment_user }: Props) {
export default function SignupForm({
new_deployment_user,
existing_user,
}: Props) {
const {
newUser,
setNewUser,
@ -20,7 +25,7 @@ export default function SignupForm({ new_deployment_user }: Props) {
isPasswordConfirmed,
setIsPasswordConfirmed,
pageProps,
} = useSignupForm({ new_deployment_user });
} = useSignupForm({ new_deployment_user, existing_user });
const is_password_valid = Boolean(
isPasswordConfirmed &&
@ -140,7 +145,11 @@ export default function SignupForm({ new_deployment_user }: Props) {
return;
}
if (!window.confirm(`Create Super Admin Account?`)) {
const confirm_msg = pageProps.user.id
? `Add New User?`
: `Create Super Admin Account?`;
if (!window.confirm(confirm_msg)) {
return;
}
@ -156,17 +165,23 @@ export default function SignupForm({ new_deployment_user }: Props) {
},
)
.then((res) => {
console.log("res", res);
if (res.success) {
window.location.reload();
if (pageProps.user.id) {
window.location.pathname = `/admin/users`;
} else {
window.location.reload();
}
}
})
.finally(() => {});
}}
loading={loading}
>
{pageProps.user.super_admin ? "Add User" : "Signup"}
{existing_user?.id
? ``
: pageProps.user.super_admin
? "Add User"
: "Signup"}
</Button>
</Stack>
</form>

View File

@ -18,9 +18,11 @@ export default async function setupDeploymentUser({ user_id }: Params) {
targetId: _n(user_id),
});
console.log("target_user_res", target_user_res);
const target_user = target_user_res.singleRes;
if (!target_user?.id) {
if (!target_user?.id || !target_user.username) {
return;
}

View File

@ -0,0 +1,36 @@
import loginUser from "@/src/functions/auth/login-user";
import { NSQLITE_TURBOCI_ADMIN_USERS } from "@/src/db/types";
import userAuth from "@/src/utils/user-auth";
import NSQLite from "@moduletrace/nsqlite";
import { APIResponseObject } from "@moduletrace/datasquirel/dist/package-shared/types";
import type { NextApiRequest, NextApiResponse } from "next";
import { APIReqObject } from "@/src/types";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse<APIResponseObject>,
) {
try {
if (req.method !== "POST") {
return res.json({
success: false,
msg: "Wrong Method",
});
}
const { singleRes: user } = await userAuth({ req });
if (!user?.id || !user.super_admin) {
return res.json({
success: false,
msg: "Unauthorized",
});
}
return res.json({
success: true,
});
} catch (error: any) {
return res.json({ success: false, msg: error.message });
}
}

View File

@ -11,7 +11,7 @@ export default function grabDeploymentUserDirNames({ user }: Params) {
const user_dir = `/home/${username}`;
const ssh_dir = `${user_dir}/.ssh`;
const ssh_key_file = `${ssh_dir}/${username}`;
const sshd_config_file = `/etc/ssh/sshd_config.d/${username}`;
const sshd_config_file = `/etc/ssh/sshd_config.d/${username}.conf`;
const force_command_file = `/usr/local/bin/turboci-deployment-user-${username}`;
return {