Beispiel #1
0
        /// <summary>
        /// The get user on login.
        /// </summary>
        /// <param name="login">
        /// The login.
        /// </param>
        /// <returns>
        /// The <see cref="User"/>.
        /// </returns>
        public User GetUserOnLogin(string login)
        {
            var user = new User();

            var sqlParameter = new SqlParameter[1];
            sqlParameter[0] = new SqlParameter("@Login", SqlDbType.VarChar) { Value = login };
            var dataTable = this.sqlDataManager.SelectProcedure("GetUserOnLogin", sqlParameter);

            if (dataTable.Rows.Count > 0)
            {
                foreach (DataRow dataRow in dataTable.Rows)
                {
                    user.LoginName = dataRow["Login"].ToString();
                    user.HashPassword = dataRow["KeyPassword"].ToString();
                    user.Salt = dataRow["Salt"].ToString();
                    user.Email = dataRow["Email"].ToString();
                }
            }
            else
            {
                return null;
            }

            return user;
        }
Beispiel #2
0
        public void AddNewUserBasicTest()
        {
            User newUser = new User();
            newUser.LoginName = "qwerty5";
            newUser.Email = "*****@*****.**";
            newUser.HashPassword = "******";
            newUser.Salt = "mLbjTL3rmvrEEu40Tcia8c3ZAtg=";
            User resultUser = this.userDalManager.AddNewUser(newUser);
            User getNewUser = this.userDalManager.GetUserOnLogin(newUser.LoginName);
            Assert.That(getNewUser.LoginName, Is.EqualTo("qwerty5"));

            //Delete new user
            this.userDalManager.DeleteUser(newUser);
        }
Beispiel #3
0
 /// <summary>
 /// The save or update.
 /// </summary>
 /// <param name="newUser">
 /// The new user.
 /// </param>
 /// <returns>
 /// The <see cref="User"/>.
 /// </returns>
 public User AddNewUser(User newUser)
 {
     SqlParameter[] sqlParameter = new SqlParameter[4];
     sqlParameter[0] = new SqlParameter("@Login", SqlDbType.VarChar) { Value = newUser.LoginName };
     sqlParameter[1] = new SqlParameter("@Email", SqlDbType.VarChar) { Value = newUser.Email };
     sqlParameter[2] = new SqlParameter("@Salt", SqlDbType.VarChar) { Value = newUser.Salt };
     sqlParameter[3] = new SqlParameter("@KeyPassword", SqlDbType.VarChar) { Value = newUser.HashPassword };
     try
     {
         this.sqlDataManager.InsertProcedure("AddUser", sqlParameter);
     }
     catch (Exception exception)
     {
         throw exception;
     }
     return newUser;
     // return newUser;
 }
Beispiel #4
0
        /// <summary>
        /// The delete user.
        /// </summary>
        /// <param name="user">
        /// The user.
        /// </param>
        public void DeleteUser(User user)
        {
            User deletingUser = this.Get(user.LoginName);
            if (deletingUser != null)
            {
                this.userDalManager.DeleteUser(user);
            }
            else
            {
                UserNotExists userNotExists = new UserNotExists();
                userNotExists.Data.Add("LoginName", user.LoginName);
                throw userNotExists;
            }

        }
Beispiel #5
0
        /// <summary>
        /// The create.
        /// </summary>
        /// <param name="registerInfo">
        /// The register info.
        /// </param>
        /// <returns>
        /// The <see cref="User"/>.
        /// </returns>
        public User CreateUser(RegisterInfo registerInfo)
        {
            var newUser = new User();
            if (this.Validate(registerInfo))
            {
                if (!this.AlreadyExist(registerInfo))
                {
                    string salt = null;
                    string hashPassword = this.passwordManager.GeneratePasswordHash(registerInfo.Password, out salt);

                    newUser.LoginName = registerInfo.LoginName;
                    newUser.Email = registerInfo.Email;
                    newUser.Salt = salt;
                    newUser.HashPassword = hashPassword;

                    //TODO user not add to DataBase
                    this.userDalManager.AddNewUser(newUser);
                }
                else
                {
                    var userAlreadyExists = new UserAlreadyExists();
                    userAlreadyExists.Data.Add("LoginName", registerInfo.LoginName);
                    throw userAlreadyExists;
                }
            }

            return newUser;
        }
Beispiel #6
0
        /// <summary>
        /// The delete.
        /// </summary>
        /// <param name="user">
        /// The user.
        /// </param>
        public void DeleteUser(User user)
        {
            SqlParameter[] sqlParameter = new SqlParameter[1];
            sqlParameter[0] = new SqlParameter("@Login", SqlDbType.VarChar) { Value = user.LoginName };

            this.sqlDataManager.InsertProcedure("DeleteUser", sqlParameter);
        }