public UserModel GetOneUserByLogin(string userNickName, string userPassword)
        {
            if (userNickName.Equals(""))
            {
                throw new ArgumentOutOfRangeException();
            }
            if (userPassword.Equals(""))
            {
                throw new ArgumentOutOfRangeException();
            }

            if (!CheckStringFormat.IsBase64String(userPassword))
            {
                userPassword = ComputeHash.ComputeNewHash(userPassword);
            }
            DataTable dt        = new DataTable();
            UserModel userModel = new UserModel();

            using (MySqlCommand command = new MySqlCommand())
            {
                dt = GetMultipleQuery(UserStringsMySql.GetOneUserByLogin(userNickName, userPassword));
            }
            foreach (DataRow ms in dt.Rows)
            {
                userModel = UserModel.ToObject(ms);
            }

            return(userModel);
        }
        public UserModel AddUser(UserModel userModel)
        {
            string orPass = userModel.userPassword;

            userModel.userPassword = ComputeHash.ComputeNewHash(userModel.userPassword);
            if (userModel.userLevel < 1)
            {
                userModel.userLevel = 1;
            }
            DataTable dt = new DataTable();

            using (MySqlCommand command = new MySqlCommand())
            {
                dt = GetMultipleQuery(UserStringsMySql.AddUser(userModel));
            }
            foreach (DataRow ms in dt.Rows)
            {
                userModel = UserModel.ToObject(ms);
            }

            if (ComputeHash.ComputeNewHash(orPass).Equals(userModel.userPassword))
            {
                userModel.userPassword = orPass;
            }

            return(userModel);
        }
        public UserModel UpdateUser(UserModel userModel)
        {
            _users.ReplaceOne(u => u.userID.Equals(userModel.userID), userModel);
            UserModel user = GetOneUserByLogin(userModel.userNickName, userModel.userPassword);

            if (ComputeHash.ComputeNewHash(userModel.userPassword).Equals(user.userPassword))
            {
                user.userPassword = userModel.userPassword;
            }
            return(user);
        }
        public LoginModel ReturnUserByNamePassword(LoginModel checkUser)
        {
            checkUser.userPassword = ComputeHash.ComputeNewHash(checkUser.userPassword);

            return((from user in _users.AsQueryable()
                    where user.userNickName.Equals(checkUser.userNickName)
                    where user.userPassword.Equals(checkUser.userPassword)
                    select new LoginModel
            {
                userNickName = user.userNickName,
                userLevel = user.userLevel,
                userPicture = user.userPicture != null ? "/assets/images/users/" + user.userPicture : null
            }).SingleOrDefault());
        }
        public UserModel AddUser(UserModel userModel)
        {
            if (userModel.userLevel < 1)
            {
                userModel.userLevel = 1;
            }

            _users.InsertOne(userModel);
            UserModel user = GetOneUserByLogin(userModel.userNickName, userModel.userPassword);

            if (ComputeHash.ComputeNewHash(userModel.userPassword).Equals(user.userPassword))
            {
                user.userPassword = userModel.userPassword;
            }

            return(user);
        }
        public LoginModel ReturnUserByNamePassword(LoginModel checkUser)
        {
            checkUser.userPassword = ComputeHash.ComputeNewHash(checkUser.userPassword);
            if (checkUser == null)
            {
                throw new ArgumentOutOfRangeException();
            }
            DataTable  dt         = new DataTable();
            LoginModel loginModel = new LoginModel();

            using (MySqlCommand command = new MySqlCommand())
            {
                dt = GetMultipleQuery(UserStringsMySql.ReturnUserByNamePassword(checkUser));
            }
            foreach (DataRow ms in dt.Rows)
            {
                loginModel = LoginModel.ToObject(ms);
            }

            return(loginModel);
        }
Пример #7
0
        public UserModel UpdateUser(UserModel userModel)
        {
            string    orPass = userModel.userPassword;
            DataTable dt     = new DataTable();

            using (SqlCommand command = new SqlCommand())
            {
                dt = GetMultipleQuery(UserStringsSql.UpdateUser(userModel));
            }
            foreach (DataRow ms in dt.Rows)
            {
                userModel = UserModel.ToObject(ms);
            }

            if (ComputeHash.ComputeNewHash(orPass).Equals(userModel.userPassword))
            {
                userModel.userPassword = orPass;
            }

            return(userModel);
        }
        public UserModel GetOneUserByLogin(string userNickName, string userPassword)
        {
            if (!CheckStringFormat.IsBase64String(userPassword))
            {
                userPassword = ComputeHash.ComputeNewHash(userPassword);
            }

            return((from user in _users.AsQueryable()
                    where user.userNickName.Equals(userNickName)
                    where user.userPassword.Equals(userPassword)
                    select new UserModel
            {
                userID = user.userID,
                userFirstName = user.userFirstName,
                userLastName = user.userLastName,
                userNickName = user.userNickName,
                userPassword = user.userPassword,
                userEmail = user.userEmail,
                userGender = user.userGender,
                userBirthDate = user.userBirthDate,
                userPicture = user.userPicture != null ? "/assets/images/users/" + user.userPicture : null,
                userLevel = user.userLevel
            }).SingleOrDefault());
        }