mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
extract reset password email
This commit is contained in:
parent
c6863d6e64
commit
fb53a0bcb0
@ -20,7 +20,7 @@ import { UserRepository } from '../../typeorm/repository/User'
|
||||
import { LoginUser } from '@entity/LoginUser'
|
||||
import { LoginUserBackup } from '@entity/LoginUserBackup'
|
||||
import { LoginEmailOptIn } from '@entity/LoginEmailOptIn'
|
||||
import { sendEMail } from '../../mailer/sendEMail'
|
||||
import { sendResetPasswordEmail } from '../../mailer/sendResetPasswordEmail'
|
||||
import { sendAccountActivationEmail } from '../../mailer/sendAccountActivationEmail'
|
||||
import { LoginElopageBuysRepository } from '../../typeorm/repository/LoginElopageBuys'
|
||||
import { signIn } from '../../apis/KlicktippController'
|
||||
@ -522,18 +522,12 @@ export class UserResolver {
|
||||
optInCode.verificationCode.toString(),
|
||||
)
|
||||
|
||||
const emailSent = await sendEMail({
|
||||
to: `${loginUser.firstName} ${loginUser.lastName} <${email}>`,
|
||||
subject: 'Gradido: Reset Password',
|
||||
text: `Hallo ${loginUser.firstName} ${loginUser.lastName},
|
||||
|
||||
Du oder jemand anderes hat für dieses Konto ein Zurücksetzen des Passworts angefordert.
|
||||
Wenn du es warst, klicke bitte auf den Link: ${link}
|
||||
oder kopiere den obigen Link in Dein Browserfenster.
|
||||
|
||||
Mit freundlichen Grüßen,
|
||||
dein Gradido-Team`,
|
||||
})
|
||||
const emailSent = await sendResetPasswordEmail(
|
||||
link,
|
||||
loginUser.firstName,
|
||||
loginUser.lastName,
|
||||
email,
|
||||
)
|
||||
|
||||
// In case EMails are disabled log the activation link for the user
|
||||
if (!emailSent) {
|
||||
|
||||
23
backend/src/mailer/sendResetPasswordEmail.test.ts
Normal file
23
backend/src/mailer/sendResetPasswordEmail.test.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { sendResetPasswordEmail } from './sendResetPasswordEmail'
|
||||
import { sendEMail } from './sendEMail'
|
||||
|
||||
jest.mock('./sendEMail', () => {
|
||||
return {
|
||||
__esModule: true,
|
||||
sendEMail: jest.fn(),
|
||||
}
|
||||
})
|
||||
|
||||
describe('sendResetPasswordEmail', () => {
|
||||
beforeEach(async () => {
|
||||
await sendResetPasswordEmail('resetLink', 'Peter', 'Lustig', 'peter@lustig.de')
|
||||
})
|
||||
|
||||
it('calls sendEMail', () => {
|
||||
expect(sendEMail).toBeCalledWith({
|
||||
to: `Peter Lustig <peter@lustig.de>`,
|
||||
subject: 'Gradido: Reset Password',
|
||||
text: expect.stringContaining('Hallo Peter Lustig') && expect.stringContaining('resetLink'),
|
||||
})
|
||||
})
|
||||
})
|
||||
21
backend/src/mailer/sendResetPasswordEmail.ts
Normal file
21
backend/src/mailer/sendResetPasswordEmail.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { sendEMail } from './sendEMail'
|
||||
|
||||
export const sendResetPasswordEmail = (
|
||||
resetLink: string,
|
||||
firstName: string,
|
||||
lastName: string,
|
||||
email: string,
|
||||
): Promise<boolean> => {
|
||||
return sendEMail({
|
||||
to: `${firstName} ${lastName} <${email}>`,
|
||||
subject: 'Gradido: Reset Password',
|
||||
text: `Hallo ${firstName} ${lastName},
|
||||
|
||||
Du oder jemand anderes hat für dieses Konto ein Zurücksetzen des Passworts angefordert.
|
||||
Wenn du es warst, klicke bitte auf den Link: ${resetLink}
|
||||
oder kopiere den obigen Link in Dein Browserfenster.
|
||||
|
||||
Mit freundlichen Grüßen,
|
||||
dein Gradido-Team`,
|
||||
})
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user