diff --git a/server/src/auth/auth.service.ts b/server/src/auth/auth.service.ts index 7b5e6e9..8567f03 100644 --- a/server/src/auth/auth.service.ts +++ b/server/src/auth/auth.service.ts @@ -25,9 +25,12 @@ export class AuthService { const match = await bcrypt.compare(password, user?.hashedPassword); if (!match) { - throw new UnauthorizedException(); + throw new UnauthorizedException("Password or email doesn't match"); } + user.lastLogin = new Date(); + await user.save(); + await this.mailer.sendTemplateMail({ templateType: 'login', recipients: [email], diff --git a/server/src/users/users.service.ts b/server/src/users/users.service.ts index be64c2d..bce00dd 100644 --- a/server/src/users/users.service.ts +++ b/server/src/users/users.service.ts @@ -66,7 +66,13 @@ export class UsersService { } async create(createUserDto: CreateUserDto): Promise { - const createdUser = new this.model(createUserDto); + const now = new Date(); + + const createdUser = new this.model({ + ...createUserDto, + lastLogin: now, + joined: now, + }); return await createdUser.save(); } @@ -87,7 +93,7 @@ export class UsersService { return String(user._id); } - async findOneByEmail(email: string): Promise { + async findOneByEmail(email: string): Promise { return await this.model.findOne({ email: email }); }