"use client"; import React, { useState, useEffect } from "react"; import { Text, Button, TextInput, PasswordInput, Title, Card, Group, Box, Image } from "@mantine/core"; import { notifications } from "@mantine/notifications"; import { Providers } from "@/app/providers"; import { useRouter } from "next/navigation"; import NextImage from "next/image"; import logo from '@/app/image/logo1.jpg'; import frontPage from '@/app/image/admin_login.jpg'; import { generateCaptcha } from '@/app/captcha'; export default function Login() { const router = useRouter(); const [error, setError] = useState(null); const [userName, setUserName] = useState(""); const [psw, SetPsw] = useState(""); const [captcha, setCaptcha] = useState(""); const [inputCaptcha, setInputCaptcha] = useState(""); const [isLogging, setIsLogging] = useState(false); useEffect(() => { const loadCaptcha = async () => { const newCaptcha = await generateCaptcha(); setCaptcha(newCaptcha); }; loadCaptcha(); }, []); const regenerateCaptcha = () => { // setCaptcha(generateCaptcha()); const loadCaptcha = async () => { const newCaptcha = await generateCaptcha(); setCaptcha(newCaptcha); }; loadCaptcha(); setInputCaptcha(""); }; async function handleLogin(e: React.FormEvent) { e.preventDefault(); if (!userName || !psw || !captcha) { notifications.show({ withBorder: true, color: "red", title: "Field Blank", message: "Please enter all mandatory details", autoClose: 5000, }); return; } if (inputCaptcha !== captcha) { notifications.show({ withBorder: true, color: "red", title: "Captcha Error", message: "Please enter the correct captcha", autoClose: 5000, }); regenerateCaptcha(); return; } const response = await fetch('/api/auth/admin/login', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ userName: userName, password: psw, }), }); const data = await response.json(); setIsLogging(true); if (response.ok) { console.log(data); const token = data.token; localStorage.setItem("admin_access_token", token); router.push("/administrator/home"); } else { setIsLogging(false); notifications.show({ withBorder: true, color: "red", title: "Wrong User Id or Password", message: "Wrong User Id or Password", autoClose: 5000, }); } } return (
{/* Header */} ebanking
THE KANGRA CENTRAL CO-OPERATIVE BANK LTD. Head Office: Dharmshala, Kangra (H.P), Pin: 176215
{/* Main */} ebanking {/* @ts-ignore */} Admin Portal
setUserName(e.currentTarget.value)} error={error} withAsterisk /> SetPsw(e.currentTarget.value)} withAsterisk mt="sm" /> {captcha} setInputCaptcha(e.currentTarget.value)} withAsterisk mt="sm" />
{/* Footer */} © 2025 KCC Bank. All rights reserved.
); }