public void Login_InputDtoAuthUser_AreSame() { InputDtoAuthUser input = new InputDtoAuthUser { Name = "name", Password = "******" }; _userService.Query().Returns(getUserOutputDtoList()); _userService.HashPassword("password") .Returns("password"); var userInDb = new User("name", "password", "email", "user"); _tokenManager.GenerateJwtToken( new OutputDtoQueryUser(userInDb.Name, userInDb.Password, userInDb.Email, userInDb.Role) ).Returns("token"); var res = _authService.Login(input); var expected = new OutputDtoAuthUser { Token = "token" }; Assert.AreEqual(expected, res); }
public ActionResult <OutputDtoAuthUser> Login([FromBody] InputDtoAuthUser user) { OutputDtoAuthUser authUser = _authService.Login(user); if (authUser != null) { return(Ok(authUser)); } return(BadRequest("Invalid user")); }
public OutputDtoAuthUser Login(InputDtoAuthUser user) { //on regarde si l'user qu'on envoie correspond à un utilisateur : admin/password IEnumerable <OutputDtoQueryUser> users = _userService.Query(); var password = _userService.HashPassword(user.Password); foreach (var userInDb in users) { if (user.Name.Equals(userInDb.Name) && password.Equals(userInDb.Password)) { var token = _tokenManager.GenerateJwtToken(userInDb); return (new OutputDtoAuthUser { Token = token }); } } return(null); }