2026-08-29 21:06:30 +03:30
|
|
|
import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common';
|
|
|
|
|
import { AuthService } from './auth.service';
|
2026-09-05 00:47:33 +03:30
|
|
|
import {
|
|
|
|
|
LoginDto,
|
2026-09-05 01:37:15 +03:30
|
|
|
LoginOtpRequestDto,
|
|
|
|
|
LoginOtpVerifyDto,
|
2026-09-05 00:47:33 +03:30
|
|
|
RegisterOrganizationDto,
|
|
|
|
|
RegisterVerifyOtpDto,
|
|
|
|
|
} from './dto';
|
2026-08-29 21:06:30 +03:30
|
|
|
import { JwtAuthGuard } from './jwt-auth.guard';
|
|
|
|
|
import { CurrentUser } from './current-user.decorator';
|
|
|
|
|
|
|
|
|
|
@Controller('auth')
|
|
|
|
|
export class AuthController {
|
|
|
|
|
constructor(private readonly authService: AuthService) {}
|
|
|
|
|
|
|
|
|
|
@Post('register')
|
|
|
|
|
register(@Body() dto: RegisterOrganizationDto) {
|
2026-09-05 00:47:33 +03:30
|
|
|
return this.authService.startRegister(dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('register/verify')
|
|
|
|
|
registerVerify(@Body() dto: RegisterVerifyOtpDto) {
|
|
|
|
|
return this.authService.verifyRegister(dto);
|
2026-08-29 21:06:30 +03:30
|
|
|
}
|
|
|
|
|
|
2026-09-05 01:37:15 +03:30
|
|
|
/** ورود با رمز (بدون OTP) */
|
2026-08-29 21:06:30 +03:30
|
|
|
@Post('login')
|
|
|
|
|
login(@Body() dto: LoginDto) {
|
2026-09-05 01:37:15 +03:30
|
|
|
return this.authService.loginWithPassword(dto);
|
2026-09-05 00:47:33 +03:30
|
|
|
}
|
|
|
|
|
|
2026-09-05 01:37:15 +03:30
|
|
|
/** درخواست کد ورود با موبایل */
|
|
|
|
|
@Post('login/otp')
|
|
|
|
|
loginOtpRequest(@Body() dto: LoginOtpRequestDto) {
|
|
|
|
|
return this.authService.requestLoginOtp(dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** تأیید کد ورود با موبایل */
|
|
|
|
|
@Post('login/otp/verify')
|
|
|
|
|
loginOtpVerify(@Body() dto: LoginOtpVerifyDto) {
|
|
|
|
|
return this.authService.verifyLoginOtp(dto);
|
2026-08-29 21:06:30 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
|
|
|
@Get('me')
|
|
|
|
|
me(@CurrentUser() user: { userId: string }) {
|
|
|
|
|
return this.authService.me(user.userId);
|
|
|
|
|
}
|
|
|
|
|
}
|