Compare commits
2 Commits
c755fd0acb
...
08f9fd2fa5
| Author | SHA1 | Date |
|---|---|---|
|
|
08f9fd2fa5 | |
|
|
46075dade5 |
|
|
@ -0,0 +1,6 @@
|
||||||
|
import Verify from "@/components/Verify";
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
|
export default function page() {
|
||||||
|
return <Verify />;
|
||||||
|
}
|
||||||
|
|
@ -20,7 +20,7 @@ export default function RootLayout({
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<html lang="fa" dir="rtl">
|
<html lang="fa" dir="rtl">
|
||||||
<body className="font-[yekan-m] ">
|
<body className="font-[yekan] ">
|
||||||
<Provider>
|
<Provider>
|
||||||
<Navbar />
|
<Navbar />
|
||||||
<NavbarSm />
|
<NavbarSm />
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,10 @@ import { Input } from "@/components/ui/input";
|
||||||
import { toast } from "@/components/ui/use-toast";
|
import { toast } from "@/components/ui/use-toast";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import LoginIcon from "../public/img/login-icon.svg";
|
import LoginIcon from "../public/img/login-icon.svg";
|
||||||
import { useMutation } from "@tanstack/react-query";
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||||
import { loginStaff } from "@/utils/authenticateApi";
|
import { loginStaff } from "@/utils/authenticateApi";
|
||||||
|
import { getCaptcha } from "@/utils/commonApi";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
const FormSchema = z.object({
|
const FormSchema = z.object({
|
||||||
username: z.string().min(2, {
|
username: z.string().min(2, {
|
||||||
|
|
@ -30,10 +32,25 @@ const FormSchema = z.object({
|
||||||
password: z.string().min(4, {
|
password: z.string().min(4, {
|
||||||
message: "Password must be at least 4 characters.",
|
message: "Password must be at least 4 characters.",
|
||||||
}),
|
}),
|
||||||
|
captcha: z.string().min(4, {
|
||||||
|
message: "Password must",
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default function Login() {
|
export default function Login() {
|
||||||
const LoginMutation = useMutation({
|
const router = useRouter();
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: CaptchaData,
|
||||||
|
isLoading,
|
||||||
|
refetch,
|
||||||
|
} = useQuery({
|
||||||
|
queryKey: ["Captcha"],
|
||||||
|
queryFn: () => getCaptcha(),
|
||||||
|
});
|
||||||
|
console.log(CaptchaData);
|
||||||
|
|
||||||
|
const loginMutation = useMutation({
|
||||||
mutationFn: loginStaff,
|
mutationFn: loginStaff,
|
||||||
onSuccess: (res) => {
|
onSuccess: (res) => {
|
||||||
console.log(res);
|
console.log(res);
|
||||||
|
|
@ -45,7 +62,11 @@ export default function Login() {
|
||||||
// router.push("/MainPage");
|
// router.push("/MainPage");
|
||||||
// }
|
// }
|
||||||
},
|
},
|
||||||
onError: (err) => {},
|
onError: (err: any) => {
|
||||||
|
if (err.response.status == 428) {
|
||||||
|
router.push("/Verify");
|
||||||
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const form = useForm<z.infer<typeof FormSchema>>({
|
const form = useForm<z.infer<typeof FormSchema>>({
|
||||||
|
|
@ -65,13 +86,30 @@ export default function Login() {
|
||||||
</pre>
|
</pre>
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
console.log(data);
|
console.log(CaptchaData?.headers["captcha-key"]);
|
||||||
|
const payload = {
|
||||||
|
username: data.username,
|
||||||
|
password: data.password,
|
||||||
|
captcha: {
|
||||||
|
key: CaptchaData?.headers["captcha-key"],
|
||||||
|
value: data.captcha,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
console.log(payload);
|
||||||
|
loginMutation.mutate(payload);
|
||||||
}
|
}
|
||||||
|
// if (data) {
|
||||||
|
// const base64ImageData = btoa(data);
|
||||||
|
// }
|
||||||
|
const srcForImage = CaptchaData
|
||||||
|
? URL.createObjectURL(CaptchaData.data)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
// const base64ImageData = btoa(data.blob());
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="w-full mt-12 sm:w-2/3 md:w-2/4 xl:w-1/3 bg-white rounded-lg dark:border xl:p-0 dark:bg-gray-800 dark:border-gray-700 shadow-[0px_0px_15px_0px_#00000040]
|
className="w-full mt-12 sm:w-2/3 md:w-2/4 xl:w-1/3 bg-white rounded-lg dark:border xl:p-0 dark:bg-gray-800 dark:border-gray-700 shadow-[0px_0px_15px_0px_#00000040]
|
||||||
h-full max-md:p-8 pt-12"
|
h-full max-md:p-8 pt-12 mb-10"
|
||||||
>
|
>
|
||||||
<div className="space-y-3 md:space-y-4 flex flex-col md:py-12 md:px-20 h-full justify-center">
|
<div className="space-y-3 md:space-y-4 flex flex-col md:py-12 md:px-20 h-full justify-center">
|
||||||
<Image alt="icon" src={LoginIcon} className="self-center w-1/3 " />
|
<Image alt="icon" src={LoginIcon} className="self-center w-1/3 " />
|
||||||
|
|
@ -123,7 +161,33 @@ export default function Login() {
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
<div className="flex gap-4 mt-4 items-center">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="captcha"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem className=" flex-1 items-center h-10">
|
||||||
|
{/* <FormLabel className="text-[#7C838A] text-sm font-medium mt-7">
|
||||||
|
رمز عبور
|
||||||
|
</FormLabel> */}
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="کد امنیتی" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
{!isLoading && (
|
||||||
|
<Image
|
||||||
|
alt="icon"
|
||||||
|
src={srcForImage as string}
|
||||||
|
className=" h-12 rounded-md shadow-md flex-1"
|
||||||
|
width={150}
|
||||||
|
height={20}
|
||||||
|
quality={100}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<div className="flex justify-end gap-2 w-full mt-14">
|
<div className="flex justify-end gap-2 w-full mt-14">
|
||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
|
|
|
||||||
|
|
@ -3,22 +3,14 @@ import { CookieValueTypes } from "cookies-next";
|
||||||
|
|
||||||
axios.defaults.baseURL = "https://sootzaniapi.shetabdahi.ir/";
|
axios.defaults.baseURL = "https://sootzaniapi.shetabdahi.ir/";
|
||||||
|
|
||||||
export async function loginStaff({
|
export async function loginStaff(Data: {
|
||||||
token,
|
username: string;
|
||||||
Data,
|
|
||||||
}: {
|
|
||||||
token: CookieValueTypes;
|
|
||||||
Data: {
|
|
||||||
userName: string;
|
|
||||||
password: string;
|
password: string;
|
||||||
captcha: {
|
captcha: {
|
||||||
key: string;
|
key: string;
|
||||||
value: string;
|
value: string;
|
||||||
};
|
};
|
||||||
};
|
|
||||||
}) {
|
}) {
|
||||||
const data = await axios.post("api/Authenticate/LoginStaff", Data, {
|
const data = await axios.post("api/Authenticate/LoginStaff", Data);
|
||||||
headers: { Authorization: `Bearer ${token}` },
|
|
||||||
});
|
|
||||||
return data.data;
|
return data.data;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,32 +3,18 @@ import { CookieValueTypes } from "cookies-next";
|
||||||
|
|
||||||
axios.defaults.baseURL = "https://sootzaniapi.shetabdahi.ir/";
|
axios.defaults.baseURL = "https://sootzaniapi.shetabdahi.ir/";
|
||||||
|
|
||||||
|
|
||||||
// Get Category
|
// Get Category
|
||||||
export async function getCategory({ token }: { token: CookieValueTypes }) {
|
export async function getCategory({ token }: { token: CookieValueTypes }) {
|
||||||
const data = await axios.get(
|
const data = await axios.get("api/Common/Categories", {
|
||||||
"api/Common/Categories",
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
}
|
});
|
||||||
);
|
|
||||||
return data.data;
|
return data.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Get Captcha
|
// Get Captcha
|
||||||
export async function getCaptcha({token}:{token: CookieValueTypes}) {
|
export async function getCaptcha() {
|
||||||
const data = await axios.get(
|
const data = await axios.get("api/Common/Captcha", { responseType: "blob" });
|
||||||
"api/Common/Captcha",
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${token}`
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
console.log(data)
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
Loading…
Reference in New Issue