MCPcopy
hub / github.com/diegohaz/rest / create

Function create

generators/app/templates/api/password-reset/controller.js:6–25  ·  view source on GitHub ↗
({ bodymen: { body: { email, link } } }, res, next)

Source from the content-addressed store, hash-verified

4import { User } from '../user'
5
6export const create = ({ bodymen: { body: { email, link } } }, res, next) =>
7 User.findOne({ email })
8 .then(notFound(res))
9 .then((user) => user ? PasswordReset.create({ user }) : null)
10 .then((reset) => {
11 if (!reset) return null
12 const { user, token } = reset
13 link = `${link.replace(/\/$/, '')}/${token}`
14 const content = `
15 Hey, ${user.name}.<br><br>
16 You requested a new password for your <%= name %> account.<br>
17 Please use the following link to set a new password. It will expire in 1 hour.<br><br>
18 <a href="${link}">${link}</a><br><br>
19 If you didn't make this request then you can safely ignore this email. :)<br><br>
20 &mdash; <%= name %> Team
21 `
22 return sendMail({ toEmail: email, subject: '<%= name %> - Password Reset', content })
23 })
24 .then(([response]) => response ? res.status(response.statusCode).end() : null)
25 .catch(next)
26
27export const show = ({ params: { token } }, res, next) =>
28 PasswordReset.findOne({ token })

Callers 1

controller.jsFile · 0.85

Calls 2

notFoundFunction · 0.90
sendMailFunction · 0.90

Tested by

no test coverage detected