public LoginUserResponse LoginUser(LoginUserRequest request) { var response = new LoginUserResponse { HasIssues = false, ErrorMessage = string.Empty }; var customer = _customerRepository.FindByEmailAddress(request.EmailAddress); if (customer == null) { response.HasIssues = true; response.ErrorMessage = string.Format("We were unable to locate a user with the email address: {0}. Please try again.", request.EmailAddress); return response; } if (!_encryptor.Validate(request.Password, customer.UserLogin.Password)) { response.HasIssues = true; response.ErrorMessage = "Invalid password. Please try again."; return response; } customer.UserLogin.IsAuthenticated = true; response.CustomerId = customer.Id.ToString(); response.UserLogin = customer.UserLogin.ConvertToUserLoginView(); response.FirstName = customer.FirstName; response.LastName = customer.LastName; return response; }
private HttpCookie SetLoginCookie(LoginUserResponse response) { var customPrincipalViewModel = new CustomPrincipalViewModel { Id = response.UserLogin.Id, FirstName = response.FirstName, LastName = response.LastName }; var userData = new JavaScriptSerializer().Serialize(customPrincipalViewModel); var authTicket = new FormsAuthenticationTicket(1, response.CustomerId, DateTime.Now, DateTime.Now.AddMinutes(60), false, userData); var encryptedTicket = _formsAuthentication.Encrypt(authTicket); return new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket) { HttpOnly = true, Expires = authTicket.Expiration }; }