"use client"; import React, { useState } from "react"; import { Text, Button, TextInput, PasswordInput, Title, Card, Box, Image } from "@mantine/core"; import { notifications } from "@mantine/notifications"; import { Providers } from "@/app/providers"; import NextImage from "next/image"; import logo from '@/app/image/logo.jpg'; import changePwdImage from '@/app/image/changepw.png'; import { useRouter } from "next/navigation"; import { generateOTP } from '@/app/OTPGenerator'; export default function ValidateUser() { const router = useRouter(); const [Cif, setCif] = useState(""); const [otp, setOTP] = useState(""); const [mobileNumber, setMobileNumber] = useState(""); const [isCifValidated, setIsCifValidated] = useState(false); const [generateOtp, setGenerateOtp] = useState(""); const validUsers = [ { cif: "11111111111", mobile: "7890544527" }, { cif: "30022497139", mobile: "6230573848" }, { cif: "11122233344", mobile: "9998887776" }, ]; async function handleGenerateOtp() { // const value = await generateOTP(6); const value = "123456"; setGenerateOtp(value); return value; } const handleValidateUser = async (e: React.FormEvent) => { e.preventDefault(); if (!Cif) { notifications.show({ title: "Invalid CIF", message: "Please Enter your 11 digit CIF number.", color: "red", }); setIsCifValidated(false); return; } if (!/^\d{11}$/.test(Cif)) { notifications.show({ title: "Invalid CIF", message: "CIF number must be exactly 11 digits.", color: "red", }); setIsCifValidated(false); return; } const user = validUsers.find((u) => u.cif === Cif); if (user) { setMobileNumber(user.mobile); setIsCifValidated(true); const Otp = await handleGenerateOtp(); const masked = `xxxxxx${user.mobile.slice(-4)}`; notifications.show({ title: "OTP Sent", message: `OTP sent to your registered mobile number ${masked}`, color: "green", }); } else { setIsCifValidated(false); notifications.show({ title: "User Not Found", message: "No such user is present.", color: "red", }); } }; const handleSubmitOtp = () => { if(!otp){ notifications.show({ title: "Invalid OTP", message: "Please Enter OTP Before You Submit.", color: "red", }); return; } if (otp === generateOtp) { notifications.show({ title: "OTP Verified", message: `OTP matched successfully`, color: "green", }); router.push("/ForgetPassword") } else { setOTP(""); notifications.show({ title: "Invalid OTP", message: `The OTP you entered is incorrect`, color: "red", }); return; } } return (
ebanking Change Password Image {/* @ts-ignore */} Validate User {isCifValidated && ( // @ts-ignore Welcome {" "}{Cif} )}
{ e.preventDefault(); isCifValidated?handleSubmitOtp():handleValidateUser(e); }}> { const input = e.currentTarget.value; if (input.length <= 11) { setCif(input); } }} onKeyDown={(e) => { const isNumberKey = /[0-9]/.test(e.key); const isControlKey = ["Backspace", "Tab", "ArrowLeft", "ArrowRight"].includes(e.key); if (!isNumberKey && !isControlKey) { e.preventDefault(); } }} />
{!isCifValidated && ( <>

NOTE: Your CIF number travels in an encrypted and highly secured mode. )} {isCifValidated && ( <> { const isNumberKey = /[0-9]/.test(e.key); const isControlKey = ["Backspace", "Tab", "ArrowLeft", "ArrowRight"].includes(e.key); if (!isNumberKey && !isControlKey) { e.preventDefault(); } }} onChange={(e) => setOTP(e.currentTarget.value)} /> OTP sent to your registered mobile number{" "} {`xxxxxx${mobileNumber.slice(-4)}`} )}
© 2025 Kangra Central Co-Operative Bank
); }