Exemplo n.º 1
0
        public ActionResult RegisterUser(RegisterUserModel model, string[] Companies, string[] Permissions)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    Roles.AddUserToRoles(model.UserName, Companies);
                    Roles.AddUserToRoles(model.UserName, Permissions);
                    FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                    User newUser = new User();
                    newUser.Username = model.UserName;
                    newUser.UserId   = secRep.GetUserId(model.UserName);
                    newUser          = secRep.AddUser(newUser);

                    Account_Rep.SetUserLogin(model.UserName);

                    return(RedirectToAction("Home", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult AddUser(string Username, string Password, string CompanyName)
        {
            // Attempt to register the user
            MembershipCreateStatus createStatus;

            Membership.CreateUser(Username, Password, "*****@*****.**", null, null, true, null, out createStatus);

            if (createStatus == MembershipCreateStatus.Success)
            {
                string[] companies   = { "u_" + CompanyName };
                string[] permissions = { "p_admin" };
                Roles.AddUserToRoles(Username, companies);
                Roles.AddUserToRoles(Username, permissions);

                User newUser = new User();
                newUser.Username = Username;
                newUser.UserId   = secRep.GetUserId(Username);
                newUser          = secRep.AddUser(newUser);

                if (newUser.UserKey == 0)
                {
                    return(Content("Fail User", "text/html"));
                }
                else
                {
                    return(Content("Success User", "text/html"));
                }
            }
            else
            {
                return(Content("Fail User", "text/html"));
            }
        }