public async Task <IActionResult> SignIn(SignInViewModel signInModel) { if (!ModelState.IsValid) { return(View()); } var res = await _signIn.Handle(signInModel); if (res.StatusCode != 200) { return(View()); } CookieOptions cookie = new CookieOptions(); cookie.Expires = DateTime.Now.AddDays(3); Response.Cookies.Append("Session", res.SessionId, cookie); Response.Cookies.Append("UserName", res.UserName, cookie); //var user = await _dbContext.Users.Include(p => p.Role).FirstOrDefaultAsync(p => p.PhoneNumber == signInModel.PhoneNumber); //var session = _sessionManagementService.AddSession(user.Id); //HttpContext.Session.SetString("SessionId", session); //HttpContext.Session.SetString("UserName", user.Name); //ViewBag.UserName = user.Name; //ViewBag.User = user.Name; return(RedirectToRoute(new { controller = res.Route.Key, action = res.Route.Value })); }
public async Task Should_Returns_User_When_SuccessOnSingIn() { var command = new SignInQuery { Email = EMAIL, Password = PASSWORD }; _authRepository.GetUserByEmail(Arg.Any <string>()).Returns(new User(OBJECT_ID, NAME, EMAIL, PASSWORD, PHONES, DateTime.UtcNow, DateTime.UtcNow, DateTime.UtcNow, TOKEN)); _authRepository.Authenticate(Arg.Any <string>(), Arg.Any <string>()).Returns(new User(OBJECT_ID, NAME, EMAIL, PASSWORD, PHONES, DateTime.UtcNow, DateTime.UtcNow, DateTime.UtcNow, TOKEN)); _authRepository.UpdateLastLogin(Arg.Any <User>()).Returns(new User(OBJECT_ID, NAME, EMAIL, PASSWORD, PHONES, DateTime.UtcNow, DateTime.UtcNow, DateTime.UtcNow, TOKEN)); var actual = await _handler.Handle(command, CancellationToken.None); Assert.NotNull(actual); Assert.True(actual.IsSuccess); Assert.NotNull(actual.Value.User); Assert.Equal(actual.Value.User.Email, EMAIL); Assert.Equal(actual.Value.User.Name, NAME); }