Commit 4fe88811 authored by Omar Luna Hernández's avatar Omar Luna Hernández
Browse files
parents 476c4668 b0804a65
Loading
Loading
Loading
Loading
+2 −8
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
        "class-transformer": "^0.5.1",
        "class-validator": "^0.14.1",
        "dotenv": "^16.4.5",
        "ejs": "^3.1.10",
        "mysql2": "^3.9.2",
        "network": "^0.7.0",
        "nodemailer": "^6.9.15",
@@ -5321,7 +5322,6 @@
      "version": "3.1.10",
      "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.10.tgz",
      "integrity": "sha512-UeJmFfOrAQS8OJWPZ4qtgHyWExa088/MtK5UEyoJGFH67cDEXkZSviOiKRCZ4Xij0zxI3JECgYs3oKx+AizQBA==",
      "optional": true,
      "dependencies": {
        "jake": "^10.8.5"
      },
@@ -6120,7 +6120,6 @@
      "version": "1.0.4",
      "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz",
      "integrity": "sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q==",
      "optional": true,
      "dependencies": {
        "minimatch": "^5.0.1"
      }
@@ -6129,7 +6128,6 @@
      "version": "5.1.6",
      "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz",
      "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==",
      "optional": true,
      "dependencies": {
        "brace-expansion": "^2.0.1"
      },
@@ -7575,7 +7573,6 @@
      "version": "10.9.2",
      "resolved": "https://registry.npmjs.org/jake/-/jake-10.9.2.tgz",
      "integrity": "sha512-2P4SQ0HrLQ+fw6llpLnOaGAvN2Zu6778SJMrCUwns4fOoG9ayrTiZk3VV8sCPkVZF8ab0zksVpS8FDY5pRCNBA==",
      "optional": true,
      "dependencies": {
        "async": "^3.2.3",
        "chalk": "^4.0.2",
@@ -7592,14 +7589,12 @@
    "node_modules/jake/node_modules/async": {
      "version": "3.2.6",
      "resolved": "https://registry.npmjs.org/async/-/async-3.2.6.tgz",
      "integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==",
      "optional": true
      "integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA=="
    },
    "node_modules/jake/node_modules/brace-expansion": {
      "version": "1.1.11",
      "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
      "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
      "optional": true,
      "dependencies": {
        "balanced-match": "^1.0.0",
        "concat-map": "0.0.1"
@@ -7609,7 +7604,6 @@
      "version": "3.1.2",
      "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
      "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
      "optional": true,
      "dependencies": {
        "brace-expansion": "^1.1.7"
      },
+1 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
    "class-transformer": "^0.5.1",
    "class-validator": "^0.14.1",
    "dotenv": "^16.4.5",
    "ejs": "^3.1.10",
    "mysql2": "^3.9.2",
    "network": "^0.7.0",
    "nodemailer": "^6.9.15",
+2 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import { UserResetCode } from './auth/user/entities/user-reset-code.entity';
import { MailerModule } from '@nestjs-modules/mailer';
import { MailConstants } from './constants/mail.constants';
import { AdminResetCode } from './auth/admin/entitites/admin-reset-code.entity';
import { UserConfirmCode } from './auth/user/entities/user-confirm-code.entity';

@Module({
  imports: [
@@ -64,6 +65,7 @@ import { AdminResetCode } from './auth/admin/entitites/admin-reset-code.entity';
        Visited,
        UserResetCode,
        AdminResetCode,
        UserConfirmCode,
      ],
      synchronize: DbConstants.DB_SYNC,
      logging: false,
+2 −1
Original line number Diff line number Diff line
@@ -10,10 +10,11 @@ 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';
import { UserConfirmCode } from './entities/user-confirm-code.entity';

@Module({
  controllers: [AuthUserController],
  providers: [UserService, JwtService, EncryptionService, AuthUserService, CategoryService, EmailService],
  imports: [TypeOrmModule.forFeature([User, Category, UserResetCode])],
  imports: [TypeOrmModule.forFeature([User, Category, UserResetCode, UserConfirmCode])],
})
export class AuthUserModule {}
+38 −4
Original line number Diff line number Diff line
import { Body, Controller, Get, Patch, Post, Req, UseGuards } from '@nestjs/common';
import { Body, Controller, 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,14 +7,22 @@ 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 {
  UserConfirmEmailBody,
  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, private readonly mailService: EmailService) {}
  constructor(
    private readonly authUserService: AuthUserService,
    private readonly mailService: EmailService,
  ) {}

  @ApiBody({ type: CreateUserDto })
  @ApiCreatedResponse({
@@ -67,4 +75,30 @@ export class AuthUserController {
      throw e;
    }
  }

  @ApiBearerAuth('jwt')
  @UseGuards(AuthUserGuard)
  @Post('user/resend-confirmation-code')
  async resendConfirmationCode(@Req() req: CustomUserRequest) {
    try {
      const email = req.user.email;
      await this.authUserService.sendConfirmationCode(email);
      return { message: 'Confirmation code sent' };
    } catch (e) {
      throw e;
    }
  }

  @ApiBody({ type: UserConfirmEmailBody })
  @ApiBearerAuth('jwt')
  @UseGuards(AuthUserGuard)
  @Post('user/confirm-email')
  async confirmEmail(@Body() { code }, @Req() req: CustomUserRequest) {
    try {
      const email = req.user.email;
      return await this.authUserService.confirmEmail(email, { code });
    } catch (e) {
      throw e;
    }
  }
}
Loading