UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

2 lines 1.62 kB
import{copy as e}from"../../libs/i18n/copy.mjs";import t from"../../constants/constants.mjs";import n from"../../utils/helpers/format-email-subject.mjs";import r from"../../libs/repositories/users.mjs";import{normalizeEmailInput as i}from"../../utils/helpers/normalize-input.mjs";import a from"../email/send-email.mjs";import o from"../user-tokens/create-single.mjs";import{add as s}from"date-fns";const c=async(c,l)=>{if(c.config.auth.password.enabled===!1)return{error:{type:`basic`,status:400,message:e(`server:core.auth.password.authentication.disabled.message`)},data:void 0};let u=new r(c.db.client,c.config.db),d=i(l.email),f=await u.selectSingle({select:[`id`,`first_name`,`last_name`,`email`],where:[{key:`email`,operator:`=`,value:d}]});if(f.error)return f;if(f.data===void 0)return{error:void 0,data:{message:e(`server:core.auth.password.reset.request.accepted`)}};let p=s(new Date,{minutes:t.passwordResetTokenExpirationMinutes}).toISOString(),m=await o(c,{userId:f.data.id,tokenType:t.userTokens.passwordReset,expiryDate:p});if(m.error)return m;let h=await a(c,{type:`internal`,to:f.data.email,subject:e=>n(c.translate(`server:core.email.password.reset.email.subject`),e.context.brand.name),template:t.email.templates.resetPassword.key,data:{firstName:f.data.first_name,lastName:f.data.last_name,email:f.data.email,resetLink:`${t.email.locations.resetPassword}?token=${m.data.token}`},storage:t.email.templates.resetPassword.storage});return h.error?h:{error:void 0,data:{message:e(`server:core.auth.password.reset.request.accepted`)}}};export{c as default}; //# sourceMappingURL=send-reset-password.mjs.map