-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<%- include('../_header.html.ejs') %> | ||
|
||
<p>Dear <%= firstName %>,</p> | ||
|
||
<p>We have received a request to reset your password for your SF Lifeline account.</p> | ||
|
||
<%- include('../_button.html.ejs', { label: 'Reset Password', url }) %> | ||
|
||
<p>This link will expire in 30 minutes. If you did not request a password reset, please ignore this email or contact | ||
our support team if you have any concerns.</p> | ||
|
||
<p>Sincerely,<br />The SF Life Line Team</p> | ||
|
||
<%- include('../_footer.html.ejs') %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Reset your password for your SF Lifeline account |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Dear <%= firstName %>, | ||
|
||
We have received a request to reset your password for your SF Lifeline account. | ||
|
||
Click on the following link to reset your: | ||
|
||
<%= url %> | ||
|
||
This link will expire in 30 minutes. If you did not request a password reset, please ignore this email or contact | ||
our support team if you have any concerns. | ||
|
||
Sincerely, | ||
The SF Life Line Team | ||
|
||
<%- include('../_footer.text.ejs') %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { StatusCodes } from 'http-status-codes'; | ||
import User from '../../../../models/user.js'; | ||
|
||
export default async function (fastify, _opts) { | ||
fastify.post( | ||
'/request-password-reset', | ||
{ | ||
schema: { | ||
body: { | ||
type: 'object', | ||
required: ['email'], | ||
properties: { | ||
email: { type: 'string' }, | ||
}, | ||
}, | ||
response: { | ||
[StatusCodes.OK]: { | ||
type: 'object', | ||
properties: { | ||
message: { type: 'string' }, | ||
}, | ||
}, | ||
[StatusCodes.NOT_FOUND]: { | ||
type: 'object', | ||
properties: { | ||
message: { type: 'string' }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
async (request, reply) => { | ||
const { email } = request.body; | ||
|
||
const data = await fastify.prisma.user.findUnique({ | ||
where: { email }, | ||
}); | ||
|
||
if (!data) { | ||
return reply.notFound('User not Found'); | ||
} | ||
|
||
const user = new User(data); | ||
|
||
user.generatePasswordResetToken(); | ||
await user.sendPasswordResetEmail(); | ||
|
||
await fastify.prisma.user.update({ | ||
where: { email }, | ||
data: { | ||
passwordResetToken: user.passwordResetToken, | ||
}, | ||
}); | ||
|
||
reply.send('Yes'); | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -695,4 +695,48 @@ describe('/api/v1/users', () => { | |
assert.deepStrictEqual(user.disabledAt, null); | ||
}); | ||
}); | ||
|
||
describe('POST /request-password-reset', () => { | ||
it('should allow user to request a password reset', async (t) => { | ||
const app = await build(t); | ||
await t.loadFixtures(); | ||
|
||
const res = await app | ||
.inject() | ||
.post('/api/v1/users/request-password-reset') | ||
.payload({ | ||
email: '[email protected]', | ||
}); | ||
|
||
assert.deepStrictEqual(res.statusCode, StatusCodes.OK); | ||
|
||
const sentMails = nodemailerMock.mock.getSentMail(); | ||
|
||
assert.notDeepStrictEqual(sentMails.length, 0); | ||
assert.deepStrictEqual( | ||
sentMails[1].to, | ||
'Volunteer User <[email protected]>', | ||
); | ||
assert.deepStrictEqual( | ||
sentMails[1].subject, | ||
'Reset your password for your SF Lifeline account', | ||
); | ||
}); | ||
|
||
it('should return not found if email does not exist', async (t) => { | ||
const app = await build(t); | ||
await t.loadFixtures(); | ||
|
||
const res = await app | ||
.inject() | ||
.post('/api/v1/users/request-password-reset') | ||
.payload({ | ||
email: '[email protected]', | ||
}); | ||
|
||
assert.deepStrictEqual(res.statusCode, StatusCodes.NOT_FOUND); | ||
const { message } = JSON.parse(res.body); | ||
assert.deepStrictEqual(message, 'User not Found'); | ||
}); | ||
}); | ||
}); |