Updates
This commit is contained in:
@@ -57,10 +57,10 @@ export default function LoginForm() {
|
||||
placeholder="Password"
|
||||
title="Password"
|
||||
type="password"
|
||||
changeHandler={(v) => {
|
||||
onChange={(e) => {
|
||||
setLoginData((prev) => ({
|
||||
...prev,
|
||||
password: v,
|
||||
password: e.target.value,
|
||||
}));
|
||||
}}
|
||||
validity={
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
* @type {import("@moduletrace/nsqlite/dist/types").NSQLITE_DatabaseSchemaType}
|
||||
*/
|
||||
const schema = {
|
||||
dbName: "test-db",
|
||||
tables: [
|
||||
{
|
||||
tableName: "users",
|
||||
|
||||
+3
-3
@@ -3,7 +3,7 @@ export const NSQLiteTables = [
|
||||
"users_ports",
|
||||
] as const
|
||||
|
||||
export type NSQLITE_TEST_DB_USERS = {
|
||||
export type NSQLITE_TURBOCI_ADMIN_USERS = {
|
||||
/**
|
||||
* The unique identifier of the record.
|
||||
*/
|
||||
@@ -26,7 +26,7 @@ export type NSQLITE_TEST_DB_USERS = {
|
||||
all_deployment_access?: number;
|
||||
}
|
||||
|
||||
export type NSQLITE_TEST_DB_USERS_PORTS = {
|
||||
export type NSQLITE_TURBOCI_ADMIN_USERS_PORTS = {
|
||||
/**
|
||||
* The unique identifier of the record.
|
||||
*/
|
||||
@@ -43,4 +43,4 @@ export type NSQLITE_TEST_DB_USERS_PORTS = {
|
||||
port?: number;
|
||||
}
|
||||
|
||||
export type NSQLITE_TEST_DB_ALL_TYPEDEFS = NSQLITE_TEST_DB_USERS & NSQLITE_TEST_DB_USERS_PORTS
|
||||
export type NSQLITE_TURBOCI_ADMIN_ALL_TYPEDEFS = NSQLITE_TURBOCI_ADMIN_USERS & NSQLITE_TURBOCI_ADMIN_USERS_PORTS
|
||||
@@ -1,7 +1,7 @@
|
||||
import { NextApiResponse } from "next";
|
||||
import { ServerResponse } from "http";
|
||||
import NSQLite from "@moduletrace/nsqlite";
|
||||
import { NSQLITE_TEST_DB_USERS, NSQLiteTables } from "../../db/types";
|
||||
import { NSQLITE_TURBOCI_ADMIN_USERS, NSQLiteTables } from "../../db/types";
|
||||
import { User } from "../../types";
|
||||
import { setCookie } from "../../utils/cookies-actions";
|
||||
import { EJSON } from "../../exports/client-exports";
|
||||
@@ -24,11 +24,11 @@ export default async function loginUser({
|
||||
password,
|
||||
email_or_username,
|
||||
}: Params): Promise<APIResponseObject> {
|
||||
let fetched_user: NSQLITE_TEST_DB_USERS | undefined;
|
||||
let fetched_user: NSQLITE_TURBOCI_ADMIN_USERS | undefined;
|
||||
|
||||
if (user_id) {
|
||||
const user_res = await NSQLite.select<
|
||||
NSQLITE_TEST_DB_USERS,
|
||||
NSQLITE_TURBOCI_ADMIN_USERS,
|
||||
(typeof NSQLiteTables)[number]
|
||||
>({
|
||||
table: "users",
|
||||
@@ -44,7 +44,7 @@ export default async function loginUser({
|
||||
|
||||
if (email_or_username) {
|
||||
const user_res = await NSQLite.select<
|
||||
NSQLITE_TEST_DB_USERS,
|
||||
NSQLITE_TURBOCI_ADMIN_USERS,
|
||||
(typeof NSQLiteTables)[number]
|
||||
>({
|
||||
table: "users",
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { NSQLITE_TEST_DB_USERS_PORTS, NSQLiteTables } from "@/src/db/types";
|
||||
import {
|
||||
NSQLITE_TURBOCI_ADMIN_USERS_PORTS,
|
||||
NSQLiteTables,
|
||||
} from "@/src/db/types";
|
||||
import {
|
||||
NormalizedServerObject,
|
||||
ParsedDeploymentServiceConfig,
|
||||
@@ -74,7 +77,7 @@ export default async function grabTtydServerInfo({
|
||||
const connected_user_data = grabConnectedWebsocketUserdata({ user });
|
||||
|
||||
await BunSQLite.insert<
|
||||
NSQLITE_TEST_DB_USERS_PORTS,
|
||||
NSQLITE_TURBOCI_ADMIN_USERS_PORTS,
|
||||
(typeof NSQLiteTables)[number]
|
||||
>({
|
||||
data: [{ user_id: user.id, port: available_port }],
|
||||
|
||||
@@ -2,31 +2,67 @@ import { AppContext } from "@/src/pages/_app";
|
||||
import Dropdown from "@/twui/components/elements/Dropdown";
|
||||
import LinkList from "@/twui/components/elements/LinkList";
|
||||
import LucideIcon from "@/twui/components/elements/lucide-icon";
|
||||
import Paper from "@/twui/components/elements/Paper";
|
||||
import Divider from "@/twui/components/layout/Divider";
|
||||
import Img from "@/twui/components/layout/Img";
|
||||
import Row from "@/twui/components/layout/Row";
|
||||
import Span from "@/twui/components/layout/Span";
|
||||
import { useContext } from "react";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
export default function HeaderUser() {
|
||||
const { pageProps } = useContext(AppContext);
|
||||
const { user } = pageProps;
|
||||
|
||||
const ICON_SIZE = 35;
|
||||
|
||||
return (
|
||||
<Dropdown
|
||||
target={
|
||||
<Row>
|
||||
<Img
|
||||
circle
|
||||
size={25}
|
||||
src={user.image_thumbnail}
|
||||
alt={`${user.first_name} Image`}
|
||||
/>
|
||||
<Row className="-my-2">
|
||||
{user.image_thumbnail ? (
|
||||
<Img
|
||||
circle
|
||||
size={ICON_SIZE}
|
||||
src={user.image_thumbnail}
|
||||
alt={`${user.first_name} Image`}
|
||||
/>
|
||||
) : (
|
||||
<div
|
||||
className={twMerge(
|
||||
`bg-slate-100 dark:bg-white/10 rounded-full w-[35px] h-[35px]`,
|
||||
``,
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
<Span>{user.first_name}</Span>
|
||||
<LucideIcon name="ChevronDown" size={17} />
|
||||
</Row>
|
||||
}
|
||||
position="bottom-right"
|
||||
>
|
||||
<LinkList />
|
||||
<Paper className="mt-3 min-w-[200px]">
|
||||
<LinkList
|
||||
links={[
|
||||
{
|
||||
title: `Dashboard`,
|
||||
url: `/admin`,
|
||||
},
|
||||
{
|
||||
title: `Settings`,
|
||||
url: `/admin/settings`,
|
||||
},
|
||||
{
|
||||
component: <Divider />,
|
||||
},
|
||||
{
|
||||
title: `Logout`,
|
||||
url: `/auth/logout`,
|
||||
},
|
||||
]}
|
||||
className="flex-col items-stretch w-full"
|
||||
/>
|
||||
</Paper>
|
||||
</Dropdown>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import Logo from "@/src/components/general/logo";
|
||||
import Row from "@/twui/components/layout/Row";
|
||||
import { PropsWithChildren } from "react";
|
||||
import HeaderUser from "./(partials)/header-user";
|
||||
|
||||
type Props = PropsWithChildren & {};
|
||||
|
||||
@@ -15,7 +16,11 @@ export default function Header({ children }: Props) {
|
||||
{/* <Divider vertical className="-mr-[7px]" /> */}
|
||||
</Row>
|
||||
<Row className="grid-cell col-span-4 hidden xl:block"></Row>
|
||||
<Row className="grid-cell col-span-3 xl:col-span-1"></Row>
|
||||
<Row className="grid-cell col-span-3 xl:col-span-1">
|
||||
<Row className="p-4 w-full justify-end">
|
||||
<HeaderUser />
|
||||
</Row>
|
||||
</Row>
|
||||
</Row>
|
||||
</header>
|
||||
);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import Main from "@/src/components/pages/admin/users";
|
||||
import { NSQLITE_TURBOCI_ADMIN_USERS } from "@/src/db/types";
|
||||
import defaultAdminProps from "@/src/functions/pages/admin/default-admin-props";
|
||||
import Layout from "@/src/layouts/admin";
|
||||
import NSQLite from "@moduletrace/nsqlite";
|
||||
import { GetServerSideProps } from "next";
|
||||
|
||||
export default function AdminDashboard() {
|
||||
@@ -19,7 +21,15 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||
return `/admin`;
|
||||
}
|
||||
|
||||
return {};
|
||||
const users_res = await NSQLite.select<NSQLITE_TURBOCI_ADMIN_USERS>(
|
||||
{
|
||||
table: "users",
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
deployment_users: users_res.payload,
|
||||
};
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { NSQLITE_TEST_DB_USERS, NSQLiteTables } from "@/src/db/types";
|
||||
import { NSQLITE_TURBOCI_ADMIN_USERS, NSQLiteTables } from "@/src/db/types";
|
||||
import { APIReqObject } from "@/src/types";
|
||||
import loginUser from "@/src/functions/auth/login-user";
|
||||
import hashPassword from "@moduletrace/datasquirel/dist/package-shared/functions/dsql/hashPassword";
|
||||
@@ -29,7 +29,7 @@ export default async function handler(
|
||||
}
|
||||
|
||||
const existing_users_res = await NSQLite.select<
|
||||
NSQLITE_TEST_DB_USERS,
|
||||
NSQLITE_TURBOCI_ADMIN_USERS,
|
||||
(typeof NSQLiteTables)[number]
|
||||
>({
|
||||
table: "users",
|
||||
@@ -47,7 +47,7 @@ export default async function handler(
|
||||
const new_user_password = hashPassword({ password });
|
||||
|
||||
const new_user_insert_res = await NSQLite.insert<
|
||||
NSQLITE_TEST_DB_USERS,
|
||||
NSQLITE_TURBOCI_ADMIN_USERS,
|
||||
(typeof NSQLiteTables)[number]
|
||||
>({
|
||||
data: [
|
||||
@@ -71,7 +71,7 @@ export default async function handler(
|
||||
}
|
||||
|
||||
const newly_inserted_user_res = await NSQLite.select<
|
||||
NSQLITE_TEST_DB_USERS,
|
||||
NSQLITE_TURBOCI_ADMIN_USERS,
|
||||
(typeof NSQLiteTables)[number]
|
||||
>({
|
||||
table: "users",
|
||||
|
||||
@@ -16,7 +16,7 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||
|
||||
return {
|
||||
redirect: {
|
||||
destination: `/login`,
|
||||
destination: `/auth/login`,
|
||||
statusCode: 307,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@ import { DATASQUIREL_LoggedInUser } from "@moduletrace/datasquirel/dist/package-
|
||||
import useAppInit from "../hooks/use-app-init";
|
||||
import { ServerWebSocket } from "bun";
|
||||
import { ChildProcess } from "child_process";
|
||||
import { NSQLITE_TURBOCI_ADMIN_USERS } from "../db/types";
|
||||
|
||||
export type User = DATASQUIREL_LoggedInUser & {
|
||||
super_admin?: 0 | 1;
|
||||
@@ -196,6 +197,7 @@ export type PagePropsType = {
|
||||
children_services?: ParsedDeploymentServiceConfig[] | null;
|
||||
ws_url?: string | null;
|
||||
host?: string | null;
|
||||
deployment_users?: NSQLITE_TURBOCI_ADMIN_USERS[] | null;
|
||||
};
|
||||
|
||||
export type APIReqObject = {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { AppData } from "@/src/data/app-data";
|
||||
import { NSQLITE_TEST_DB_USERS_PORTS, NSQLiteTables } from "@/src/db/types";
|
||||
import {
|
||||
NSQLITE_TURBOCI_ADMIN_USERS_PORTS,
|
||||
NSQLiteTables,
|
||||
} from "@/src/db/types";
|
||||
import { User } from "@/src/types";
|
||||
import BunSQLite from "@moduletrace/bun-sqlite";
|
||||
import { execSync, ExecSyncOptions } from "child_process";
|
||||
@@ -11,7 +14,7 @@ type Params = {
|
||||
|
||||
export default async function killAllTtydPorts({ user }: Params) {
|
||||
const user_ports_res = await BunSQLite.select<
|
||||
NSQLITE_TEST_DB_USERS_PORTS,
|
||||
NSQLITE_TURBOCI_ADMIN_USERS_PORTS,
|
||||
(typeof NSQLiteTables)[number]
|
||||
>({
|
||||
table: "users_ports",
|
||||
@@ -28,7 +31,7 @@ export default async function killAllTtydPorts({ user }: Params) {
|
||||
await killPort({ port: user_port.port });
|
||||
|
||||
await BunSQLite.delete<
|
||||
NSQLITE_TEST_DB_USERS_PORTS,
|
||||
NSQLITE_TURBOCI_ADMIN_USERS_PORTS,
|
||||
(typeof NSQLiteTables)[number]
|
||||
>({
|
||||
table: "users_ports",
|
||||
|
||||
Reference in New Issue
Block a user