示例#1
0
        /// <summary>
        /// Bobby Thorne
        /// 2/12/17
        /// Update
        /// Bobby Thorne
        /// 3/10/2017
        ///
        /// This will test the Text Fields to make sure that
        /// bad data is not entered when creating a new user
        ///
        /// Update
        /// added a catch for phone number and if username is
        /// already used
        ///
        /// Updated 2017-03-22 by William Flood
        /// Refactored database call to a static method to resolve issue #22
        /// </summary>
        /// <param name="user"></param>
        /// <param name="password"></param>
        /// <param name="confirmPassword"></param>
        /// <returns></returns>
        public string CreateNewUser(User user, string password, string confirmPassword)
        {
            var result = ValidateUser(user, password, confirmPassword);

            if (result != "")
            {
                return(result);
            }
            user.PasswordSalt = RandomString(32);
            user.PasswordHash = HashSha256(password + user.PasswordSalt);

            try
            {
                if (1 == UserAccessor.CreateUser(user))
                {
                    return("Created");
                }
            }
            catch
            {
                return("UnableToCreate");
            }

            return("UnableToCreate");
        }
        public bool RegisterUser(User user)
        {
            bool result = false;

            try
            {
                bool userCreated = 1 == UserAccessor.CreateUser(user);
                if (!userCreated)
                {
                    throw new ApplicationException("User could not be created!");
                }
                else
                {
                    foreach (var role in user.Roles)
                    {
                        if (1 != UserAccessor.CreateUserRole(user.Username, role))
                        {
                            result = false;
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(result);
        }
示例#3
0
 public int AddNewUser(string firstName,
                       string lastName,
                       string zip,
                       string emailAddress,
                       string userName,
                       string passWord,
                       bool active,
                       int?regionID)
 {
     try
     {
         var usr = new User()
         {
             FirstName    = firstName,
             LastName     = lastName,
             Zip          = zip,
             EmailAddress = emailAddress,
             UserName     = userName,
             Password     = passWord,
             Active       = active,
             RegionId     = regionID
         };
         return(UserAccessor.CreateUser(usr));
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#4
0
 ///<summary>
 ///Author: Stenner Kvindlog
 ///AddUser sends user to database to be created
 //calling to the user accessor
 ///Date: 3/4/16
 ///</summary>
 public int AddUser(User newUser)
 {
     try
     {
         int num = UserAccessor.CreateUser(newUser);
         return(num);
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#5
0
        /// <summary>
        /// Refactored create new user action to separate password from the model.
        /// Required properties: UserName, FirstName, LastName, EmailAddress, Zip
        /// TODO: Get rid of the password in the model.
        ///
        /// Created by: Trent Cullinan 03/25/16
        /// </summary>
        /// <param name="user">User with required base information.</param>
        /// <param name="password">Value to be set as password.</param>
        /// <returns>Whether the password change was successful.</returns>
        public bool AddNewUserPasswordChange(User user, string password)
        {
            bool flag = false;

            user.Password = password.HashSha256();

            try
            {
                flag = 1 == UserAccessor.CreateUser(user);
            }
            catch (Exception) { } // flag set to false

            return(flag);
        }
        public bool CreateUser(User user)
        {
            user.PasswordHash = HashSha256(user.PasswordHash);

            try
            {
                int result = UserAccessor.CreateUser(user);
                if (result == 0)
                {
                    throw new ApplicationException("User was not created");
                }
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }