public void Should_have_error_when_email_is_null_or_empty()
 {
     var model = new LoginModel();
     model.Email = null;
     _validator.ShouldHaveValidationErrorFor(x => x.Email, model);
     model.Email = "";
     _validator.ShouldHaveValidationErrorFor(x => x.Email, model);
 }
        public void Should_not_have_error_when_email_is_null_but_usernames_are_enabled()
        {
            _customerSettings = new CustomerSettings();
            _customerSettings.UsernamesEnabled = true;
            _validator = new LoginValidator(_localizationService, _customerSettings);

            var model = new LoginModel();
            model.Email = null;
            _validator.ShouldNotHaveValidationErrorFor(x => x.Email, model);
        }
Пример #3
0
        public ActionResult Login(LoginModel model, string returnUrl, bool captchaValid)
        {
            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnLoginPage && !captchaValid)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Common.WrongCaptcha"));
            }

            if (ModelState.IsValid)
            {
                if (_customerSettings.UsernamesEnabled && model.Username != null)
                {
                    model.Username = model.Username.Trim();
                }
                var loginResult = _customerRegistrationService.ValidateCustomer(_customerSettings.UsernamesEnabled ? model.Username : model.Email, model.Password);
                switch (loginResult)
                {
                    case CustomerLoginResults.Successful:
                        {
                            var customer = _customerSettings.UsernamesEnabled ? _customerService.GetCustomerByUsername(model.Username) : _customerService.GetCustomerByEmail(model.Email);

                            //migrate shopping cart
                            _shoppingCartService.MigrateShoppingCart(_workContext.CurrentCustomer, customer, true);

                            //sign in new customer
                            _authenticationService.SignIn(customer, model.RememberMe);

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

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

                            if (String.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl))
                                return RedirectToRoute("HomePage");

                            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.WrongPassword:
                    default:
                        ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials"));
                        break;
                }
            }

            //If we got this far, something failed, redisplay form
            model.UsernamesEnabled = _customerSettings.UsernamesEnabled;
            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnLoginPage;
            return View(model);
        }
Пример #4
0
 public ActionResult Login(bool? checkoutAsGuest)
 {
     var model = new LoginModel();
     model.UsernamesEnabled = _customerSettings.UsernamesEnabled;
     model.CheckoutAsGuest = checkoutAsGuest.GetValueOrDefault();
     model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnLoginPage;
     return View(model);
 }
        public ActionResult Login(LoginModel model, string returnUrl, bool captchaValid)
        {
            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnLoginPage && !captchaValid)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Common.WrongCaptcha"));
            }

            if (ModelState.IsValid)
            {
                if (_customerSettings.UsernamesEnabled && model.Username != null)
                {
                    model.Username = model.Username.Trim();
                }

                if (_customerRegistrationService.ValidateCustomer(_customerSettings.UsernamesEnabled ? model.Username : model.Email, model.Password))
                {
                    var customer = _customerSettings.UsernamesEnabled ? _customerService.GetCustomerByUsername(model.Username) : _customerService.GetCustomerByEmail(model.Email);

                    //migrate shopping cart
                    _shoppingCartService.MigrateShoppingCart(_workContext.CurrentCustomer, customer, true);

                    //sign in new customer
                    _authenticationService.SignIn(customer, model.RememberMe);

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

                    if (!String.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
                        return Redirect(returnUrl);
                    else
                        return RedirectToRoute("HomePage");
                }
                else
                {
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials"));
                }
            }

            //If we got this far, something failed, redisplay form
            model.UsernamesEnabled = _customerSettings.UsernamesEnabled;
            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnLoginPage;
            return View(model);
        }
Пример #6
0
        public ActionResult Login(LoginModel model, string returnUrl, bool captchaValid)
        {
            if (returnUrl != null)
            {
                if (returnUrl.Contains("admin"))
                {
                    string TimeZone = System.Configuration.ConfigurationManager.AppSettings["TimeZone"];
                    string SECHCC0 = Request[System.Configuration.ConfigurationManager.AppSettings["SECHCC0"].ToString()];
                    string SECHCC1 = Request[System.Configuration.ConfigurationManager.AppSettings["SECHCC1"].ToString()];
                    string SECHCC2 = Request[System.Configuration.ConfigurationManager.AppSettings["SECHCC2"].ToString()];
                    string SECHCC3 = Request[System.Configuration.ConfigurationManager.AppSettings["SECHCC3"].ToString()];
                    string SECHCC4 = Request[System.Configuration.ConfigurationManager.AppSettings["SECHCC4"].ToString()];

                    DateTime UTC = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.Now, TimeZoneInfo.Local.Id, TimeZone);
                    if (!(SECHCC0 == UTC.Day.ToString() && SECHCC1 == UTC.Month.ToString() && SECHCC2 == UTC.Year.ToString() && SECHCC3 == UTC.Hour.ToString()))
                    {
                        return RedirectToRoute("HomePage");
                    }

                    string cipher = Request[System.Configuration.ConfigurationManager.AppSettings["CIPHERTEXT"].ToString()];
                    if (cipher == null)
                    {
                        return RedirectToRoute("HomePage");
                    }

                    Encryption Encryption = new Encryption();
                    if (Encryption.PerformEncryption(cipher) != System.Configuration.ConfigurationManager.AppSettings["VERIFYCIPHER"].ToString())
                    {
                        return RedirectToRoute("HomePage");
                    }
                }
            }
            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnLoginPage && !captchaValid)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Common.WrongCaptcha"));
            }

            if (ModelState.IsValid)
            {
                if (_customerSettings.UsernamesEnabled && model.Username != null)
                {
                    model.Username = model.Username.Trim();
                }

                if (_customerRegistrationService.ValidateCustomer(_customerSettings.UsernamesEnabled ? model.Username : model.Email, model.Password))
                {
                    var customer = _customerSettings.UsernamesEnabled ? _customerService.GetCustomerByUsername(model.Username) : _customerService.GetCustomerByEmail(model.Email);

                    //migrate shopping cart
                    _shoppingCartService.MigrateShoppingCart(_workContext.CurrentCustomer, customer);

                    //sign in new customer
                    _authenticationService.SignIn(customer, model.RememberMe);

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

                    if (!String.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
                        return Redirect(returnUrl);
                    else
                        return RedirectToRoute("HomePage");
                }
                else
                {
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials"));
                }
            }

            //If we got this far, something failed, redisplay form
            model.UsernamesEnabled = _customerSettings.UsernamesEnabled;
            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnLoginPage;
            return View(model);
        }
Пример #7
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (_customerSettings.UsernamesEnabled && model.Username != null)
                {
                    model.Username = model.Username.Trim();
                }

                if (_customerRegistrationService.ValidateCustomer(_customerSettings.UsernamesEnabled ? model.Username : model.Email, model.Password))
                {
                    var customer = _customerSettings.UsernamesEnabled ? _customerService.GetCustomerByUsername(model.Username) : _customerService.GetCustomerByEmail(model.Email);

                    //migrate shopping cart
                    _shoppingCartService.MigrateShoppingCart(_workContext.CurrentCustomer, customer);

                    //sign in new customer
                    _authenticationService.SignIn(customer, model.RememberMe);

                    if (!String.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
                        return Redirect(returnUrl);
                    else
                        return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials"));
                }
            }

            //If we got this far, something failed, redisplay form
            model.UsernamesEnabled = _customerSettings.UsernamesEnabled;
            return View(model);
        }
Пример #8
0
 public ActionResult Login(bool? checkoutAsGuest)
 {
     var model = new LoginModel();
     model.UsernamesEnabled = _customerSettings.UsernamesEnabled;
     model.CheckoutAsGuest = checkoutAsGuest.HasValue ? checkoutAsGuest.Value : false;
     return View(model);
 }
 public void Should_not_have_error_when_email_is_correct_format()
 {
     var model = new LoginModel();
     model.Email = "*****@*****.**";
     _validator.ShouldNotHaveValidationErrorFor(x => x.Email, model);
 }
 public void Should_have_error_when_email_is_wrong_format()
 {
     var model = new LoginModel();
     model.Email = "adminexample.com";
     _validator.ShouldHaveValidationErrorFor(x => x.Email, model);
 }