Commit 94e6cd2f authored by Diego Iván's avatar Diego Iván
Browse files
parents a5a84c03 a142745a
Loading
Loading
Loading
Loading
+3221 −194

File changed.

Preview size limit exceeded, changes collapsed.

+3 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
  },
  "dependencies": {
    "@google-cloud/text-to-speech": "^5.3.0",
    "@nestjs-modules/mailer": "^2.0.2",
    "@nestjs/common": "^10.0.0",
    "@nestjs/core": "^10.0.0",
    "@nestjs/jwt": "^10.2.0",
@@ -35,6 +36,8 @@
    "dotenv": "^16.4.5",
    "mysql2": "^3.9.2",
    "network": "^0.7.0",
    "nodemailer": "^6.9.15",
    "puppeteer": "^23.3.0",
    "qrcode": "^1.5.4",
    "reflect-metadata": "^0.2.0",
    "rxjs": "^7.8.1",
+20 −1
Original line number Diff line number Diff line
@@ -32,6 +32,10 @@ import { TravelPlaceModule } from './travel-place/travel-place.module';
import { TravelPlace } from './travel-place/entities/travel-place.entity';
import { VisitedModule } from './visited/visited.module';
import { Visited } from './visited/entities/visited.entity';
import { EmailService } from './email/email.service';
import { UserResetCode } from './auth/user/entities/user-reset-code.entity';
import { MailerModule } from '@nestjs-modules/mailer';
import { MailConstants } from './constants/mail.constants';

@Module({
  imports: [
@@ -57,10 +61,25 @@ import { Visited } from './visited/entities/visited.entity';
        Route,
        TravelPlace,
        Visited,
        UserResetCode,
      ],
      synchronize: DbConstants.DB_SYNC,
      logging: false,
    }),
    MailerModule.forRoot({
      transport: {
        host: MailConstants.MAIL_HOST,
        port: 587,
        secure: false,
        auth: {
          user: MailConstants.MAIL_USER,
          pass: MailConstants.MAIL_PASSWORD,
        },
      },
      defaults: {
        from: '"No Reply" <noreplt@example.com>',
      },
    }),
    AuthAdminModule,
    AdminModule,
    UserModule,
@@ -79,7 +98,7 @@ import { Visited } from './visited/entities/visited.entity';
    VisitedModule,
  ],
  controllers: [AppController],
  providers: [AppService, DatabaseSeederModule],
  providers: [AppService, DatabaseSeederModule, EmailService],
  exports: [TypeOrmModule],
})
export class AppModule {}
+5 −2
Original line number Diff line number Diff line
@@ -8,9 +8,12 @@ import { User } from 'src/user/entities/user.entity';
import { AuthUserService } from './authUserservice';
import { Category } from 'src/category/entities/category.entity';
import { CategoryService } from 'src/category/category.service';
import { UserResetCode } from './entities/user-reset-code.entity';
import { EmailService } from 'src/email/email.service';

@Module({
  controllers: [AuthUserController],
  providers: [UserService, JwtService, EncryptionService, AuthUserService, CategoryService],
  imports: [TypeOrmModule.forFeature([User, Category])],
  providers: [UserService, JwtService, EncryptionService, AuthUserService, CategoryService, EmailService],
  imports: [TypeOrmModule.forFeature([User, Category, UserResetCode])],
})
export class AuthUserModule {}
+22 −2
Original line number Diff line number Diff line
import { Body, Controller, Patch, Post, Req, UseGuards } from '@nestjs/common';
import { Body, Controller, Get, Patch, Post, Req, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiBody, ApiCreatedResponse, ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger';
import { AuthUserService } from './authUserservice';
import { CreateUserDto } from 'src/user/dto/create-user.dto';
@@ -7,11 +7,14 @@ import { UserSigninResDto } from './dto/user-signin-res.dto';
import { AuthUserGuard } from './authUser.guard';
import { CustomUserRequest } from './interface/customUserReq';
import { UpdatePwdDto } from './dto/update-pwd.dto';
import { UserRequestCodeBody, UserResetPasswordBody, UserResetPasswordDto } from './dto/user-reset-password.dto';
import { GetResetCode } from './dto/get-reset-code.dto';
import { EmailService } from 'src/email/email.service';

@Controller('')
@ApiTags('Create user account and sign in as user')
export class AuthUserController {
  constructor(private readonly authUserService: AuthUserService) {}
  constructor(private readonly authUserService: AuthUserService, private readonly mailService: EmailService) {}

  @ApiBody({ type: CreateUserDto })
  @ApiCreatedResponse({
@@ -47,4 +50,21 @@ export class AuthUserController {
  async changePassword(@Req() req: CustomUserRequest, @Body() updatePwdDto: UpdatePwdDto) {
    return this.authUserService.changePassword(req.user.email, updatePwdDto);
  }

  @ApiBody({ type: UserResetPasswordBody })
  @Post('user/reset-password')
  async resetPassword(@Body() resetPasswordDto: UserResetPasswordDto) {
    return this.authUserService.resetPassword(resetPasswordDto);
  }

  @ApiBody({ type: UserRequestCodeBody })
  @Post('user/get-reset-code')
  async getResetCode(@Body() resetPasswordInfo: GetResetCode) {
    try{
      const code = await this.authUserService.getResetPasswordCode(resetPasswordInfo.email);
      await this.mailService.sendResetPasswordEmail(resetPasswordInfo.email, code);
    } catch (e) {
      throw e;
    }
  }
}
Loading