public async Task <IActionResult> Register([FromBody] RegisterUserDto registerUserDto) { if (registerUserDto == null) { return(BadRequest(_config["Errors:Base:ModelInValid"])); } //Validation model dto var validatorDto = new RegisterUserDtoValidator(); var resultValidateDto = validatorDto.Validate(registerUserDto); if (!resultValidateDto.IsValid) { return(BadRequest(ValidationDto.GetMessagesByErrors(resultValidateDto.Errors))); } //Check user exists var userExists = await _userService.UserExists(registerUserDto.UserName); if (userExists) { return(BadRequest(_config["Errors:User:Exist"])); } //Register user var isOk = await _userService.Register(registerUserDto); return(Ok(isOk)); }
public async Task <ActionResult> Edit(Guid id, [FromBody] EditUserDto editUserDto) { if (id == Guid.Empty || editUserDto == null) { return(BadRequest(_config["Errors:Base:ModelInValid"])); } //Validation model dto var validatorDto = new EditUserDtoValidator(); var resultValidateDto = validatorDto.Validate(editUserDto); if (!resultValidateDto.IsValid) { return(BadRequest(ValidationDto.GetMessagesByErrors(resultValidateDto.Errors))); } //Set Config SetConfig(); //Edit user var isOk = await _userService.Edit(id, editUserDto); return(Ok(isOk)); }
public async Task <IActionResult> Login([FromBody] LoginUserDto loginUserDto) { if (loginUserDto == null) { return(BadRequest(_config["Errors:Base:ModelInValid"])); } // Validation model dto var validatorDto = new LoginUserDtoValidator(); var resultValidateDto = validatorDto.Validate(loginUserDto); if (!resultValidateDto.IsValid) { return(BadRequest(ValidationDto.GetMessagesByErrors(resultValidateDto.Errors))); } // Verify Account var userDto = await _userService.VerifyAccount(loginUserDto); if (userDto == null) { return(BadRequest(_config["Errors:User:Incorrect"])); } // Create Refresh Token RefreshTokenDto refreshTokenDto = await _tokenService.CreateRefreshTokenByUserDtoAsync(userDto); // Generate token var tokenDto = GenerateToken(userDto, refreshTokenDto.RefreshToken); return(Ok(tokenDto)); }