1
- import { Body , Controller , Get , HttpCode , HttpStatus , Patch , Post , Query , Req , Res , UseGuards } from '@nestjs/common' ;
1
+ import {
2
+ Body ,
3
+ Controller ,
4
+ Get ,
5
+ HttpCode ,
6
+ HttpStatus ,
7
+ Patch ,
8
+ Post ,
9
+ Query ,
10
+ Req ,
11
+ Res ,
12
+ UseGuards ,
13
+ } from '@nestjs/common' ;
2
14
import { AuthService } from './auth.service' ;
3
15
import { LocalUserRegisterDto } from './dto/LocalUserRegisterDto' ;
4
16
import { LocalUserLoginDto } from './dto/LocalUserLoginDto' ;
5
17
import { AuthGuard } from '@nestjs/passport' ;
6
18
import { AuthReq , GeneralAuthenticator } from './guards/GeneralAuthenticator' ;
7
- import { query , Response } from 'express' ;
19
+ import { Response } from 'express' ;
8
20
import { ResetPasswordDto } from './dto/ResetPasswordDto' ;
9
21
import { ChangePasswordDto } from './dto/ChangePasswordDto' ;
10
22
11
-
12
- @Controller ( "auth" )
23
+ @Controller ( 'auth' )
13
24
export class AuthController {
14
-
15
-
16
- constructor ( private readonly authService :AuthService ) { }
17
-
25
+ constructor ( private readonly authService : AuthService ) { }
26
+ // check authenticated User
18
27
@Get ( 'check' )
19
28
@UseGuards ( GeneralAuthenticator )
20
- checkAuth ( @Req ( ) req :AuthReq ) {
21
- return this . authService . checkAuth ( req )
29
+ checkAuth ( @Req ( ) req : AuthReq ) {
30
+ return this . authService . checkAuth ( req ) ;
22
31
}
23
32
@Get ( 'google' )
24
33
@UseGuards ( AuthGuard ( 'google' ) )
25
- googleRedirect ( ) { }
26
-
27
-
28
- @Get ( "/reset" )
29
- checkIsValidResetUrl ( @Query ( "token" ) token :string ) {
30
- return this . authService . checkResetPasswordUrlValid ( token ) ;
31
- }
34
+ googleRedirect ( ) { }
32
35
33
36
@Get ( 'google/redirect' )
34
37
@UseGuards ( AuthGuard ( 'google' ) )
35
- googleLoginUserRedirect ( @Req ( ) req :AuthReq , @Res ( { passthrough :true } ) res :Response ) {
36
-
37
-
38
- return this . authService . loginGoogleUSer ( req , res ) ;
38
+ googleLoginUserRedirect (
39
+ @Req ( ) req : AuthReq ,
40
+ @Res ( { passthrough : true } ) res : Response ,
41
+ ) {
42
+ return this . authService . loginGoogleUSer ( req , res ) ;
39
43
}
40
44
41
45
// local authentication routes
42
- @Post ( " register" )
46
+ @Post ( ' register' )
43
47
registerUserByEmail ( @Body ( ) localUserRegisterDto : LocalUserRegisterDto ) {
44
48
return this . authService . registerLocalUser ( localUserRegisterDto ) ;
45
49
}
46
- @Post ( " login" )
50
+ @Post ( ' login' )
47
51
@HttpCode ( HttpStatus . OK )
48
- loginLocalAccount ( @Body ( ) localUserLoginDto : LocalUserLoginDto , @Res ( { passthrough :true } ) res :Response ) {
52
+ loginLocalAccount (
53
+ @Body ( ) localUserLoginDto : LocalUserLoginDto ,
54
+ @Res ( { passthrough : true } ) res : Response ,
55
+ ) {
49
56
return this . authService . loginLocalUser ( localUserLoginDto , res ) ;
50
57
}
51
58
52
- @Post ( "reset" )
53
- resetPasswordRequest ( @Body ( ) resetPasswordDto :ResetPasswordDto ) {
59
+ // reset password mechanisme
60
+ @Get ( '/reset' )
61
+ checkIsValidResetUrl ( @Query ( 'token' ) token : string ) {
62
+ return this . authService . checkResetPasswordUrlValid ( token ) ;
63
+ }
64
+ @Post ( 'reset' )
65
+ @HttpCode ( HttpStatus . OK )
66
+ resetPasswordRequest ( @Body ( ) resetPasswordDto : ResetPasswordDto ) {
54
67
return this . authService . requestResetPassword ( resetPasswordDto ) ;
55
68
}
56
- @Patch ( "reset" )
57
- changePassword ( @Body ( ) changePasswordDto :ChangePasswordDto , @Query ( 'token' ) token :string ) {
58
- return this . authService . changePassword ( changePasswordDto , token ) ;
59
-
69
+ @Patch ( 'reset' )
70
+ changePassword (
71
+ @Body ( ) changePasswordDto : ChangePasswordDto ,
72
+ @Query ( 'token' ) token : string ,
73
+ ) {
74
+ return this . authService . changePassword ( changePasswordDto , token ) ;
60
75
}
61
- }
76
+ }
0 commit comments