コード例 #1
0
        public virtual IActionResult Login(LoginModel model, string returnUrl, bool captchaValid)
        {
            var username = _encryptionService.EncryptText(model.Email);
            var password = _encryptionService.EncryptText(model.Password);

            if (ModelState.IsValid)
            {
                var loginResult = _customerRegistrationService.ValidateCustomerLogin(model.Email, model.Password);
                switch (loginResult)
                {
                case CustomerLoginResults.Successful:
                {
                    var customer = _customerService.GetCustomerByEmail(_encryptionService.EncryptText(model.Email));

                    _authenticationService.SignIn(customer, model.RememberMe);

                    if (string.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl))
                    {
                        NotificationMessage.msgLoginSuccessfull = "Welcome Back !" + " " + _encryptionService.DecryptText(_WorkContextService.CurrentCustomer.BillingAddress.FirstName) + "" + _encryptionService.DecryptText(_WorkContextService.CurrentCustomer.BillingAddress.LastName);
                        AddNotification(NotificationMessage.TitleSuccess, NotificationMessage.msgLoginSuccessfull, NotificationMessage.TypeSuccess);

                        return(Redirect("/Home/Index"));
                    }
                    return(Redirect(returnUrl));
                }

                case CustomerLoginResults.CustomerNotExist:
                    ModelState.AddModelError("", "CustomerNotExist");
                    break;

                case CustomerLoginResults.Deleted:
                    ModelState.AddModelError("", "Deleted");
                    break;

                case CustomerLoginResults.NotActive:
                    ModelState.AddModelError("", "NotActive");
                    break;

                case CustomerLoginResults.NotRegistered:
                    ModelState.AddModelError("", "NotRegistered");
                    break;

                case CustomerLoginResults.LockedOut:
                    ModelState.AddModelError("", "LockedOut.Try after 10 min");
                    break;

                case CustomerLoginResults.WrongPassword:
                default:
                    ModelState.AddModelError("", "WrongCredentials");
                    break;
                }
            }
            return(View(model));
        }