Beispiel #1
0
        public OperationResult ChangePassword(Models.ServiceModels.User user, string password)
        {
            OperationResult res = new OperationResult();

            if (string.IsNullOrEmpty(password))
            {
                res.AddResultCode(OperationErrors.PassErr);
            }
            if (user == null)
            {
                res.AddResultCode(OperationErrors.NullErr);
            }
            else
            {
                if (!IsExistsById(user.Id))
                {
                    res.AddResultCode(OperationErrors.UserNotExistErr);
                }
            }
            if (res.Success)
            {
                string salt                  = CryptoFunctions.GenerationSalt(32);
                string passwordHash          = CryptoFunctions.GetMd5Hash(password, salt);
                Models.EFModels.User newUser = Mapper.Map <Models.EFModels.User>(user);
                newUser.Password = passwordHash;
                newUser.Salt     = salt;
                _userRepository.ChangePassword(newUser);
            }
            return(res);
        }
Beispiel #2
0
        public OperationResult DeleteUser(Models.ServiceModels.User user)
        {
            OperationResult res = new OperationResult();

            if (user == null)
            {
                res.AddResultCode(OperationErrors.NullErr);
            }
            else
            {
                if (!IsExistsById(user.Id))
                {
                    res.AddResultCode(OperationErrors.UserNotExistErr);
                }
            }
            if (res.Success)
            {
                Models.EFModels.User newUser = Mapper.Map <Models.ServiceModels.User, Models.EFModels.User>(user);
                _userRepository.Delete(newUser);
            }
            return(res);
        }
Beispiel #3
0
        public OperationResult <Models.ServiceModels.User> AuthorizationUser(string login, string password)
        {
            OperationResult <Models.ServiceModels.User> res = new OperationResult <Models.ServiceModels.User>();

            Models.EFModels.User user = _userRepository.GetByLogin(login);
            if (user == null)
            {
                res.AddResultCode(OperationErrors.AutorizationFiledErr);
            }
            else
            {
                Models.ServiceModels.User newUser = Mapper.Map <Models.EFModels.User, Models.ServiceModels.User>(user);
                if (!user.Password.Equals(CryptoFunctions.GetMd5Hash(password, user.Salt)))
                {
                    res.AddResultCode(OperationErrors.AutorizationFiledErr);
                }
                else
                {
                    res.Result = newUser;
                }
            }
            return(res);
        }
Beispiel #4
0
        public OperationResult AddRole(string roleName)
        {
            OperationResult res = new OperationResult();

            if (string.IsNullOrEmpty(roleName))
            {
                res.AddResultCode(OperationErrors.RoleErr);
            }
            if (res.Success)
            {
                Models.EFModels.Role newRole = new Models.EFModels.Role(roleName);
                _roleRepository.Create(newRole);
            }
            return(res);
        }
Beispiel #5
0
        public OperationResult CreateUser(Models.ServiceModels.User user, string password)
        {
            OperationResult res = new OperationResult();

            if (string.IsNullOrEmpty(password))
            {
                res.AddResultCode(OperationErrors.PassErr);
            }
            if (user == null)
            {
                res.AddResultCode(OperationErrors.NullErr);
            }
            else
            {
                if (string.IsNullOrEmpty(user.Login))
                {
                    res.AddResultCode(OperationErrors.LoginErr);
                }
                if (string.IsNullOrEmpty(user.FullName))
                {
                    res.AddResultCode(OperationErrors.FullNameErr);
                }
                if (string.IsNullOrEmpty(user.Roles.First().RoleName))
                {
                    res.AddResultCode(OperationErrors.RoleErr);
                }
                if (IsExists(user))
                {
                    res.AddResultCode(OperationErrors.UserExistErr);
                }
            }
            if (res.Success)
            {
                string salt         = CryptoFunctions.GenerationSalt(32);
                string passwordHash = CryptoFunctions.GetMd5Hash(password, salt);

                Models.EFModels.User newUser = Mapper.Map <Models.ServiceModels.User, Models.EFModels.User>(user);
                newUser.Password = passwordHash;
                newUser.Salt     = salt;
                _userRepository.Create(newUser);
            }
            return(res);
        }
Beispiel #6
0
        public OperationResult UpdateUser(Models.ServiceModels.User user)
        {
            OperationResult res = new OperationResult();

            if (user == null)
            {
                res.AddResultCode(OperationErrors.NullErr);
            }
            else
            {
                if (string.IsNullOrEmpty(user.Login))
                {
                    res.AddResultCode(OperationErrors.LoginErr);
                }
                if (string.IsNullOrEmpty(user.FullName))
                {
                    res.AddResultCode(OperationErrors.FullNameErr);
                }
                if (string.IsNullOrEmpty(user.Roles.First().RoleName))
                {
                    res.AddResultCode(OperationErrors.RoleErr);
                }
                if (!IsExistsById(user.Id))
                {
                    res.AddResultCode(OperationErrors.UserNotExistErr);
                }
                if (IsExistsLogin(user))
                {
                    res.AddResultCode(OperationErrors.UserExistErr);
                }
            }
            if (res.Success)
            {
                Models.EFModels.User newUser = Mapper.Map <Models.EFModels.User>(user);
                _userRepository.Update(newUser);
            }
            return(res);
        }