Ejemplo n.º 1
0
        public ActionResult PCreateUser(CreateModel cModel)
        {
            ADInfo adinfo  = new ADInfo();
            var    OUgroup = adinfo.GetOU();

            cModel.OrgUnit = adinfo.GetSelectListItems(OUgroup);
            string test = cModel.SelectedOU;

            if (ModelState.IsValid)
            {
                try
                {
                    using (UserPrincipal uP = adinfo.GetUser(cModel.SamAccountName, false))
                    {
                        if (uP == null)
                        {
                            PrincipalContext ctx = new PrincipalContext(ContextType.Domain,
                                                                        "newgate-software.local",
                                                                        "ou=" + cModel.SelectedOU + ",dc=newgate-software,dc=local",
                                                                        "NEWGATE-SOFTWAR\\Administrator",
                                                                        "P@ssw0rd123");
                            UserPrincipal newUser = new UserPrincipal(ctx, cModel.SamAccountName, cModel.Password, true)
                            {
                                GivenName            = cModel.DisplayName,
                                PasswordNeverExpires = true,
                                Enabled = true
                            };
                            newUser.Save();

                            ViewBag.Message = "Success";
                            ModelState.Clear();
                            return(PartialView("_CreateUser", cModel));
                        }
                        else
                        {
                            ViewBag.Message = "Username existed";
                            ModelState.Clear();
                            return(PartialView("_CreateUser", cModel));
                        }
                    }
                }
                catch (Exception e)
                {
                    ViewBag.Message = e.Message + e.StackTrace + e.InnerException;
                    ModelState.Clear();
                    return(PartialView("_CreateUser", cModel));
                }
            }
            return(PartialView("_CreateUser", cModel));
        }
Ejemplo n.º 2
0
        // GET: /Home/Details/
        public ActionResult GetDetails(string name)
        {
#if DEBUG
            UserInfo userInfo = new UserInfo
            {
                Name   = name,
                Info   = "info",
                Status = true
            };
#else
            ADInfo        adinfo   = new ADInfo();
            UserPrincipal uP       = adinfo.GetUser(name, false);
            var           status   = uP.Enabled ?? false;
            UserInfo      userInfo = new UserInfo
            {
                Name   = uP.SamAccountName,
                Info   = adinfo.GetOUForUser(name),
                Status = status
            };
#endif
            return(PartialView("Details", userInfo));
        }
Ejemplo n.º 3
0
        public ActionResult ResetPass(ResetModel rModel)
        {
            if (ModelState.IsValid)
            {
#if DEBUG
                Debug.WriteLine("Thread sleep now");
                Thread.Sleep(2000);
                Debug.WriteLine("Thread after");
#else
                try
                {
                    ADInfo adinfo = new ADInfo();
                    using (UserPrincipal uP = adinfo.GetUser(rModel.SamAccountName, true))
                    {
                        if (uP != null)
                        {
                            uP.SetPassword(rModel.Password);
                            uP.Save();
                            ViewBag.Message = "Success";
                            ModelState.Clear();
                            return(PartialView("_ResetPassword"));
                        }
                        ViewBag.Message = "User Not Found";
                        ModelState.Clear();
                        return(PartialView("_ResetPassword", rModel));
                    }
                }
                catch (Exception e)
                {
                    ViewBag.Message = e.Message + e.StackTrace + e.InnerException;
                    ModelState.Clear();
                    return(PartialView("_ResetPassword", rModel));
                }
#endif
            }
            return(PartialView("_ResetPassword", rModel));
        }