disable otp
This commit is contained in:
parent
3d2bb07b00
commit
831acbb5da
|
|
@ -40,7 +40,6 @@ export default function SpeechToText(props: {
|
||||||
}) {
|
}) {
|
||||||
const searchParam = useSearchParams();
|
const searchParam = useSearchParams();
|
||||||
const transcriptQuery = searchParam.get("transcriptId");
|
const transcriptQuery = searchParam.get("transcriptId");
|
||||||
const roleId = Cookies.get("urie");
|
|
||||||
|
|
||||||
let [files, setFiles] = useState<File[]>([]);
|
let [files, setFiles] = useState<File[]>([]);
|
||||||
const [handleFileStatus, setHandleFileStatus] = useState("");
|
const [handleFileStatus, setHandleFileStatus] = useState("");
|
||||||
|
|
|
||||||
|
|
@ -19,18 +19,26 @@ import withReactContent from "sweetalert2-react-content";
|
||||||
import { saveActivity } from "@/service/activity-log";
|
import { saveActivity } from "@/service/activity-log";
|
||||||
import { Image } from "@heroui/react";
|
import { Image } from "@heroui/react";
|
||||||
import { InputOtp } from "@heroui/input-otp";
|
import { InputOtp } from "@heroui/input-otp";
|
||||||
|
import PasswordChecklist from "react-password-checklist";
|
||||||
|
|
||||||
export default function Login() {
|
export default function Login() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [isVisible, setIsVisible] = React.useState(false);
|
const [isVisible, setIsVisible] = useState(false);
|
||||||
|
const [isVisibleSetup, setIsVisibleSetup] = useState([false, false]);
|
||||||
|
const [emailSetup, setEmailSetup] = useState("");
|
||||||
|
const [passwordSetup, setPasswordSetup] = useState("");
|
||||||
|
const [confPasswordSetup, setConfPasswordSetup] = useState("");
|
||||||
|
|
||||||
const toggleVisibility = () => setIsVisible(!isVisible);
|
const toggleVisibility = () => setIsVisible(!isVisible);
|
||||||
const [needOtp, setNeedOtp] = useState(false);
|
const [needOtp, setNeedOtp] = useState(false);
|
||||||
|
const [isFirstLogin, setFirstLogin] = useState(false);
|
||||||
const [otpValue, setOtpValue] = useState("");
|
const [otpValue, setOtpValue] = useState("");
|
||||||
const [username, setUsername] = useState("");
|
const [username, setUsername] = useState("");
|
||||||
const [password, setPassword] = useState("");
|
const [password, setPassword] = useState("");
|
||||||
const [accessData, setAccessData] = useState<any>();
|
const [accessData, setAccessData] = useState<any>();
|
||||||
const [profile, setProfile] = useState<any>();
|
const [profile, setProfile] = useState<any>();
|
||||||
|
const [isValidPassword, setIsValidPassword] = useState(false);
|
||||||
|
|
||||||
const onSubmit = async () => {
|
const onSubmit = async () => {
|
||||||
const data = {
|
const data = {
|
||||||
username: username,
|
username: username,
|
||||||
|
|
@ -46,16 +54,84 @@ export default function Login() {
|
||||||
error("Username / Password Tidak Sesuai");
|
error("Username / Password Tidak Sesuai");
|
||||||
} else {
|
} else {
|
||||||
setAccessData(response?.data?.data);
|
setAccessData(response?.data?.data);
|
||||||
const access_token: any = response?.data?.data?.access_token;
|
const profile = await getProfile(response?.data?.data?.access_token);
|
||||||
const refresh_token: any = response?.data?.data?.refresh_token;
|
console.log("PROFILE : ", profile?.data?.data);
|
||||||
const profile = await getProfile(access_token);
|
// setEmailSetup(profile?.data?.data?.email);
|
||||||
console.log("PROFILE : ", profile?.data?.data?.email);
|
// setProfile(profile?.data?.data);
|
||||||
setProfile(profile?.data?.data);
|
// setFirstLogin(true);
|
||||||
const res = await otpRequest(
|
|
||||||
profile?.data?.data?.email,
|
// if (profile?.data?.data?.isFirstLogin) {
|
||||||
profile?.data?.data?.fullname
|
// setFirstLogin(true);
|
||||||
|
// } else {
|
||||||
|
// const res = await otpRequest(
|
||||||
|
// profile?.data?.data?.email,
|
||||||
|
// profile?.data?.data?.fullname
|
||||||
|
// );
|
||||||
|
// setNeedOtp(true);
|
||||||
|
// }
|
||||||
|
|
||||||
|
const dateTime: any = new Date();
|
||||||
|
|
||||||
|
const newTime: any = dateTime.getTime() + 10 * 60 * 1000;
|
||||||
|
|
||||||
|
Cookies.set("access_token", response?.data?.data?.access_token, {
|
||||||
|
expires: 1,
|
||||||
|
});
|
||||||
|
Cookies.set("refresh_token", response?.data?.data?.refresh_token, {
|
||||||
|
expires: 1,
|
||||||
|
});
|
||||||
|
Cookies.set("time_refresh", newTime, {
|
||||||
|
expires: 1,
|
||||||
|
});
|
||||||
|
Cookies.set("is_first_login", "true", {
|
||||||
|
secure: true,
|
||||||
|
sameSite: "strict",
|
||||||
|
});
|
||||||
|
const resActivity = await saveActivity(
|
||||||
|
{
|
||||||
|
activityTypeId: 1,
|
||||||
|
url: "https://kontenhumas.com/auth",
|
||||||
|
userId: profile?.data?.data?.id,
|
||||||
|
},
|
||||||
|
accessData?.id_token
|
||||||
);
|
);
|
||||||
setNeedOtp(true);
|
Cookies.set("profile_picture", profile?.data?.data?.profilePictureUrl, {
|
||||||
|
expires: 1,
|
||||||
|
});
|
||||||
|
Cookies.set("uie", profile?.data?.data?.id, {
|
||||||
|
expires: 1,
|
||||||
|
});
|
||||||
|
Cookies.set("ufne", profile?.data?.data?.fullname, {
|
||||||
|
expires: 1,
|
||||||
|
});
|
||||||
|
Cookies.set("ulie", profile?.data?.data?.userLevelGroup, {
|
||||||
|
expires: 1,
|
||||||
|
});
|
||||||
|
Cookies.set("username", profile?.data?.data?.username, {
|
||||||
|
expires: 1,
|
||||||
|
});
|
||||||
|
Cookies.set("urie", profile?.data?.data?.roleId, {
|
||||||
|
expires: 1,
|
||||||
|
});
|
||||||
|
Cookies.set("roleName", profile?.data?.data?.roleName, {
|
||||||
|
expires: 1,
|
||||||
|
});
|
||||||
|
Cookies.set("masterPoldaId", profile?.data?.data?.masterPoldaId, {
|
||||||
|
expires: 1,
|
||||||
|
});
|
||||||
|
Cookies.set("ulne", profile?.data?.data?.userLevelId, {
|
||||||
|
expires: 1,
|
||||||
|
});
|
||||||
|
Cookies.set("urce", profile?.data?.data?.roleCode, {
|
||||||
|
expires: 1,
|
||||||
|
});
|
||||||
|
Cookies.set("email", profile?.data?.data?.email, {
|
||||||
|
expires: 1,
|
||||||
|
});
|
||||||
|
router.push("/admin/dashboard");
|
||||||
|
Cookies.set("status", "login", {
|
||||||
|
expires: 1,
|
||||||
|
});
|
||||||
|
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
@ -175,6 +251,40 @@ export default function Login() {
|
||||||
close();
|
close();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const generatePassword = () => {
|
||||||
|
const length = Math.floor(Math.random() * 9) + 8;
|
||||||
|
|
||||||
|
const upperCaseChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
const lowerCaseChars = "abcdefghijklmnopqrstuvwxyz";
|
||||||
|
const numberChars = "0123456789";
|
||||||
|
const specialChars = "!@#$%^&*";
|
||||||
|
const allChars =
|
||||||
|
upperCaseChars + lowerCaseChars + numberChars + specialChars;
|
||||||
|
|
||||||
|
let generatedPassword = "";
|
||||||
|
|
||||||
|
generatedPassword +=
|
||||||
|
upperCaseChars[Math.floor(Math.random() * upperCaseChars.length)];
|
||||||
|
generatedPassword +=
|
||||||
|
specialChars[Math.floor(Math.random() * specialChars.length)];
|
||||||
|
generatedPassword +=
|
||||||
|
numberChars[Math.floor(Math.random() * numberChars.length)];
|
||||||
|
generatedPassword +=
|
||||||
|
lowerCaseChars[Math.floor(Math.random() * lowerCaseChars.length)];
|
||||||
|
|
||||||
|
for (let i = generatedPassword.length; i < length; i++) {
|
||||||
|
generatedPassword +=
|
||||||
|
allChars[Math.floor(Math.random() * allChars.length)];
|
||||||
|
}
|
||||||
|
|
||||||
|
generatedPassword = generatedPassword
|
||||||
|
.split("")
|
||||||
|
.sort(() => 0.5 - Math.random())
|
||||||
|
.join("");
|
||||||
|
|
||||||
|
setPasswordSetup(generatedPassword);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-row h-full">
|
<div className="flex flex-row h-full">
|
||||||
<div
|
<div
|
||||||
|
|
@ -201,7 +311,106 @@ export default function Login() {
|
||||||
/>
|
/>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
{needOtp ? (
|
{isFirstLogin ? (
|
||||||
|
<div className="bg-[#1F1A17] w-full md:w-2/5 p-8 md:px-24 justify-center flex flex-col">
|
||||||
|
<p className="text-[72px] text-[#DD8306] font-semibold mb-10">
|
||||||
|
Setting Account
|
||||||
|
</p>
|
||||||
|
<p className="my-2 text-white">Email</p>
|
||||||
|
<Input
|
||||||
|
isRequired
|
||||||
|
type="email"
|
||||||
|
label=""
|
||||||
|
placeholder=""
|
||||||
|
className="my-2"
|
||||||
|
classNames={{ input: "rounded-md", inputWrapper: "rounded-md" }}
|
||||||
|
value={emailSetup}
|
||||||
|
onValueChange={setEmailSetup}
|
||||||
|
/>
|
||||||
|
<p className="my-2 text-white">Password Baru</p>
|
||||||
|
<Input
|
||||||
|
isRequired
|
||||||
|
className="my-2"
|
||||||
|
classNames={{ input: "rounded-md", inputWrapper: "rounded-md" }}
|
||||||
|
endContent={
|
||||||
|
<button
|
||||||
|
className="focus:outline-none"
|
||||||
|
type="button"
|
||||||
|
onClick={() =>
|
||||||
|
setIsVisibleSetup([!isVisibleSetup[0], isVisibleSetup[1]])
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{isVisibleSetup[0] ? (
|
||||||
|
<EyeSlashFilledIcon className="text-2xl text-default-400 pointer-events-none" />
|
||||||
|
) : (
|
||||||
|
<EyeFilledIcon className="text-2xl text-default-400 pointer-events-none" />
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
type={isVisibleSetup[0] ? "text" : "password"}
|
||||||
|
label=""
|
||||||
|
placeholder=""
|
||||||
|
value={passwordSetup}
|
||||||
|
onValueChange={setPasswordSetup}
|
||||||
|
/>
|
||||||
|
<p className="my-2 text-white">Konfirmasi Password Baru</p>
|
||||||
|
<Input
|
||||||
|
isRequired
|
||||||
|
className="my-2"
|
||||||
|
classNames={{ input: "rounded-md", inputWrapper: "rounded-md" }}
|
||||||
|
endContent={
|
||||||
|
<button
|
||||||
|
className="focus:outline-none"
|
||||||
|
type="button"
|
||||||
|
onClick={() =>
|
||||||
|
setIsVisibleSetup([isVisibleSetup[0], !isVisibleSetup[1]])
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{isVisibleSetup[1] ? (
|
||||||
|
<EyeSlashFilledIcon className="text-2xl text-default-400 pointer-events-none" />
|
||||||
|
) : (
|
||||||
|
<EyeFilledIcon className="text-2xl text-default-400 pointer-events-none" />
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
type={isVisibleSetup[1] ? "text" : "password"}
|
||||||
|
label=""
|
||||||
|
placeholder=""
|
||||||
|
value={confPasswordSetup}
|
||||||
|
onValueChange={setConfPasswordSetup}
|
||||||
|
/>
|
||||||
|
<a
|
||||||
|
className="cursor-pointer text-[#DD8306]"
|
||||||
|
onClick={generatePassword}
|
||||||
|
>
|
||||||
|
Generate Password
|
||||||
|
</a>
|
||||||
|
<PasswordChecklist
|
||||||
|
rules={["minLength", "specialChar", "number", "capital", "match"]}
|
||||||
|
minLength={8}
|
||||||
|
value={passwordSetup}
|
||||||
|
valueAgain={confPasswordSetup}
|
||||||
|
onChange={(isValid) => {
|
||||||
|
setIsValidPassword(isValid);
|
||||||
|
}}
|
||||||
|
className="text-white text-sm my-3"
|
||||||
|
messages={{
|
||||||
|
minLength: "Kata sandi harus lebih dari 8 karakter",
|
||||||
|
specialChar: "Kata sandi harus mengandung karakter khusus",
|
||||||
|
number: "Kata sandi harus mengandung angka",
|
||||||
|
capital: "Kata sandi harus mengandung huruf kapital",
|
||||||
|
match: "Kata sandi cocok",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
size="lg"
|
||||||
|
className="w-fit bg-[#DD8306] rounded-md font-semibold my-3 text-white"
|
||||||
|
onPress={submitOtp}
|
||||||
|
>
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
) : needOtp ? (
|
||||||
<div className="bg-[#1F1A17] w-full md:w-2/5 p-8 md:px-24 justify-center flex flex-col">
|
<div className="bg-[#1F1A17] w-full md:w-2/5 p-8 md:px-24 justify-center flex flex-col">
|
||||||
<p className="text-[72px] text-[#DD8306] font-semibold mb-10">
|
<p className="text-[72px] text-[#DD8306] font-semibold mb-10">
|
||||||
Login
|
Login
|
||||||
|
|
@ -237,6 +446,7 @@ export default function Login() {
|
||||||
label=""
|
label=""
|
||||||
placeholder=""
|
placeholder=""
|
||||||
className="my-2"
|
className="my-2"
|
||||||
|
classNames={{ input: "rounded-md", inputWrapper: "rounded-md" }}
|
||||||
value={checkUsernameValue}
|
value={checkUsernameValue}
|
||||||
onChange={(e: any) => {
|
onChange={(e: any) => {
|
||||||
setCheckUsernameValue(e.target.value.trim());
|
setCheckUsernameValue(e.target.value.trim());
|
||||||
|
|
@ -264,9 +474,7 @@ export default function Login() {
|
||||||
>
|
>
|
||||||
Beranda
|
Beranda
|
||||||
</Link>
|
</Link>
|
||||||
{/* <div>
|
|
||||||
<Checkbox color="warning"></Checkbox> Remember me
|
|
||||||
</div> */}
|
|
||||||
<a
|
<a
|
||||||
className="text-[#DD8306] cursor-pointer"
|
className="text-[#DD8306] cursor-pointer"
|
||||||
onClick={() => setIsResetPassword(false)}
|
onClick={() => setIsResetPassword(false)}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue