コード例 #1
0
ファイル: UsersController.cs プロジェクト: dkahari/Foundation
        private void SaveUser(UsersPageViewModel viewModel)
        {
            var contactUser = new SiteUser
            {
                UserName           = viewModel.Contact.Email,
                Email              = viewModel.Contact.Email,
                Password           = "******",
                FirstName          = viewModel.Contact.FirstName,
                LastName           = viewModel.Contact.LastName,
                RegistrationSource = "Registration page"
            };

            _userManager.Create(contactUser);

            _customerService.CreateContact(viewModel.Contact, contactUser.Id);

            var user = _userManager.FindByName(viewModel.Contact.Email);

            if (user != null)
            {
                var startPage = _contentLoader.Get <CommerceHomePage>(ContentReference.StartPage);
                var body      = _mailService.GetHtmlBodyForMail(startPage.ResetPasswordMail, new NameValueCollection(), ContentLanguage.PreferredCulture.TwoLetterISOLanguageName);
                var mailPage  = _contentLoader.Get <MailBasePage>(startPage.ResetPasswordMail);
                var code      = _userManager.GeneratePasswordResetToken(user.Id);
                var url       = Url.Action("ResetPassword", "ResetPassword", new { userId = user.Id, code = HttpUtility.UrlEncode(code), language = ContentLanguage.PreferredCulture.TwoLetterISOLanguageName }, Request.Url.Scheme);

                body = body.Replace("[MailUrl]",
                                    string.Format("{0}<a href=\"{1}\">{2}</a>",
                                                  _localizationService.GetString("/ResetPassword/Mail/Text"),
                                                  url,
                                                  _localizationService.GetString("/ResetPassword/Mail/Link")));

                _mailService.Send(mailPage.MailTitle, body, user.Email);
            }
        }
コード例 #2
0
        public ActionResult Index(UsersPage currentPage)
        {
            if (TempData["ImpersonateFail"] != null)
            {
                ViewBag.Impersonate = (bool)TempData["ImpersonateFail"];
            }

            var organization               = _organizationService.GetCurrentFoundationOrganization();
            var currentOrganization        = organization;
            var currentOrganizationContext = _cookieService.Get(Constant.Fields.SelectedSuborganization);

            if (currentOrganizationContext != null)
            {
                currentOrganization = _organizationService.GetFoundationOrganizationById(currentOrganizationContext);
            }

            var viewModel = new UsersPageViewModel
            {
                CurrentContent = currentPage,
                Users          = _customerService.GetContactsForOrganization(currentOrganization),
                Organizations  = organization?.SubOrganizations ?? new List <FoundationOrganization>()
            };

            if (currentOrganization.SubOrganizations.Any())
            {
                foreach (var subOrg in currentOrganization.SubOrganizations)
                {
                    var contacts = _customerService.GetContactsForOrganization(subOrg);
                    viewModel.Users.AddRange(contacts);
                }
            }

            return(View(viewModel));
        }
コード例 #3
0
        public ActionResult AddUser(UsersPageViewModel viewModel)
        {
            var user = _userManager.FindByEmail(viewModel.Contact.Email);

            if (user != null)
            {
                var contact      = _customerService.GetContactByEmail(user.Email);
                var organization = _organizationService.GetCurrentFoundationOrganization();
                if (_customerService.HasOrganization(contact.ContactId.ToString()))
                {
                    viewModel.Contact.ShowOrganizationError = true;
                    viewModel.Organizations = organization.SubOrganizations ?? new List <FoundationOrganization>();
                    return(View(viewModel));
                }

                var organizationId             = organization.OrganizationId.ToString();
                var currentOrganizationContext = _cookieService.Get(Constant.Fields.SelectedSuborganization);
                if (currentOrganizationContext != null)
                {
                    organizationId = currentOrganizationContext;
                }

                _customerService.AddContactToOrganization(contact, organizationId);
                _customerService.UpdateContact(contact.ContactId.ToString(), viewModel.Contact.UserRole, viewModel.Contact.UserLocationId);
            }
            else
            {
                SaveUser(viewModel);
            }

            return(RedirectToAction("Index"));
        }
コード例 #4
0
ファイル: UsersController.cs プロジェクト: dkahari/Foundation
        public ActionResult AddUser(UsersPage currentPage)
        {
            var organization = _organizationService.GetCurrentFoundationOrganization();
            var viewModel    = new UsersPageViewModel
            {
                CurrentContent = currentPage,
                Contact        = FoundationContact.New(),
                Organizations  = organization?.SubOrganizations ?? new List <FoundationOrganization>()
            };

            return(View(viewModel));
        }
コード例 #5
0
ファイル: UsersController.cs プロジェクト: dkahari/Foundation
        public ActionResult Index(UsersPage currentPage)
        {
            var organization = _organizationService.GetCurrentFoundationOrganization();
            var viewModel    = new UsersPageViewModel
            {
                CurrentContent = currentPage,
                Users          = _customerService.GetContactsForOrganization(),
                Organizations  = organization?.SubOrganizations ?? new List <FoundationOrganization>()
            };

            if (viewModel.Organizations.Any())
            {
                foreach (var subOrg in viewModel.Organizations)
                {
                    var contacts = _customerService.GetContactsForOrganization(subOrg);
                    viewModel.Users.AddRange(contacts);
                }
            }

            return(View(viewModel));
        }
コード例 #6
0
ファイル: UsersController.cs プロジェクト: dkahari/Foundation
        public ActionResult EditUser(UsersPage currentPage, string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(RedirectToAction("Index"));
            }

            var organization = _organizationService.GetCurrentFoundationOrganization();
            var contact      = _customerService.GetContactById(id);

            var viewModel = new UsersPageViewModel
            {
                CurrentContent  = currentPage,
                Contact         = contact,
                Organizations   = organization?.SubOrganizations ?? new List <FoundationOrganization>(),
                SubOrganization =
                    contact.B2BUserRole != B2BUserRoles.Admin
                        ? _organizationService.GetSubFoundationOrganizationById(contact.FoundationOrganization.OrganizationId.ToString())
                        : new SubFoundationOrganizationModel(organization)
            };

            return(View(viewModel));
        }
コード例 #7
0
ファイル: UsersController.cs プロジェクト: dkahari/Foundation
        public ActionResult AddUser(UsersPageViewModel viewModel)
        {
            var user = _userManager.FindByEmail(viewModel.Contact.Email);

            if (user != null)
            {
                if (_customerService.HasOrganization(user.Id))
                {
                    viewModel.Contact.ShowOrganizationError = true;
                    var organization = _organizationService.GetCurrentFoundationOrganization();
                    viewModel.Organizations = organization.SubOrganizations ?? new List <FoundationOrganization>();
                    return(View(viewModel));
                }

                _customerService.AddContactToOrganization(viewModel.Contact);
                _customerService.UpdateContact(user.Id, viewModel.Contact.UserRole, viewModel.Contact.UserLocationId);
            }
            else
            {
                SaveUser(viewModel);
            }

            return(RedirectToAction("Index"));
        }
コード例 #8
0
ファイル: UsersController.cs プロジェクト: dkahari/Foundation
        public ActionResult UpdateUser(UsersPageViewModel viewModel)
        {
            _customerService.EditContact(viewModel.Contact);

            return(RedirectToAction("Index"));
        }