(()=>{var a={};a.id=7758,a.ids=[7758],a.modules={24:(a,b,c)=>{"use strict";c.d(b,{B:()=>f,E:()=>e});var d=c(7028);async function e(a){return await d.Ay.hash(a,12)}async function f(a,b){return await d.Ay.compare(a,b)}},261:a=>{"use strict";a.exports=require("next/dist/shared/lib/router/utils/app-paths")},3295:a=>{"use strict";a.exports=require("next/dist/server/app-render/after-task-async-storage.external.js")},10846:a=>{"use strict";a.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},17373:(a,b,c)=>{"use strict";c.a(a,async(a,d)=>{try{c.r(b),c.d(b,{DELETE:()=>p,POST:()=>l});var e=c(10641),f=c(25224),g=c(24),h=c(52137),i=c(96032),j=c(30909),k=a([f]);async function l(a){try{let{email:b,password:c}=await a.json();if(!b||!c)return e.NextResponse.json({error:"Email and password are required"},{status:400});let d=await f.A.query("SELECT * FROM users WHERE email = $1",[b]);if(0===d.rows.length)return e.NextResponse.json({error:"Invalid email or password"},{status:401});let i=d.rows[0];if("pending"===i.status)return e.NextResponse.json({error:"Your account is pending approval"},{status:403});if("suspended"===i.status)return e.NextResponse.json({error:"Your account has been suspended"},{status:403});if(!await (0,g.B)(c,i.password_hash))return await n(f.A,i.id,!1,"Invalid password",(0,h.m)(a)),e.NextResponse.json({error:"Invalid email or password"},{status:401});let j=!i.last_login||await m(c,i.password_hash),k=(0,h.m)(a);await n(f.A,i.id,!0,null,k);let l=await o(f.A,i.id,k);await f.A.query("UPDATE users SET last_login = CURRENT_TIMESTAMP WHERE id = $1",[i.id]);let p={id:i.id,title:i.title,firstName:i.first_name,lastName:i.last_name,email:i.email,phoneNumber:i.phone_number,status:i.status,accessLevel:i.access_level,photo:i.photo,designation:i.designation,lastLogin:i.last_login,signupDate:i.signup_date,ticketsSubmitted:i.tickets_submitted,contentPosted:i.content_posted},q={theme:i.theme,accentColour:i.accent_colour,idleTimeout:i.idle_timeout},r=e.NextResponse.json({success:!0,data:{profile:p,preferences:q},meta:{needsPasswordChange:j}});return r.cookies.set("session_token",l,{httpOnly:!0,secure:!0,sameSite:"lax",maxAge:86400,path:"/"}),r.cookies.set("user_id",i.id.toString(),{httpOnly:!1,secure:!0,sameSite:"lax",maxAge:86400,path:"/"}),r}catch(a){return console.error("Login error:",a),e.NextResponse.json({success:!1,error:"Internal server error"},{status:500})}}async function m(a,b){return a===i.Gr||(await (0,g.E)(i.Gr),await (0,g.B)(i.Gr,b))}async function n(a,b,c,d=null,e){try{await a.query(`INSERT INTO login_history (
        user_id, login_time, ip_address, user_agent,
        device_info, location, success, failure_reason
      ) VALUES ($1, NOW(), $2, $3, $4, $5, $6, $7)`,[b,e.ip||"Unknown",e.userAgent||"Unknown",e.device||"Unknown",e.location||"Unknown",c,d])}catch(a){console.error("Error recording login attempt:",a)}}async function o(a,b,c){try{let d=(0,j.A)(),e=new Date;return e.setHours(e.getHours()+24),await a.query(`UPDATE user_sessions 
       SET is_active = false, logout_time = NOW()
       WHERE user_id = $1 AND is_active = true AND token IS NOT NULL`,[b]),await a.query(`INSERT INTO user_sessions (
        user_id, token, expires_at, login_time, ip_address, 
        user_agent, device_info, location, last_activity, 
        is_active, session_type
      ) VALUES ($1, $2, $3, NOW(), $4, $5, $6, $7, NOW(), true, 'token')`,[b.toString(),d,e,c.ip||"Unknown",c.userAgent||"Unknown",c.device||"Unknown",c.location||"Unknown"]),d}catch(a){throw console.error("Error creating user session:",a),a}}async function p(a){try{let b=a.cookies.get("session_token")?.value;b&&await f.A.query(`UPDATE user_sessions 
         SET is_active = false, logout_time = NOW()
         WHERE token = $1 AND is_active = true`,[b]);let c=e.NextResponse.json({success:!0});return c.cookies.delete("session_token"),c.cookies.delete("user_id"),c}catch(a){return console.error("Logout error:",a),e.NextResponse.json({success:!1,error:"Internal server error"},{status:500})}}f=(k.then?(await k)():k)[0],d()}catch(a){d(a)}})},19121:a=>{"use strict";a.exports=require("next/dist/server/app-render/action-async-storage.external.js")},25224:(a,b,c)=>{"use strict";c.a(a,async(a,d)=>{try{c.d(b,{A:()=>g});var e=c(64939),f=a([e]);let g=new(e=(f.then?(await f)():f)[0]).Pool({user:process.env.DB_USER,host:process.env.DB_HOST,database:process.env.DB_NAME,password:process.env.DB_PASSWORD,port:parseInt(process.env.DB_PORT||"5432")});d()}catch(a){d(a)}})},29294:a=>{"use strict";a.exports=require("next/dist/server/app-render/work-async-storage.external.js")},30909:(a,b,c)=>{"use strict";c.d(b,{A:()=>i});let d=require("node:crypto"),e={randomUUID:d.randomUUID},f=new Uint8Array(256),g=f.length,h=[];for(let a=0;a<256;++a)h.push((a+256).toString(16).slice(1));let i=function(a,b,c){if(e.randomUUID&&!b&&!a)return e.randomUUID();var i=a,j=c;let k=(i=i||{}).random??i.rng?.()??(g>f.length-16&&((0,d.randomFillSync)(f),g=0),f.slice(g,g+=16));if(k.length<16)throw Error("Random bytes length must be >= 16");if(k[6]=15&k[6]|64,k[8]=63&k[8]|128,b){if((j=j||0)<0||j+16>b.length)throw RangeError(`UUID byte range ${j}:${j+15} is out of buffer bounds`);for(let a=0;a<16;++a)b[j+a]=k[a];return b}return function(a,b=0){return(h[a[b+0]]+h[a[b+1]]+h[a[b+2]]+h[a[b+3]]+"-"+h[a[b+4]]+h[a[b+5]]+"-"+h[a[b+6]]+h[a[b+7]]+"-"+h[a[b+8]]+h[a[b+9]]+"-"+h[a[b+10]]+h[a[b+11]]+h[a[b+12]]+h[a[b+13]]+h[a[b+14]]+h[a[b+15]]).toLowerCase()}(k)}},36268:(a,b,c)=>{"use strict";c.a(a,async(a,d)=>{try{c.r(b),c.d(b,{handler:()=>x,patchFetch:()=>w,routeModule:()=>y,serverHooks:()=>B,workAsyncStorage:()=>z,workUnitAsyncStorage:()=>A});var e=c(95736),f=c(9117),g=c(4044),h=c(39326),i=c(32324),j=c(261),k=c(54290),l=c(85328),m=c(38928),n=c(46595),o=c(3421),p=c(17679),q=c(41681),r=c(63446),s=c(86439),t=c(51356),u=c(17373),v=a([u]);u=(v.then?(await v)():v)[0];let y=new e.AppRouteRouteModule({definition:{kind:f.RouteKind.APP_ROUTE,page:"/api/auth/login/route",pathname:"/api/auth/login",filename:"route",bundlePath:"app/api/auth/login/route"},distDir:".next",relativeProjectDir:"",resolvedPagePath:"/Users/kanyinsola/Documents/koh/kohfrontline/src/app/api/auth/login/route.ts",nextConfigOutput:"standalone",userland:u}),{workAsyncStorage:z,workUnitAsyncStorage:A,serverHooks:B}=y;function w(){return(0,g.patchFetch)({workAsyncStorage:z,workUnitAsyncStorage:A})}async function x(a,b,c){var d;let e="/api/auth/login/route";"/index"===e&&(e="/");let g=await y.prepare(a,b,{srcPage:e,multiZoneDraftMode:!1});if(!g)return b.statusCode=400,b.end("Bad Request"),null==c.waitUntil||c.waitUntil.call(c,Promise.resolve()),null;let{buildId:u,params:v,nextConfig:w,isDraftMode:x,prerenderManifest:z,routerServerContext:A,isOnDemandRevalidate:B,revalidateOnlyGenerated:C,resolvedPathname:D}=g,E=(0,j.normalizeAppPath)(e),F=!!(z.dynamicRoutes[E]||z.routes[D]);if(F&&!x){let a=!!z.routes[D],b=z.dynamicRoutes[E];if(b&&!1===b.fallback&&!a)throw new s.NoFallbackError}let G=null;!F||y.isDev||x||(G=D,G="/index"===G?"/":G);let H=!0===y.isDev||!F,I=F&&!H,J=a.method||"GET",K=(0,i.getTracer)(),L=K.getActiveScopeSpan(),M={params:v,prerenderManifest:z,renderOpts:{experimental:{cacheComponents:!!w.experimental.cacheComponents,authInterrupts:!!w.experimental.authInterrupts},supportsDynamicResponse:H,incrementalCache:(0,h.getRequestMeta)(a,"incrementalCache"),cacheLifeProfiles:null==(d=w.experimental)?void 0:d.cacheLife,isRevalidate:I,waitUntil:c.waitUntil,onClose:a=>{b.on("close",a)},onAfterTaskError:void 0,onInstrumentationRequestError:(b,c,d)=>y.onRequestError(a,b,d,A)},sharedContext:{buildId:u}},N=new k.NodeNextRequest(a),O=new k.NodeNextResponse(b),P=l.NextRequestAdapter.fromNodeNextRequest(N,(0,l.signalFromNodeResponse)(b));try{let d=async c=>y.handle(P,M).finally(()=>{if(!c)return;c.setAttributes({"http.status_code":b.statusCode,"next.rsc":!1});let d=K.getRootSpanAttributes();if(!d)return;if(d.get("next.span_type")!==m.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${d.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let e=d.get("next.route");if(e){let a=`${J} ${e}`;c.setAttributes({"next.route":e,"http.route":e,"next.span_name":a}),c.updateName(a)}else c.updateName(`${J} ${a.url}`)}),g=async g=>{var i,j;let k=async({previousCacheEntry:f})=>{try{if(!(0,h.getRequestMeta)(a,"minimalMode")&&B&&C&&!f)return b.statusCode=404,b.setHeader("x-nextjs-cache","REVALIDATED"),b.end("This page could not be found"),null;let e=await d(g);a.fetchMetrics=M.renderOpts.fetchMetrics;let i=M.renderOpts.pendingWaitUntil;i&&c.waitUntil&&(c.waitUntil(i),i=void 0);let j=M.renderOpts.collectedTags;if(!F)return await (0,o.I)(N,O,e,M.renderOpts.pendingWaitUntil),null;{let a=await e.blob(),b=(0,p.toNodeOutgoingHttpHeaders)(e.headers);j&&(b[r.NEXT_CACHE_TAGS_HEADER]=j),!b["content-type"]&&a.type&&(b["content-type"]=a.type);let c=void 0!==M.renderOpts.collectedRevalidate&&!(M.renderOpts.collectedRevalidate>=r.INFINITE_CACHE)&&M.renderOpts.collectedRevalidate,d=void 0===M.renderOpts.collectedExpire||M.renderOpts.collectedExpire>=r.INFINITE_CACHE?void 0:M.renderOpts.collectedExpire;return{value:{kind:t.CachedRouteKind.APP_ROUTE,status:e.status,body:Buffer.from(await a.arrayBuffer()),headers:b},cacheControl:{revalidate:c,expire:d}}}}catch(b){throw(null==f?void 0:f.isStale)&&await y.onRequestError(a,b,{routerKind:"App Router",routePath:e,routeType:"route",revalidateReason:(0,n.c)({isRevalidate:I,isOnDemandRevalidate:B})},A),b}},l=await y.handleResponse({req:a,nextConfig:w,cacheKey:G,routeKind:f.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:z,isRoutePPREnabled:!1,isOnDemandRevalidate:B,revalidateOnlyGenerated:C,responseGenerator:k,waitUntil:c.waitUntil});if(!F)return null;if((null==l||null==(i=l.value)?void 0:i.kind)!==t.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==l||null==(j=l.value)?void 0:j.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});(0,h.getRequestMeta)(a,"minimalMode")||b.setHeader("x-nextjs-cache",B?"REVALIDATED":l.isMiss?"MISS":l.isStale?"STALE":"HIT"),x&&b.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let m=(0,p.fromNodeOutgoingHttpHeaders)(l.value.headers);return(0,h.getRequestMeta)(a,"minimalMode")&&F||m.delete(r.NEXT_CACHE_TAGS_HEADER),!l.cacheControl||b.getHeader("Cache-Control")||m.get("Cache-Control")||m.set("Cache-Control",(0,q.getCacheControlHeader)(l.cacheControl)),await (0,o.I)(N,O,new Response(l.value.body,{headers:m,status:l.value.status||200})),null};L?await g(L):await K.withPropagatedContext(a.headers,()=>K.trace(m.BaseServerSpan.handleRequest,{spanName:`${J} ${a.url}`,kind:i.SpanKind.SERVER,attributes:{"http.method":J,"http.target":a.url}},g))}catch(b){if(L||b instanceof s.NoFallbackError||await y.onRequestError(a,b,{routerKind:"App Router",routePath:E,routeType:"route",revalidateReason:(0,n.c)({isRevalidate:I,isOnDemandRevalidate:B})}),F)throw b;return await (0,o.I)(N,O,new Response(null,{status:500})),null}}d()}catch(a){d(a)}})},44870:a=>{"use strict";a.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},52137:(a,b,c)=>{"use strict";function d(a){var b,c;let d=a.headers.get("user-agent")||"Unknown",e=function(a){let b=a.headers.get("x-forwarded-for"),c=a.headers.get("x-real-ip"),d=a.headers.get("cf-connecting-ip");return b?b.split(",")[0].trim():d||c||"127.0.0.1"}(a);return{ip:e,userAgent:d,device:(b=d)?/mobile/i.test(b)?"Mobile":/tablet/i.test(b)?"Tablet":"Desktop":"Unknown Device",location:"127.0.0.1"===(c=e)||"::1"===c?"Localhost":"Unknown Location"}}c.d(b,{m:()=>d})},55511:a=>{"use strict";a.exports=require("crypto")},63033:a=>{"use strict";a.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},64939:a=>{"use strict";a.exports=import("pg")},78335:()=>{},86439:a=>{"use strict";a.exports=require("next/dist/shared/lib/no-fallback-error.external")},96032:(a,b,c)=>{"use strict";c.d(b,{Ft:()=>f,Gr:()=>d,gW:()=>e});let d="password123",e=[{label:"Election Data",href:"/dataentry"},{label:"Parties",href:"/dataentry/parties"},{label:"Candidates",href:"/dataentry/candidates"}],f=[{label:"Profile",href:"/settings"},{label:"Account",href:"/settings/account"},{label:"Security",href:"/settings/security"},{label:"Preferences",href:"/settings/preferences"}]},96487:()=>{}};var b=require("../../../../webpack-runtime.js");b.C(a);var c=b.X(0,[4586,1692,7028],()=>b(b.s=36268));module.exports=c})();