"use strict";(()=>{var e={};e.id=908,e.ids=[908],e.modules={5529:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/functions/dsql/hashPassword")},8804:e=>{e.exports=require("@moduletrace/nsqlite")},1635:e=>{e.exports=require("dayjs")},145:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},2048:e=>{e.exports=require("fs")},6249:(e,t)=>{Object.defineProperty(t,"l",{enumerable:!0,get:function(){return function e(t,r){return r in t?t[r]:"then"in t&&"function"==typeof t.then?t.then(t=>e(t,r)):"function"==typeof t&&"default"===r?t:void 0}}})},6644:(e,t,r)=>{r.r(t),r.d(t,{config:()=>l,default:()=>d,routeModule:()=>c});var i={};r.r(i),r.d(i,{default:()=>u});var a=r(1802),n=r(7153),s=r(6249),o=r(4751);async function u(e,t){try{if("POST"!==e.method)return t.json({success:!1,msg:"Wrong Method"});let{email:r,username:i,password:a}=e.body;if("string"!=typeof a||!a?.match(/./))throw Error("Password is required!");let n=await (0,o.Z)({res:t,email_or_username:r||i,password:a,req:e});return t.json(n)}catch(e){return t.json({success:!1,msg:e.message})}}let d=(0,s.l)(i,"default"),l=(0,s.l)(i,"config"),c=new a.PagesAPIRouteModule({definition:{kind:n.x.PAGES_API,page:"/api/auth/login",pathname:"/api/auth/login",bundlePath:"",filename:""},userland:i})},2253:(e,t,r)=>{r.d(t,{dF:()=>s(),_n:()=>l,lV:()=>u()});let i=require("@moduletrace/datasquirel/dist/client");var a=r.n(i);let n=require("@moduletrace/datasquirel/dist/package-shared/utils/ejson");var s=r.n(n);let o=require("@moduletrace/datasquirel/dist/package-shared/utils/slugify");var u=r.n(o);let d=require("@moduletrace/datasquirel/dist/package-shared/utils/numberfy"),l=r.n(d)();a().utils.serializeQuery,a().utils.deserializeQuery},4751:(e,t,r)=>{r.d(t,{Z:()=>f});var i=r(8804),a=r.n(i),n=r(6941),s=r(2253);let o=require("@moduletrace/datasquirel/dist/package-shared/functions/dsql/encrypt");var u=r.n(o),d=r(5529),l=r.n(d),c=r(1635),m=r.n(c),p=r(9786);async function f({req:e,res:t,user_id:r,password:i,email_or_username:o}){let d;if(r){let e=await a().select({table:"users",targetId:r});if(!e.singleRes?.id)throw Error("Couldn't Find user for login");d=e.singleRes}if(o){let e=await a().select({table:"users",query:{query:{email:{value:o},username:{value:o}},searchOperator:"OR"}});if(!e.singleRes?.id)throw Error("Couldn't Find user for login");d=e.singleRes}if(!d)return{success:!1,msg:"User Not Found!"};if(i&&l()({password:i})!==d.password)return{success:!1,msg:"Invalid Password."};let c=Date.now(),f=Math.random().toString(36).substring(2)+"-"+Math.random().toString(36).substring(2),h={first_name:d.first_name,last_name:d.last_name,date:c,email:d.email,csrf_k:f,id:d.id,logged_in_status:!0,image:d.image,image_thumbnail:d.image,super_admin:!!d.is_super_admin},g=s.dF.stringify(h),_=u()({data:g||""}),y=m()(Date.now()).add(7,"days");y.add(7,"days");let{auth_key_cookie_name:P,csrf_cookie_name:q}=(0,p.Z)(),v=e.headers.host;return(0,n.d8)(t,[{name:P,value:_||"",options:{secure:"localhost"!==v,path:"/",expires:y,domain:v}},{name:q,value:f,options:{path:"/",expires:y,domain:v}}]),{success:!0,singleRes:h}}},6941:(e,t,r)=>{function i(e,t){let r=[];for(let e=0;e<t.length;e++){let{name:i,options:a,value:n}=t[e],s=[`${encodeURIComponent(i)}=${encodeURIComponent(n)}`];a.expires&&s.push(`Expires=${a.expires.toDate().toUTCString()}`),void 0!==a.maxAge&&s.push(`Max-Age=${a.maxAge}`),a.path&&s.push(`Path=${a.path}`),a.domain&&s.push(`Domain=${a.domain}`),a.secure&&s.push("Secure"),a.httpOnly&&s.push("HttpOnly"),r.push(s)}let i=r.map(e=>e.join("; "));e.setHeader("Set-Cookie",i)}function a(e,t){return e.split(";").reduce((e,t)=>{let[r,i]=t.trim().split("=").map(decodeURIComponent);return e[r]=i,e},{})[t]||null}r.d(t,{d8:()=>i,ej:()=>a}),r(1635)},9786:(e,t,r)=>{r.d(t,{Z:()=>s});var i=r(2048);let a=require("path");var n=r.n(a);function s(){let{TURBOCI_DEPLOYMENT_ID_FILE:e}=function(){let e=n().resolve(__dirname,"../../"),t="/root/.turboci",r=n().join(t,".config"),i=n().join(r,"turboci.json"),a=n().join(t,"deployment_id"),s=n().join(t,".ssh"),o=n().join(s,"turboci");return{APP_DIR:e,TURBOCI_CONFIG_DIR:r,TURBOCI_CONFIG_JSON_FILE:i,TURBOCI_DIR:t,TURBOCI_SSH_DIR:s,TURBOCI_SSH_KEY_FILE:o,TURBOCI_DEPLOYMENT_ID_FILE:a}}();if(!(0,i.existsSync)(e))throw Error(`\`${e}\` does not exist.`);let t=(0,i.readFileSync)(e,"utf-8").split("-").shift();if(!t)throw Error("Invalid deployment_id");return{auth_key_cookie_name:`turboci-admin-${t}-auth-key`,csrf_cookie_name:`turboci-admin-${t}-csrf`}}},7153:(e,t)=>{var r;Object.defineProperty(t,"x",{enumerable:!0,get:function(){return r}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE"}(r||(r={}))},1802:(e,t,r)=>{e.exports=r(145)}};var t=require("../../../webpack-api-runtime.js");t.C(e);var r=t(t.s=6644);module.exports=r})();