public async Task <ActionResult> InternalLogin(LoginViewModel viewModel) { var returnUrl = GetSafeReturnUrl(Request.UrlReferrer); if (!ModelState.IsValid) { return(Json(new { success = false, errors = ModelState.Keys .SelectMany(k => ModelState[k].Errors) .Select(m => m.ErrorMessage).ToArray() })); } var user = _customerService.GetSiteUser(viewModel.Email); if (user != null) { var result = await _customerService.SignInManager().PasswordSignInAsync(user.UserName, viewModel.Password, viewModel.RememberMe, shouldLockout: true); switch (result) { case SignInStatus.Success: _campaignService.UpdateLastLoginDate(viewModel.Email); TrackingCookieManager.SetTrackingCookie(user.Id); break; case SignInStatus.LockedOut: throw new Exception("Account is locked out."); default: ModelState.AddModelError("LoginViewModel.Password", _localizationService.GetString("/Login/Form/Error/WrongPasswordOrEmail", "You have entered wrong username or password")); return(Json(new { success = false, errors = ModelState.Keys .SelectMany(k => ModelState[k].Errors) .Select(m => m.ErrorMessage).ToArray() })); } return(Json(new { success = true, returnUrl = viewModel.ReturnUrl })); } ModelState.AddModelError("LoginViewModel.Password", _localizationService.GetString("/Login/Form/Error/WrongPasswordOrEmail", "You have entered wrong username or password")); return(Json(new { success = false, errors = ModelState.Keys .SelectMany(k => ModelState[k].Errors) .Select(m => m.ErrorMessage).ToArray() })); }
public async Task <ActionResult> RegisterAccount(RegisterAccountViewModel viewModel) { if (!ModelState.IsValid) { return(Json(new { success = false, errors = ModelState.Keys .SelectMany(k => ModelState[k].Errors) .Select(m => m.ErrorMessage).ToArray() })); } viewModel.Address.BillingDefault = true; viewModel.Address.ShippingDefault = true; viewModel.Address.Email = viewModel.Email; var user = new SiteUser { UserName = viewModel.Email, Email = viewModel.Email, Password = viewModel.Password, FirstName = viewModel.Address.FirstName, LastName = viewModel.Address.LastName, RegistrationSource = "Registration page", NewsLetter = viewModel.Newsletter, IsApproved = true }; var registration = await _customerService.CreateUser(user); if (registration.IdentityResult.Succeeded) { if (registration.FoundationContact != null) { _addressBookService.Save(viewModel.Address, registration.FoundationContact); } TrackingCookieManager.SetTrackingCookie(registration.FoundationContact.UserId); return(new EmptyResult()); } else { return(Json(new { success = false, errors = registration.IdentityResult.Errors })); } }
public ActionResult Login(string userName, string returnUrl) { _customerService.SignOut(); var user = _customerService.UserManager().FindByEmailAsync(userName).GetAwaiter().GetResult(); if (user == null) { return(new EmptyResult()); } _customerService.SignInManager().SignIn(user, true, true); //set tracking cookie TrackingCookieManager.SetTrackingCookie(user.Id); return(Redirect(returnUrl)); }
public virtual void SignOut() { AuthenticationManager().SignOut(); TrackingCookieManager.SetTrackingCookie(Guid.NewGuid().ToString()); }
public ActionResult SignOut() { _userService.SignOut(); TrackingCookieManager.SetTrackingCookie(Guid.NewGuid().ToString()); return(RedirectToAction("Index", new { node = ContentReference.StartPage })); }