import config from '../config' ; import { Response , Request } from 'express' ; import { UserServiceType } from '../services/user.service' ; import { inject , injectable } from 'inversify' ; import { controller , httpPost , httpGet } from 'inversify-express-utils' ; import 'reflect-metadata' ; import { AuthorizedRequest } from '../requests/authorized.request' ; /**
 * UserController
 */ @ injectable ( ) @ controller ( '/user' , 'OnlyAcceptApplicationJson' ) export class UserController { constructor ( @ inject ( UserServiceType ) private userService ) { } param req param res @ httpPost ( '/' , 'CreateUserValidation' ) async create ( req , res ) { res . json ( await this . userService . create ( req . body ) ) ; } param req param res @ httpPost ( '/activate' , 'ActivateUserValidation' ) async activate ( req , res ) { res . json ( await this . userService . activate ( req . body ) ) ; } param req param res @ httpPost ( '/login/initiate' , 'InitiateLoginValidation' ) async initiateLogin ( req , res ) { let ip = req . header ( config . app . clientIpHeader as string ) || req . ip ; if ( ip . substr ( 0 , 7 ) === '::ffff:' ) { ip = ip . substr ( 7 ) ; } res . json ( await this . userService . initiateLogin ( req . body , ip ) ) ; } param req param res @ httpPost ( '/login/verify' , 'VerifyLoginValidation' ) async validateLogin ( req , res ) { res . status ( 200 ) . send ( await this . userService . verifyLogin ( req . body ) ) ; } param req param res @ httpGet ( '/me' , 'AuthMiddleware' ) async getMe ( req , res ) { res . json ( await this . userService . getUserInfo ( req . user ) ) ; } @ httpPost ( '/me/changePassword/initiate' , 'AuthMiddleware' , 'ChangePasswordValidation' ) async initiateChangePassword ( req , res ) { res . json ( await this . userService . initiateChangePassword ( req . user , req . body ) ) ; } @ httpPost ( '/me/changePassword/verify' , 'AuthMiddleware' , 'ChangePasswordValidation' ) async verifyChangePassword ( req , res ) { res . json ( await this . userService . verifyChangePassword ( req . user , req . body ) ) ; } @ httpPost ( '/resetPassword/initiate' , 'ResetPasswordInitiateValidation' ) async initiateResetPassword ( req , res ) { res . json ( await this . userService . initiateResetPassword ( req . body ) ) ; } @ httpPost ( '/resetPassword/verify' , 'ResetPasswordVerifyValidation' ) async verifyResetPassword ( req , res ) { res . json ( await this . userService . verifyResetPassword ( req . body ) ) ; } @ httpPost ( '/invite' , 'AuthMiddleware' , 'InviteUserValidation' ) async invite ( req , res ) { res . json ( await this . userService . invite ( req . user , req . body ) ) ; } @ httpGet ( '/enable2fa/initiate' , 'AuthMiddleware' ) async enable2faInitiate ( req , res ) { res . json ( await this . userService . initiateEnable2fa ( req . user ) ) ; } @ httpPost ( '/enable2fa/verify' , 'AuthMiddleware' , 'VerificationRequiredValidation' ) async enable2faVerify ( req , res ) { res . json ( await this . userService . verifyEnable2fa ( req . user , req . body ) ) ; } @ httpGet ( '/disable2fa/initiate' , 'AuthMiddleware' ) async disable2faInitiate ( req , res ) { res . json ( await this . userService . initiateDisable2fa ( req . user ) ) ; } @ httpPost ( '/disable2fa/verify' , 'AuthMiddleware' , 'VerificationRequiredValidation' ) async disable2faVerify ( req , res ) { res . json ( await this . userService . verifyDisable2fa ( req . user , req . body ) ) ; } @ httpPost ( '/resendVerification' , 'ResendVerificationValidation' ) async resendVerification ( req , res ) { res . json ( await this . userService . resendVerification ( req . body ) ) ; } }