Example #1
0
        public ActionResult Create(UserViewModel model)
        {
            if (false == ModelState.IsValid)
            {
                return(View(model));
            }

            try
            {
                Alue71UserPrincipal newUser = new Alue71UserPrincipal(_context);
                model.DisplayName    = model.GivenName;
                model.Name           = model.GivenName + " " + model.Surname;
                model.Email          = model.GivenName + "." + model.Surname + "@alue71.local";
                model.SamAccountName = model.GivenName.ToLower() + model.Surname.ToLower();
                newUser.UpdateFromModel(model);
                newUser.SetPassword("admin");
                newUser.ExpirePasswordNow();
                newUser.Enabled = true;
                newUser.Save();

                GroupPrincipal grp = GroupPrincipal.FindByIdentity(_context, "WebNormaali");

                if (grp != null)
                {
                    grp.Members.Add(newUser);
                    grp.Save();
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                ViewBag.message = ex.Message;
                return(View(model));
            }
        }
        public IActionResult Edit(UserViewModel user)
        {
            try
            {
                Alue71UserPrincipal principal = GetPrincipal();
                principal.UpdateFromModel(user);
                principal.Save();
                ReplaceSession(principal.ToViewModel());

                return(RedirectToAction(nameof(Details)));
            }
            catch
            {
                return(View(GetUser()));
            }
        }
        public IActionResult Password(IFormCollection password)
        {
            try
            {
                Alue71UserPrincipal principal = GetPrincipal();
                if (password["New"] == password["Repeat"])
                {
                    principal.ChangePassword(password["Old"], password["New"]);
                    principal.Save();
                }

                return(RedirectToAction(nameof(Details)));
            }
            catch (Exception ex)
            {
                ViewBag.message = ex.Message;
                return(View("Edit", GetUser()));
            }
        }
Example #4
0
        public ActionResult Edit(UserViewModel user)
        {
            try
            {
                Alue71UserPrincipal model = new Alue71UserPrincipal(_context);
                model.SamAccountName = user.SamAccountName;

                PrincipalSearcher   searcher = new PrincipalSearcher(model);
                Alue71UserPrincipal edituser = (Alue71UserPrincipal)searcher.FindOne();
                edituser.UpdateFromModel(user);
                edituser.Save();

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                ViewBag.message = ex.Message;
                return(View(user));
            }
        }