mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
refactor: Authentication service.
This commit is contained in:
41
server/src/subscribers/authentication.ts
Normal file
41
server/src/subscribers/authentication.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { Container } from 'typedi';
|
||||
import { pick } from 'lodash';
|
||||
import { EventSubscriber, On } from 'event-dispatch';
|
||||
import events from '@/subscribers/events';
|
||||
|
||||
|
||||
@EventSubscriber()
|
||||
export class AuthenticationSubscriber {
|
||||
|
||||
@On(events.auth.login)
|
||||
public onLogin(payload) {
|
||||
const { emailOrPhone, password } = payload;
|
||||
}
|
||||
|
||||
@On(events.auth.register)
|
||||
public onRegister(payload) {
|
||||
const { registerDTO } = payload;
|
||||
|
||||
const agenda = Container.get('agenda');
|
||||
|
||||
// Send welcome mail to the user.
|
||||
agenda.now('welcome-email', {
|
||||
...pick(registerDTO, ['email', 'organizationName', 'firstName']),
|
||||
});
|
||||
}
|
||||
|
||||
@On(events.auth.resetPassword)
|
||||
public onResetPassword(payload) {
|
||||
|
||||
}
|
||||
|
||||
@On(events.auth.sendResetPassword)
|
||||
public onSendResetPassword (payload) {
|
||||
const { user, token } = payload;
|
||||
|
||||
const agenda = Container.get('agenda');
|
||||
|
||||
// Send reset password mail.
|
||||
agenda.now('reset-password-mail', { user, token })
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ export default {
|
||||
auth: {
|
||||
login: 'onLogin',
|
||||
register: 'onRegister',
|
||||
sendResetPassword: 'onSendResetPassword',
|
||||
resetPassword: 'onResetPassword',
|
||||
},
|
||||
}
|
||||
0
server/src/subscribers/users.ts
Normal file
0
server/src/subscribers/users.ts
Normal file
Reference in New Issue
Block a user