"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 s=r(1802),n=r(7153),a=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:s}=e.body;if("string"!=typeof s||!s?.match(/./))throw Error("Password is required!");let n=await (0,o.Z)({res:t,email_or_username:r||i,password:s});return t.json(n)}catch(e){return t.json({success:!1,msg:e.message})}}let d=(0,a.l)(i,"default"),l=(0,a.l)(i,"config"),c=new s.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:()=>a(),_n:()=>l,lV:()=>u()});let i=require("@moduletrace/datasquirel/dist/client");var s=r.n(i);let n=require("@moduletrace/datasquirel/dist/package-shared/utils/ejson");var a=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)();s().utils.serializeQuery,s().utils.deserializeQuery},4751:(e,t,r)=>{r.d(t,{Z:()=>f});var i=r(8804),s=r.n(i),n=r(6941),a=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),p=r.n(c),m=r(9786);async function f({res:e,user_id:t,password:r,email_or_username:i}){let o;if(t){let e=await s().select({table:"users",targetId:t});if(!e.singleRes?.id)throw Error("Couldn't Find user for login");o=e.singleRes}if(i){let e=await s().select({table:"users",query:{query:{email:{value:i},username:{value:i}},searchOperator:"OR"}});if(!e.singleRes?.id)throw Error("Couldn't Find user for login");o=e.singleRes}if(!o)return{success:!1,msg:"User Not Found!"};if(r&&l()({password:r})!==o.password)return{success:!1,msg:"Invalid Password."};let d=Date.now(),c=Math.random().toString(36).substring(2)+"-"+Math.random().toString(36).substring(2),f={first_name:o.first_name,last_name:o.last_name,date:d,email:o.email,csrf_k:c,id:o.id,logged_in_status:!0,image:o.image,image_thumbnail:o.image,super_admin:!!o.is_super_admin},g=a.dF.stringify(f),h=u()({data:g||""}),_=p()(Date.now()).add(7,"days");_.add(7,"days");let{auth_key_cookie_name:y,csrf_cookie_name:P}=(0,m.Z)();return(0,n.d8)(e,[{name:y,value:h||"",options:{secure:"localhost"!==process.env.DOMAIN,path:"/",expires:_,domain:process.env.DOMAIN}},{name:P,value:c,options:{path:"/",expires:_,domain:process.env.DOMAIN}}]),{success:!0,singleRes:f}}},6941:(e,t,r)=>{function i(e,t){let r=[];for(let e=0;e<t.length;e++){let{name:i,options:s,value:n}=t[e],a=[`${encodeURIComponent(i)}=${encodeURIComponent(n)}`];s.expires&&a.push(`Expires=${s.expires.toDate().toUTCString()}`),void 0!==s.maxAge&&a.push(`Max-Age=${s.maxAge}`),s.path&&a.push(`Path=${s.path}`),s.domain&&a.push(`Domain=${s.domain}`),s.secure&&a.push("Secure"),s.httpOnly&&a.push("HttpOnly"),r.push(a)}let i=r.map(e=>e.join("; "));e.setHeader("Set-Cookie",i)}function s(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:()=>s}),r(1635)},9786:(e,t,r)=>{r.d(t,{Z:()=>a});var i=r(2048);let s=require("path");var n=r.n(s);function a(){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"),s=n().join(t,"deployment_id"),a=n().join(t,".ssh"),o=n().join(a,"turboci");return{APP_DIR:e,TURBOCI_CONFIG_DIR:r,TURBOCI_CONFIG_JSON_FILE:i,TURBOCI_DIR:t,TURBOCI_SSH_DIR:a,TURBOCI_SSH_KEY_FILE:o,TURBOCI_DEPLOYMENT_ID_FILE:s}}();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})();