示例#1
0
        public virtual SignInPostModel PrepareLoginModel()
        {
            var model = new SignInPostModel
            {
                DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnLoginPage
            };

            return(model);
        }
示例#2
0
        public IActionResult SignIn(SignInPostModel model, string returnUrl, bool captchaValid)
        {
            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnLoginPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (ModelState.IsValid)
            {
                Customer customer    = null;
                var      loginResult = _customerRegistrationService.ValidateCustomer(model.Username, model.Password, out customer);
                switch (loginResult)
                {
                case CustomerLoginResults.Successful:
                {
                    //sign in new customer
                    _authenticationService.SignIn(customer, model.RememberMe);

                    //raise event
                    _eventPublisher.Publish(new CustomerLoggedinEvent(customer));

                    //activity log
                    _customerActivityService.InsertActivity(customer, "PublicStore.Login", _localizationService.GetResource("ActivityLog.PublicStore.Login"));

                    if (string.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl))
                    {
                        return(RedirectToAction("Index", "Profile", new { area = "" }));
                    }

                    return(Redirect(returnUrl));
                }

                case CustomerLoginResults.CustomerNotExist:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.CustomerNotExist"));
                    break;

                case CustomerLoginResults.Deleted:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.Deleted"));
                    break;

                case CustomerLoginResults.NotActive:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.NotActive"));
                    break;

                case CustomerLoginResults.NotRegistered:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.NotRegistered"));
                    break;

                case CustomerLoginResults.LockedOut:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.LockedOut"));
                    break;

                case CustomerLoginResults.WrongPassword:
                default:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials"));
                    break;
                }
            }


            var returnModel = _customerModelFactory.PrepareLoginModel();

            returnModel.Username   = model.Username;
            returnModel.RememberMe = model.RememberMe;
            return(View(model));
        }