Compare commits
No commits in common. "08f9fd2fa5c8d4fd7e71b318b0637f81e9802e98" and "c755fd0acb177d657a89f98650c858fd66b55830" have entirely different histories.
08f9fd2fa5
...
c755fd0acb
|
|
@ -1,6 +0,0 @@
|
||||||
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] ">
|
<body className="font-[yekan-m] ">
|
||||||
<Provider>
|
<Provider>
|
||||||
<Navbar />
|
<Navbar />
|
||||||
<NavbarSm />
|
<NavbarSm />
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,8 @@ 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, useQuery } from "@tanstack/react-query";
|
import { useMutation } 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, {
|
||||||
|
|
@ -32,25 +30,10 @@ 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 router = useRouter();
|
const LoginMutation = useMutation({
|
||||||
|
|
||||||
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);
|
||||||
|
|
@ -62,11 +45,7 @@ export default function Login() {
|
||||||
// router.push("/MainPage");
|
// router.push("/MainPage");
|
||||||
// }
|
// }
|
||||||
},
|
},
|
||||||
onError: (err: any) => {
|
onError: (err) => {},
|
||||||
if (err.response.status == 428) {
|
|
||||||
router.push("/Verify");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const form = useForm<z.infer<typeof FormSchema>>({
|
const form = useForm<z.infer<typeof FormSchema>>({
|
||||||
|
|
@ -86,30 +65,13 @@ export default function Login() {
|
||||||
</pre>
|
</pre>
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
console.log(CaptchaData?.headers["captcha-key"]);
|
console.log(data);
|
||||||
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 mb-10"
|
h-full max-md:p-8 pt-12"
|
||||||
>
|
>
|
||||||
<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 " />
|
||||||
|
|
@ -161,33 +123,7 @@ 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,14 +3,22 @@ import { CookieValueTypes } from "cookies-next";
|
||||||
|
|
||||||
axios.defaults.baseURL = "https://sootzaniapi.shetabdahi.ir/";
|
axios.defaults.baseURL = "https://sootzaniapi.shetabdahi.ir/";
|
||||||
|
|
||||||
export async function loginStaff(Data: {
|
export async function loginStaff({
|
||||||
username: string;
|
token,
|
||||||
password: string;
|
Data,
|
||||||
captcha: {
|
}: {
|
||||||
key: string;
|
token: CookieValueTypes;
|
||||||
value: string;
|
Data: {
|
||||||
|
userName: string;
|
||||||
|
password: string;
|
||||||
|
captcha: {
|
||||||
|
key: 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,18 +3,32 @@ import { CookieValueTypes } from "cookies-next";
|
||||||
|
|
||||||
axios.defaults.baseURL = "https://sootzaniapi.shetabdahi.ir/";
|
axios.defaults.baseURL = "https://sootzaniapi.shetabdahi.ir/";
|
||||||
|
|
||||||
// Get Category
|
|
||||||
export async function getCategory({ token }: { token: CookieValueTypes }) {
|
|
||||||
const data = await axios.get("api/Common/Categories", {
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return data.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get Captcha
|
// Get Category
|
||||||
export async function getCaptcha() {
|
export async function getCategory({token}:{token: CookieValueTypes}) {
|
||||||
const data = await axios.get("api/Common/Captcha", { responseType: "blob" });
|
const data = await axios.get(
|
||||||
return data;
|
"api/Common/Categories",
|
||||||
}
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return data.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Get Captcha
|
||||||
|
export async function getCaptcha({token}:{token: CookieValueTypes}) {
|
||||||
|
const data = await axios.get(
|
||||||
|
"api/Common/Captcha",
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
console.log(data)
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in New Issue