Compare commits

..

No commits in common. "08f9fd2fa5c8d4fd7e71b318b0637f81e9802e98" and "c755fd0acb177d657a89f98650c858fd66b55830" have entirely different histories.

5 changed files with 52 additions and 100 deletions

View File

@ -1,6 +0,0 @@
import Verify from "@/components/Verify";
import React from "react";
export default function page() {
return <Verify />;
}

View File

@ -20,7 +20,7 @@ export default function RootLayout({
}) {
return (
<html lang="fa" dir="rtl">
<body className="font-[yekan] ">
<body className="font-[yekan-m] ">
<Provider>
<Navbar />
<NavbarSm />

View File

@ -20,10 +20,8 @@ import { Input } from "@/components/ui/input";
import { toast } from "@/components/ui/use-toast";
import Image from "next/image";
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 { getCaptcha } from "@/utils/commonApi";
import { useRouter } from "next/navigation";
const FormSchema = z.object({
username: z.string().min(2, {
@ -32,25 +30,10 @@ const FormSchema = z.object({
password: z.string().min(4, {
message: "Password must be at least 4 characters.",
}),
captcha: z.string().min(4, {
message: "Password must",
}),
});
export default function Login() {
const router = useRouter();
const {
data: CaptchaData,
isLoading,
refetch,
} = useQuery({
queryKey: ["Captcha"],
queryFn: () => getCaptcha(),
});
console.log(CaptchaData);
const loginMutation = useMutation({
const LoginMutation = useMutation({
mutationFn: loginStaff,
onSuccess: (res) => {
console.log(res);
@ -62,11 +45,7 @@ export default function Login() {
// router.push("/MainPage");
// }
},
onError: (err: any) => {
if (err.response.status == 428) {
router.push("/Verify");
}
},
onError: (err) => {},
});
const form = useForm<z.infer<typeof FormSchema>>({
@ -86,30 +65,13 @@ export default function Login() {
</pre>
),
});
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);
console.log(data);
}
// if (data) {
// const base64ImageData = btoa(data);
// }
const srcForImage = CaptchaData
? URL.createObjectURL(CaptchaData.data)
: null;
// const base64ImageData = btoa(data.blob());
return (
<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]
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">
<Image alt="icon" src={LoginIcon} className="self-center w-1/3 " />
@ -161,33 +123,7 @@ export default function Login() {
</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">
<Button
type="submit"

View File

@ -3,14 +3,22 @@ import { CookieValueTypes } from "cookies-next";
axios.defaults.baseURL = "https://sootzaniapi.shetabdahi.ir/";
export async function loginStaff(Data: {
username: string;
export async function loginStaff({
token,
Data,
}: {
token: CookieValueTypes;
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;
}

View File

@ -3,18 +3,32 @@ import { CookieValueTypes } from "cookies-next";
axios.defaults.baseURL = "https://sootzaniapi.shetabdahi.ir/";
// Get Category
export async function getCategory({token}:{token: CookieValueTypes}) {
const data = await axios.get("api/Common/Categories", {
const data = await axios.get(
"api/Common/Categories",
{
headers: {
Authorization: `Bearer ${token}`,
Authorization: `Bearer ${token}`
},
});
}
);
return data.data;
}
// Get Captcha
export async function getCaptcha() {
const data = await axios.get("api/Common/Captcha", { responseType: "blob" });
export async function getCaptcha({token}:{token: CookieValueTypes}) {
const data = await axios.get(
"api/Common/Captcha",
{
headers: {
Authorization: `Bearer ${token}`
},
}
);
console.log(data)
return data;
}