Пример #1
0
        public virtual ActionResult Login(LoginViewModel loginViewModel)
        {
            var model = _loginViewModelBuilder.Build(loginViewModel);

            model.RedirectUrl = loginViewModel.RedirectUrl;

            if (!_loginService.IsValidLoginForm(_modelState, model.LoginForm))
            {
                return(View(model));
            }

            try
            {
                var loginSuccessfull = _loginService.Login(model.LoginForm.UserName, model.LoginForm.Password, out var token);
                if (loginSuccessfull)
                {
                    var person = _loginService.GetUser(model.LoginForm.UserName);

                    if (!_loginService.IsBusinessCustomer(person, out var organizations))
                    {
                        var addressType = _addressTypeService.Get(AddressTypeNameConstants.Address);
                        var address     = person.Addresses.FirstOrDefault(x => x.AddressTypeSystemId == addressType.SystemId);
                        //Check if user has the same country in the address as channel has.
                        if (address != null && !string.IsNullOrEmpty(address.Country) && !address.Country.Equals(_requestModelAccessor.RequestModel.CountryModel.Country.Id, StringComparison.CurrentCultureIgnoreCase))
                        {
                            var country = _countryService.Get(address.Country);
                            //Check if country is connected to the channel
                            if (country != null && _requestModelAccessor.RequestModel.ChannelModel.Channel.CountryLinks.Any(x => x.CountrySystemId == country.SystemId))
                            {
                                // Set user's country to the channel
                                _requestModelAccessor.RequestModel.Cart.SetChannel(_requestModelAccessor.RequestModel.ChannelModel.Channel, country, SecurityToken.CurrentSecurityToken);
                            }
                        }
                        return(new RedirectResult(model.RedirectUrl));
                    }
                    if (organizations.Count <= 1)
                    {
                        return(new RedirectResult(model.RedirectUrl));
                    }
                    model.Organizations = _loginViewModelBuilder.GetOrganizations(organizations);
                    return(View(nameof(SelectOrganization), model));
                }
                model.ErrorMessage = "login.failed".AsWebSiteString();
            }
            catch (ChangePasswordException)
            {
                return(View(nameof(ChangePassword), model));
            }

            return(View(model));
        }
Пример #2
0
        public virtual ActionResult SelectOrganization(string redirectUrl)
        {
            var model           = new LoginViewModel();
            var currentPersonId = _securityContextService.GetIdentityUserSystemId();

            if (currentPersonId.HasValue)
            {
                var person = _personService.Get(currentPersonId.Value);
                if (_loginService.IsBusinessCustomer(person, out var organizations))
                {
                    model.Organizations = _loginViewModelBuilder.GetOrganizations(organizations);
                    model.RedirectUrl   = redirectUrl;
                    return(View(model));
                }
            }

            return(View(model));
        }