コード例 #1
0
        /// <summary>
        /// Creates a new user account
        /// </summary>
        /// <param name="username">A unique username</param>
        /// <param name="password">A hopefully secure password</param>
        /// <param name="email">A unique email address</param>
        /// <param name="roles"></param>
        /// <returns></returns>
        public JsonResult Create(CreateUserViewModel userViewModel)
        {
            MyJsonResult result;

            if (ModelState.IsValid)
            {
                ApplicationUser user;
                IdentityResult  res = _userAccountService.CreateUser(userViewModel.Email, userViewModel.Password, userViewModel.roles, out user);

                if (res.Succeeded)
                {
                    result = new MyJsonResult()
                    {
                        data      = user,
                        isSuccess = true
                    };
                }
                else
                {
                    ModelState.AddModelError("", res.Errors.First());
                    result = MyJsonResult.CreateError(string.Format("Error on adding user {0} to the database: ", userViewModel.Email) + res.Errors);
                }
            }
            else
            {
                result = MyJsonResult.CreateError(string.Format("Error on adding user {0} to the database: ", userViewModel.Email) + "Invalid user model.");
            }
            return(Json(result));
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: mohammedkhizar/Eportal
        static void createUser()
        {
            IUserAccountService    userAccountService = new UserAccountService(_connectionString);
            MembershipCreateStatus createStatus;

            string         username = "******";
            MembershipUser user     = userAccountService.CreateUser(username, "ayesha", "*****@*****.**", null, "power button user", out createStatus);

            logger.Info("Creating user, " + username);
            logger.Info("create status for user " + username + " is " + createStatus.ToString());
        }
コード例 #3
0
        public ActionResult CreateUser(CreateAccount ca)
        {
            if (ModelState.IsValid)
            {
                int code = _uas.CreateUser(ca);
                switch (code)
                {
                case 1:
                {
                    ViewBag.CreateUser = "******";
                    break;
                }

                case 2:
                {
                    ViewBag.CreateUser = "******";
                    break;
                }

                case 3:
                {
                    ViewBag.CreateUser = "******";
                    break;
                }

                case 4:
                {
                    ViewBag.AuthError = "Username already exists.";
                    return(View(ca));
                }

                case 5:
                {
                    ViewBag.EmailError = "Email already exists.";
                    return(View(ca));
                }
                }
                return(RedirectToAction("Users"));
            }
            return(View(ca));
        }
コード例 #4
0
        private void CreateGod()
        {
            UserAccount god = m_UserAccountService.GetUserAccount(UUID.Zero, m_WebApp.AdminFirst, m_WebApp.AdminLast);

            if (god == null)
            {
                m_log.DebugFormat("[Wifi]: Administrator account {0} {1} does not exist. Creating it...", m_WebApp.AdminFirst, m_WebApp.AdminLast);
                // Doesn't exist. Create one
                god = m_UserAccountService.CreateUser(UUID.Zero, UUID.Random(), m_WebApp.AdminFirst, m_WebApp.AdminLast, m_WebApp.AdminPassword, m_WebApp.AdminEmail);

                god.UserLevel = m_WebApp.AdminUserLevel;
                god.UserTitle = "Administrator";
                god.UserFlags = 0;
                m_UserAccountService.StoreUserAccount(god);
                if (m_WebApp.AdminPassword == string.Empty)
                {
                    // Signal that the App needs installation
                    m_WebApp.IsInstalled = false;
                }
                else
                {
                    m_WebApp.IsInstalled = true;
                }
            }
            else
            {
                m_log.DebugFormat("[Wifi]: Administrator account {0} {1} exists.", m_WebApp.AdminFirst, m_WebApp.AdminLast);
                // Signal that the App has been previously installed
                m_WebApp.IsInstalled = true;
            }

            if (god.UserLevel < m_WebApp.AdminUserLevel)
            {
                // Might have existed but had wrong UserLevel
                god.UserLevel = m_WebApp.AdminUserLevel;
                m_UserAccountService.StoreUserAccount(god);
            }
        }
コード例 #5
0
 public void CreateUser(string name, string md5password, string email)
 {
     m_localService.CreateUser(name, md5password, email);
 }