Beispiel #1
0
        public ActionResult Create(int[] roleIds)
        {
            User newUser = new User();

            try
            {
                UpdateModel(newUser, new [] { "UserName", "FirstName", "LastName", "Email", "Website", "IsActive", "TimeZone" });
                newUser.Password             = CuyahogaUser.HashPassword(Request.Form["Password"]);
                newUser.PasswordConfirmation = CuyahogaUser.HashPassword(Request.Form["PasswordConfirmation"]);
                if (roleIds != null && roleIds.Length > 0)
                {
                    IList <Role> roles = this._userService.GetRolesByIds(roleIds);
                    foreach (Role role in roles)
                    {
                        newUser.Roles.Add(role);
                    }
                }

                if (ValidateModel(newUser))
                {
                    this._userService.CreateUser(newUser);
                    Messages.AddFlashMessageWithParams("UserCreatedMessage", newUser.UserName);
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                Messages.AddException(ex);
            }
            ViewData["Roles"]     = this._userService.GetAllRolesBySite(CuyahogaContext.CurrentSite);
            ViewData["TimeZones"] = new SelectList(TimeZoneUtil.GetTimeZones(), "Key", "Value", newUser.TimeZone);
            return(View("NewUser", newUser));
        }
Beispiel #2
0
        /// <summary>
        /// Generates a new password and stores a hashed password in the User instance.
        /// </summary>
        /// <returns>The newly created password.</returns>
        public virtual string GeneratePassword()
        {
            int    length = 8;
            string chars  = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
            string pwd    = String.Empty;
            Random rnd    = new Random();

            for (int i = 0; i < length; i++)
            {
                pwd += chars[rnd.Next(chars.Length)];
            }
            this._password = User.HashPassword(pwd);
            return(pwd);
        }
Beispiel #3
0
        public ActionResult ChangePassword(int id, string password, string passwordConfirmation)
        {
            User user = this._userService.GetUserById(id);

            try
            {
                user.Password             = CuyahogaUser.HashPassword(password);
                user.PasswordConfirmation = CuyahogaUser.HashPassword(passwordConfirmation);

                if (ValidateModel(user, new[] { "Password", "PasswordConfirmation" }))
                {
                    this._userService.UpdateUser(user);
                    Messages.AddMessage("PasswordChangedMessage");
                }
            }
            catch (Exception ex)
            {
                Messages.AddException(ex);
            }
            ViewData["Roles"]     = this._userService.GetAllRolesBySite(CuyahogaContext.CurrentSite);
            ViewData["TimeZones"] = new SelectList(TimeZoneUtil.GetTimeZones(), "Key", "Value", user.TimeZone);
            return(View("EditUser", user));
        }