Advertisement
Guest User

Untitled

a guest
Apr 6th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. public virtual ActionResult Index(LoginModel model)
  2. {
  3. if (ModelState.IsValid)
  4. {
  5. model.Username = model.Username.Trim();
  6.  
  7. var loginResult = _customerRegistrationService.ValidateCustomer(model.Username, model.Password);
  8.  
  9. switch (loginResult)
  10. {
  11. case CustomerLoginResults.Successful:
  12. {
  13. var customer = model.Username.Contains("@") ?
  14. _customerService.GetCustomerByEmail(model.Username) :
  15. _customerService.GetCustomerByUsername(model.Username);
  16.  
  17. if (customer.IsAdmin())
  18. {
  19. _authenticationService.SignIn(customer, model.RememberMe);
  20. return Redirect("~/Admin");
  21. }
  22. break;
  23. }
  24. case CustomerLoginResults.CustomerNotExist:
  25. ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.CustomerNotExist"));
  26. break;
  27. case CustomerLoginResults.Deleted:
  28. ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.Deleted"));
  29. break;
  30. case CustomerLoginResults.NotActive:
  31. ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.NotActive"));
  32. break;
  33. case CustomerLoginResults.NotRegistered:
  34. ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.NotRegistered"));
  35. break;
  36. case CustomerLoginResults.LockedOut:
  37. ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.LockedOut"));
  38. break;
  39. case CustomerLoginResults.WrongPassword:
  40. default:
  41. ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials"));
  42. break;
  43. }
  44. }
  45. return View(model);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement