Compare commits
6 Commits
0ddf67d815
...
c6f766089b
| Author | SHA1 | Date | |
|---|---|---|---|
| c6f766089b | |||
| 6c27fa10a6 | |||
| 8198c7a478 | |||
| 45dda3c40a | |||
| 56d21fec84 | |||
| 721813dc29 |
@@ -1,5 +1,5 @@
|
|||||||
vars {
|
vars {
|
||||||
url: http://localhost:4200
|
url: https://usiow2prod.alpla.net
|
||||||
session_cookie:
|
session_cookie:
|
||||||
urlv2: http://localhost:3000
|
urlv2: http://localhost:3000
|
||||||
jwtV2:
|
jwtV2:
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { auth } from "../../../../pkg/auth/auth.js";
|
|||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.patch("/:userId", async (req: Request, res: Response) => {
|
router.get("/:userId", async (req: Request, res: Response) => {
|
||||||
const userId = req.params.userId;
|
const userId = req.params.userId;
|
||||||
const cookieHeader = req.headers.cookie ?? "";
|
const cookieHeader = req.headers.cookie ?? "";
|
||||||
const authorization = req.headers.authorization ?? "";
|
const authorization = req.headers.authorization ?? "";
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Link } from "@tanstack/react-router";
|
import { Link, useRouterState } from "@tanstack/react-router";
|
||||||
import { useAuth, useLogout } from "../../lib/authClient";
|
import { useAuth, useLogout } from "../../lib/authClient";
|
||||||
import { ModeToggle } from "../mode-toggle";
|
import { ModeToggle } from "../mode-toggle";
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar";
|
import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar";
|
||||||
@@ -15,6 +15,8 @@ import {
|
|||||||
export default function Nav() {
|
export default function Nav() {
|
||||||
const { session } = useAuth();
|
const { session } = useAuth();
|
||||||
const logout = useLogout();
|
const logout = useLogout();
|
||||||
|
const router = useRouterState();
|
||||||
|
const currentPath = router.location.href;
|
||||||
return (
|
return (
|
||||||
<nav className="flex justify-end w-full shadow ">
|
<nav className="flex justify-end w-full shadow ">
|
||||||
<div className="m-2 flex flex-row gap-1">
|
<div className="m-2 flex flex-row gap-1">
|
||||||
@@ -67,7 +69,9 @@ export default function Nav() {
|
|||||||
) : (
|
) : (
|
||||||
<div className="m-1">
|
<div className="m-1">
|
||||||
<Button>
|
<Button>
|
||||||
<Link to="/login">Login</Link>
|
<Link to="/login" search={{ redirect: currentPath }}>
|
||||||
|
Login
|
||||||
|
</Link>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
145
frontend/src/routes/_app/(auth)/-components/ChangePassword.tsx
Normal file
145
frontend/src/routes/_app/(auth)/-components/ChangePassword.tsx
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
import { useRouter } from "@tanstack/react-router";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
import {
|
||||||
|
CardContent,
|
||||||
|
CardDescription,
|
||||||
|
CardHeader,
|
||||||
|
CardTitle,
|
||||||
|
} from "@/components/ui/card";
|
||||||
|
import { LstCard } from "@/components/ui/lstCard";
|
||||||
|
import { authClient, useLogout } from "@/lib/authClient";
|
||||||
|
import { useAppForm } from "@/lib/formStuff";
|
||||||
|
|
||||||
|
export default function ChangePassword() {
|
||||||
|
//const navigate = useNavigate();
|
||||||
|
const logout = useLogout();
|
||||||
|
const router = useRouter();
|
||||||
|
const form = useAppForm({
|
||||||
|
defaultValues: {
|
||||||
|
newPassword: "",
|
||||||
|
confirmPassword: "",
|
||||||
|
currentPassword: "",
|
||||||
|
},
|
||||||
|
onSubmit: async ({ value }) => {
|
||||||
|
if (value.newPassword != value.confirmPassword) {
|
||||||
|
toast.error("Passwords do not match");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const { data, error } = await authClient.changePassword({
|
||||||
|
newPassword: value.newPassword, // required
|
||||||
|
currentPassword: value.currentPassword, // required
|
||||||
|
revokeOtherSessions: true,
|
||||||
|
});
|
||||||
|
console.log("Data", data);
|
||||||
|
console.log("Error", error);
|
||||||
|
if (data) {
|
||||||
|
toast.success("Password has been updated");
|
||||||
|
form.reset();
|
||||||
|
router.invalidate();
|
||||||
|
logout();
|
||||||
|
//navigate({ to: "/login" });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
toast.success(error.message);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
// @ts-ignore
|
||||||
|
toast.error(error?.response.data.message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="">
|
||||||
|
<LstCard className="p-6 w-96">
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Set a new password</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
After Entering your new password you will need to sign in again.
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
|
||||||
|
<CardContent>
|
||||||
|
<form
|
||||||
|
onSubmit={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
form.handleSubmit();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<form.AppField
|
||||||
|
name="currentPassword"
|
||||||
|
children={(field) => (
|
||||||
|
<field.InputPasswordField
|
||||||
|
label="Enter your current password"
|
||||||
|
required={true}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<form.AppField
|
||||||
|
name="newPassword"
|
||||||
|
// validators={{
|
||||||
|
// onChangeListenTo: ["password"],
|
||||||
|
// onChange: ({ value, fieldApi }) => {
|
||||||
|
// if (
|
||||||
|
// value !==
|
||||||
|
// fieldApi.form.getFieldValue("password")
|
||||||
|
// ) {
|
||||||
|
// return "Passwords do not match";
|
||||||
|
// }
|
||||||
|
// return undefined;
|
||||||
|
// },
|
||||||
|
// }}
|
||||||
|
children={(field) => (
|
||||||
|
<field.InputPasswordField
|
||||||
|
label="New password"
|
||||||
|
required={true}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<form.AppField
|
||||||
|
name="confirmPassword"
|
||||||
|
// validators={{
|
||||||
|
// onChangeListenTo: ["password"],
|
||||||
|
// onChange: ({ value, fieldApi }) => {
|
||||||
|
// if (
|
||||||
|
// value !==
|
||||||
|
// fieldApi.form.getFieldValue("password")
|
||||||
|
// ) {
|
||||||
|
// return "Passwords do not match";
|
||||||
|
// }
|
||||||
|
// return undefined;
|
||||||
|
// },
|
||||||
|
// }}
|
||||||
|
children={(field) => (
|
||||||
|
<field.InputPasswordField
|
||||||
|
label="Re-enter your password"
|
||||||
|
required={true}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="flex justify-end mt-6">
|
||||||
|
<form.AppForm>
|
||||||
|
<form.SubmitButton>Reset Password</form.SubmitButton>
|
||||||
|
</form.AppForm>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{/* <div className="mt-6 text-center text-sm text-gray-600">
|
||||||
|
Remembered your account?{" "}
|
||||||
|
<Link
|
||||||
|
to="/login"
|
||||||
|
className="text-primary underline underline-offset-4 hover:text-primary/80"
|
||||||
|
>
|
||||||
|
Back to login
|
||||||
|
</Link>
|
||||||
|
</div> */}
|
||||||
|
</CardContent>
|
||||||
|
</LstCard>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Link, useRouter, useSearch } from "@tanstack/react-router";
|
import { Link, useNavigate } from "@tanstack/react-router";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import {
|
import {
|
||||||
@@ -11,13 +11,13 @@ import { LstCard } from "../../../../components/ui/lstCard";
|
|||||||
import { getSession, useAuth, useUserRoles } from "../../../../lib/authClient";
|
import { getSession, useAuth, useUserRoles } from "../../../../lib/authClient";
|
||||||
import { useAppForm } from "../../../../lib/formStuff";
|
import { useAppForm } from "../../../../lib/formStuff";
|
||||||
|
|
||||||
export default function LoginForm() {
|
export default function LoginForm({ redirectPath }: { redirectPath: string }) {
|
||||||
const router = useRouter();
|
//const search = useSearch({ from: "/_app/(auth)/login" });
|
||||||
const search = useSearch({ from: "/_app/(auth)/login" });
|
|
||||||
const username = localStorage.getItem("username") || "";
|
const username = localStorage.getItem("username") || "";
|
||||||
const rememberMe = localStorage.getItem("rememberMe") === "true";
|
const rememberMe = localStorage.getItem("rememberMe") === "true";
|
||||||
const { setSession } = useAuth();
|
const { setSession } = useAuth();
|
||||||
const { fetchRoles } = useUserRoles();
|
const { fetchRoles } = useUserRoles();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const form = useAppForm({
|
const form = useAppForm({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
@@ -48,8 +48,12 @@ export default function LoginForm() {
|
|||||||
toast.success(
|
toast.success(
|
||||||
`Welcome back ${session?.user.name ? session?.user.name : session?.user.username} `,
|
`Welcome back ${session?.user.name ? session?.user.name : session?.user.username} `,
|
||||||
);
|
);
|
||||||
router.invalidate();
|
//router.invalidate();
|
||||||
router.history.push(search.redirect ? search.redirect : "/");
|
if (redirectPath.includes("profile")) {
|
||||||
|
navigate({ to: "/" });
|
||||||
|
} else {
|
||||||
|
navigate({ to: redirectPath });
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (!error.response.data.success) {
|
if (!error.response.data.success) {
|
||||||
|
|||||||
@@ -22,9 +22,11 @@ export const Route = createFileRoute("/_app/(auth)/login")({
|
|||||||
});
|
});
|
||||||
|
|
||||||
function RouteComponent() {
|
function RouteComponent() {
|
||||||
|
const search = Route.useSearch();
|
||||||
|
const redirectPath = search.redirect ?? "/";
|
||||||
return (
|
return (
|
||||||
<div className="ml-[25%] mt-[0.5%]">
|
<div className="ml-[25%] mt-[0.5%]">
|
||||||
<LoginForm />
|
<LoginForm redirectPath={redirectPath} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { createFileRoute, redirect } from "@tanstack/react-router";
|
import { createFileRoute, redirect } from "@tanstack/react-router";
|
||||||
import { authClient, useAuth } from "../../../../lib/authClient";
|
import { authClient } from "../../../../lib/authClient";
|
||||||
|
import ChangePassword from "../-components/ChangePassword";
|
||||||
|
|
||||||
export const Route = createFileRoute("/_app/(auth)/user/profile")({
|
export const Route = createFileRoute("/_app/(auth)/user/profile")({
|
||||||
beforeLoad: async () => {
|
beforeLoad: async () => {
|
||||||
@@ -22,19 +23,20 @@ export const Route = createFileRoute("/_app/(auth)/user/profile")({
|
|||||||
});
|
});
|
||||||
|
|
||||||
function RouteComponent() {
|
function RouteComponent() {
|
||||||
const { session } = useAuth();
|
//const { session } = useAuth();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="m-2">
|
<div className="m-2">
|
||||||
<div>
|
<div>
|
||||||
<span>Things you can change</span>
|
{/* <span>Things you can change</span>
|
||||||
<ol>
|
<ol>
|
||||||
<li>Display name: {session?.user.displayUsername}</li>
|
<li>Display name: {session?.user.displayUsername}</li>
|
||||||
<li>Name: {session?.user.name}</li>
|
<li>Name: {session?.user.name}</li>
|
||||||
<li>Image: To be added</li>
|
<li>Image: To be added</li>
|
||||||
<li>password: **************</li>
|
<li></li>
|
||||||
</ol>
|
</ol> */}
|
||||||
</div>
|
</div>
|
||||||
|
<ChangePassword />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { createFileRoute } from "@tanstack/react-router";
|
import { createFileRoute, Link } from "@tanstack/react-router";
|
||||||
|
|
||||||
|
|
||||||
export const Route = createFileRoute("/_app/")({
|
export const Route = createFileRoute("/_app/")({
|
||||||
component: Index,
|
component: Index,
|
||||||
@@ -9,8 +8,17 @@ function Index() {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="h-screen flex flex-col items-center justify-center">
|
<div className="h-screen flex flex-col items-center justify-center">
|
||||||
|
<div className="m-2">
|
||||||
|
<p>
|
||||||
|
As we transtion to the new version and need to utilize both site
|
||||||
|
click{" "}
|
||||||
|
<Link to={"/old"} className="underline">
|
||||||
|
Old version
|
||||||
|
</Link>{" "}
|
||||||
|
to get to everything you are familiar with
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export const Route = createFileRoute("/_old/old/(logistics)/dm/")({
|
|||||||
beforeLoad: async () => {
|
beforeLoad: async () => {
|
||||||
const auth = await checkUserAccess({
|
const auth = await checkUserAccess({
|
||||||
allowedRoles: ["systemAdmin", "technician", "admin", "manager"],
|
allowedRoles: ["systemAdmin", "technician", "admin", "manager"],
|
||||||
moduleName: "siloAdjustments", // optional
|
moduleName: "demandManagement", // optional
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!auth) {
|
if (!auth) {
|
||||||
|
|||||||
@@ -41,11 +41,7 @@ export function LogisticsSideBar({
|
|||||||
const Icon = iconMap[item.icon];
|
const Icon = iconMap[item.icon];
|
||||||
return (
|
return (
|
||||||
<SidebarMenuItem key={item.submodule_id}>
|
<SidebarMenuItem key={item.submodule_id}>
|
||||||
{hasPageAccess(
|
{hasPageAccess(userUpdate as any, item.roles, item.name) && (
|
||||||
userUpdate as any,
|
|
||||||
item.roles,
|
|
||||||
item.moduleName,
|
|
||||||
) && (
|
|
||||||
<>
|
<>
|
||||||
<SidebarMenuButton asChild>
|
<SidebarMenuButton asChild>
|
||||||
<a href={item?.link}>
|
<a href={item?.link}>
|
||||||
|
|||||||
@@ -105,7 +105,8 @@ export default function SiloCard(data: any) {
|
|||||||
stock.
|
stock.
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
-Silo virtualy ran empty due to production over consumption.
|
-Silo virtually ran empty due to production over
|
||||||
|
consumption.
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
-Someone forgot to move a railcar compartment over to this
|
-Someone forgot to move a railcar compartment over to this
|
||||||
@@ -116,7 +117,7 @@ export default function SiloCard(data: any) {
|
|||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
{session?.user &&
|
{session?.user &&
|
||||||
userAccess("logistics", [
|
userAccess("siloAdjustments", [
|
||||||
"supervisor",
|
"supervisor",
|
||||||
"manager",
|
"manager",
|
||||||
"admin",
|
"admin",
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
import { createFileRoute, Link, Outlet } from "@tanstack/react-router";
|
import {
|
||||||
|
createFileRoute,
|
||||||
|
Link,
|
||||||
|
Outlet,
|
||||||
|
useRouterState,
|
||||||
|
} from "@tanstack/react-router";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { ModeToggle } from "../../../components/mode-toggle";
|
import { ModeToggle } from "../../../components/mode-toggle";
|
||||||
@@ -30,6 +35,8 @@ function RouteComponent() {
|
|||||||
const sidebarState = Cookies.get("sidebar_state") === "true";
|
const sidebarState = Cookies.get("sidebar_state") === "true";
|
||||||
const { session } = useAuth();
|
const { session } = useAuth();
|
||||||
const logout = useLogout();
|
const logout = useLogout();
|
||||||
|
const router = useRouterState();
|
||||||
|
const currentPath = router.location.href;
|
||||||
//const { settings } = useSettingStore();
|
//const { settings } = useSettingStore();
|
||||||
//console.log(location.pathname);
|
//console.log(location.pathname);
|
||||||
return (
|
return (
|
||||||
@@ -86,7 +93,9 @@ function RouteComponent() {
|
|||||||
<DropdownMenuItem>
|
<DropdownMenuItem>
|
||||||
{/* <Link to="/passwordChange">Password Change</Link> */}
|
{/* <Link to="/passwordChange">Password Change</Link> */}
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem>
|
||||||
|
<Link to="/user/profile">Profile</Link>
|
||||||
|
</DropdownMenuItem>
|
||||||
{/* <DropdownMenuItem>Billing</DropdownMenuItem>
|
{/* <DropdownMenuItem>Billing</DropdownMenuItem>
|
||||||
<DropdownMenuItem>Team</DropdownMenuItem>
|
<DropdownMenuItem>Team</DropdownMenuItem>
|
||||||
<DropdownMenuItem>Subscription</DropdownMenuItem> */}
|
<DropdownMenuItem>Subscription</DropdownMenuItem> */}
|
||||||
@@ -101,7 +110,9 @@ function RouteComponent() {
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<Button className="m-1">
|
<Button className="m-1">
|
||||||
<Link to="/login">Login</Link>
|
<Link to="/login" search={{ redirect: currentPath }}>
|
||||||
|
Login
|
||||||
|
</Link>
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user