public ActionResult Authentication(AuthenticationPostModel postModel) { var model = new AuthenticationViewModel(); if (!ModelState.IsValid) { return(View(model)); } var userName = postModel.Username; var password = _passwordHashProvidcer.Hash(postModel.Password, _salt); var user = _unitOfWork.UserRepository.GetUserByUsernameAndPassword(userName, password); if (user != null) { FormsAuthentication.SetAuthCookie(user.UserName, false); // Not a good practice Session[SessionUserKey] = user; // Map User to Model model = new AuthenticationViewModel() { IdHashed = _encryptionProvider.Encrypt(user.Id.ToString(), _key, _vector), Name = user.Name, EMail = user.EMail.SanitizeEmail() }; } return(View(model)); }
public async Task <IActionResult> Authentication(AuthenticationPostModel request) { var serviceRepsonse = await userService.AuthenticateAsync(request.Username, request.Password); return(Ok(serviceRepsonse)); }