public async Task <IActionResult> SignIn( [FromServices] IAuthenticationService _services, [FromBody] LoginCreateDTO loginDTO) { loginDTO.Validate(); if (loginDTO.Invalid) { return(BadRequest(new ResultDTO(false, "Invalid field.", loginDTO.Notifications))); } try { var userSignIOutDto = await _services.Login(loginDTO); if (userSignIOutDto.Success == false) { return(BadRequest(userSignIOutDto)); } return(Ok(userSignIOutDto)); } catch (Exception ex) { return(this.StatusCode(StatusCodes.Status500InternalServerError, $"ERROR {ex.Message}")); } }
public async Task <ResultDTO> Login(LoginCreateDTO loginDTO) { var user = await _userManager.FindByEmailAsync(loginDTO.Email); if (user == null) { return(new ResultDTO(false, "Please, confirm your email, verify your password, verify your user name and try again.", user)); } var result = await _signInManager .CheckPasswordSignInAsync(user, loginDTO.Password, false); if (result.IsNotAllowed == true) { await CreateAndSendEmailConfirm(loginDTO.Email, user).ConfigureAwait(false); return(new ResultDTO(true, "A new email has been send to your email, please, confirm and try again.", result)); } if (!result.Succeeded) { return(new ResultDTO(false, "Please, confirm your email, verify your password, verify your user name and try again.", result)); } var token = _tokenService.GenerateJwtToken(user).Result; var userToReturn = _mapper.Map <LoginReadDTO>(user); userToReturn.AddToken(token); return(new ResultDTO(true, "User authenticated.", userToReturn)); }
public void Check_Password_Smaller_or_Equals_100_Chars(string email) { var loginCreateDTO = new LoginCreateDTO { Email = email, Password = new string('*', 101) }; loginCreateDTO.Validate(); Assert.IsTrue(loginCreateDTO.Invalid); }
public void Check_Password_Greater_Than_7_Chars(string email, string password) { var loginCreateDTO = new LoginCreateDTO { Email = email, Password = password }; loginCreateDTO.Validate(); Assert.IsTrue(loginCreateDTO.Invalid); }
public void Check_Password_Is_Valid(string email, string password) { var loginCreateDTO = new LoginCreateDTO { Email = email, Password = password }; loginCreateDTO.Validate(); Assert.IsTrue(loginCreateDTO.Valid); }
public void LoginCreate_Valid_Should_Pass(string email, string password) { var loginCreateDTO = new LoginCreateDTO(); Assert.IsNull(loginCreateDTO.Email); Assert.IsNull(loginCreateDTO.Password); loginCreateDTO.Email = email; loginCreateDTO.Password = password; Assert.IsNotNull(loginCreateDTO); Assert.AreEqual(email, loginCreateDTO.Email); Assert.AreEqual(password, loginCreateDTO.Password); loginCreateDTO.Validate(); Assert.IsTrue(loginCreateDTO.Valid); }
private static Task <ResultDTO> CreateControlerAndUseService( string fullName = null, string email = null, string confirmPassword = null, string password = null, string token = null ) { var fakeContext = new FakeContext("AccountManagerServiceTests"); var fakeUserManager = fakeContext.FakeUserManager().Object; var fakeSignInManager = fakeContext.FakeSigninManager().Object; var controller = new AuthenticationService(fakeUserManager, fakeSignInManager, fakeContext._mapper, fakeContext._tokenService, fakeContext._configuration, fakeContext._mailService); if (fullName != null) { var registerDTO = new RegisterCreateDTO { FullName = fullName, Email = email, Password = password, ConfirmPassword = confirmPassword };; return(controller.Register(registerDTO)); } else if (token != null) { var result = controller.ConfirmEmail(email, token); return(result); } else if (password != null) { var loginDTO = new LoginCreateDTO { Email = email, Password = password }; return(controller.Login(loginDTO)); } var forgotPasswordDTO = new ForgotPasswordDTO { Email = email }; return(controller.ForgotPassword(forgotPasswordDTO)); }
private static Task <IActionResult> CriaControllerEUtilizaAService( string fullName = null, string email = null, string password = null, string confirmPassword = null, string token = null) { var fakeContext = new FakeContext("AccountManagerControllerTests"); var fakeService = fakeContext.FakeAuthenticationRepository().Object; var controller = new AuthenticationController(); if (confirmPassword != null) { var registerCreateDTO = new RegisterCreateDTO { FullName = fullName, Email = email, Password = password, ConfirmPassword = confirmPassword }; return(controller.Register(fakeService, registerCreateDTO)); } else if (token != null) { return(controller.ConfirmEmail(fakeService, fakeContext._configuration, email, token)); } else if (password != null && confirmPassword == null) { var loginCreateDTO = new LoginCreateDTO { Email = email, Password = password }; return(controller.SignIn(fakeService, loginCreateDTO)); } else { var forgotPasswordDTO = new ForgotPasswordDTO { Email = email }; return(controller.ForgotPassword(fakeService, forgotPasswordDTO)); } }