Download src/modules/auth/auth.controller.ts from bardd/node-pt: direct link, hf CLI and curl.
- Browser
- Download file 2.66 kB
-
https://huggingface.co/spaces/bardd/node-pt/resolve/ca4fcfa020aaa53fd098cac7defe8d6c3f7b0afb/src/modules/auth/auth.controller.ts
- Command line
-
hf download hf://spaces/bardd/node-pt@ca4fcfa020aaa53fd098cac7defe8d6c3f7b0afb/src/modules/auth/auth.controller.ts
-
curl -L -o auth.controller.ts https://huggingface.co/spaces/bardd/node-pt/resolve/ca4fcfa020aaa53fd098cac7defe8d6c3f7b0afb/src/modules/auth/auth.controller.ts
2.66 kB
| import { | |
| Body, | |
| Controller, | |
| Get, | |
| HttpStatus, | |
| Inject, | |
| Param, | |
| Post, | |
| Put, | |
| Query, | |
| Req, | |
| Res, | |
| UploadedFile, | |
| UseGuards, | |
| UseInterceptors, | |
| } from '@nestjs/common'; | |
| import { Response, Request } from 'express'; | |
| import { AuthService } from './auth.service'; | |
| import * as bcrypt from 'bcrypt'; | |
| import { LocalAuthGuard } from './local-auth.guard'; | |
| import { UserService } from '../user/user.service'; | |
| import { JwtAuthGuard } from './jwt-auth.guard'; | |
| import * as jwt from 'jsonwebtoken'; | |
| import { FileInterceptor } from '@nestjs/platform-express'; | |
| import { Model } from 'mongoose'; | |
| import { AuthGuard } from '@nestjs/passport'; | |
| import { JwtService } from '@nestjs/jwt'; | |
| import { CommonServices } from '../shared/common.service'; | |
| import { jwtConstants } from 'src/constants/jwt.constant'; | |
| ('auth') | |
| export class AuthController extends CommonServices { | |
| constructor( | |
| private readonly authService: AuthService, | |
| private readonly userService: UserService, | |
| ) { | |
| super(); | |
| } | |
| (LocalAuthGuard) | |
| ('/login') | |
| async login( | |
| () req: any, | |
| () res: Response, | |
| () body: any, | |
| ): Promise<any> { | |
| try { | |
| const Userresp: any = await this.authService.login(req.user, body); | |
| return this.sendResponse( | |
| this.messages.Success, | |
| Userresp, | |
| HttpStatus.OK, | |
| res, | |
| ); | |
| } catch (error) { | |
| console.log(`error =>`, error); | |
| return this.sendResponse( | |
| 'Internal server Error', | |
| {}, | |
| HttpStatus.INTERNAL_SERVER_ERROR, | |
| res, | |
| ); | |
| } | |
| } | |
| ('/signup') | |
| async signup( | |
| () req: any, | |
| () res: Response, | |
| () body: any, | |
| ): Promise<any> { | |
| try { | |
| const email = body.email.toLowerCase().trim(); | |
| const checkUser = await this.userService.sharedFindOne({ email: email }); | |
| if (checkUser && checkUser.email == email) { | |
| return this.sendResponse( | |
| this.messages.userAlreadyExist, | |
| {}, | |
| HttpStatus.CONFLICT, | |
| res, | |
| ); | |
| } | |
| const createUser = await this.userService.sharedCreate({ | |
| ...body, | |
| password: bcrypt.hashSync(body.password, jwtConstants.salt), | |
| roles: ['user'], | |
| }); | |
| const Userresp: any = await this.authService.login(createUser); | |
| return this.sendResponse( | |
| 'Account created!', | |
| { | |
| ...Userresp, | |
| }, | |
| HttpStatus.OK, | |
| res, | |
| ); | |
| } catch (error) { | |
| console.log(error); | |
| return this.sendResponse( | |
| 'Internal server Error', | |
| {}, | |
| HttpStatus.INTERNAL_SERVER_ERROR, | |
| res, | |
| ); | |
| } | |
| } | |
| } | |