示例#1
0
        private string SetPassword(int userId, string newPwd, string oldPwd)
        {
            return(ServiceInvoke(unitOfWork =>
            {
                var userEntity = unitOfWork.UserRepository.Get(v => v.Id == userId).FirstOrDefault();
                if (userEntity == null)
                {
                    return "用户未找到";
                }

                if (PwdSecurityHelper.CheckEqual(oldPwd, userEntity.Password))
                {
                    userEntity.Password = PwdSecurityHelper.ComputeHash(newPwd);
                    userEntity.UpdatedDate = DateTime.Now;
                }
                else
                {
                    return "原密码错";
                }

                unitOfWork.UserRepository.Update(userEntity);

                return null;
            }));


            //using (UnitOfWork)
            //{
            //    var userEntity = UnitOfWork.UserRepository.Get(v => v.Id == userId).FirstOrDefault();
            //    if (userEntity == null)
            //    {
            //        return "用户未找到";
            //    }

            //    if (PwdSecurityHelper.CheckEqual(oldPwd, userEntity.Password))
            //    {
            //        userEntity.Password = PwdSecurityHelper.ComputeHash(newPwd);
            //        userEntity.UpdatedDate = DateTime.Now;
            //    }
            //    else
            //    {
            //        return "原密码错";
            //    }

            //    UnitOfWork.UserRepository.Update(userEntity);
            //}

            //return null;
        }
示例#2
0
        private UserEntity CheckUser(string userName, string password)
        {
            var userEntity = ServiceInvoke(unitOfWork => unitOfWork.UserRepository.Get(v =>
                                                                                       String.Compare(v.Name, userName,
                                                                                                      StringComparison.OrdinalIgnoreCase) == 0)
                                           .FirstOrDefault());


            if (userEntity == null)
            {
                return(null);
            }

            return(PwdSecurityHelper.CheckEqual(password, userEntity.Password) ? userEntity : null);
        }
示例#3
0
        private MethodResult <UserEntity, int, string> InsertUser(UserEntity user)
        {
            var result = new MethodResult <UserEntity, int, string>();

            //check user name
            ServiceInvoke <NGnono_FMNoteContextUnitOfWork>(v =>
            {
                //1 check
                //2 insert
                var checkUserName =
                    v.UserRepository.Get(g => String.Compare(g.Name, user.Name, StringComparison.OrdinalIgnoreCase) == 0).FirstOrDefault() == null;

                if (!checkUserName)
                {
                    result.StatusCode = 2;
                    result.Message    = "用户名已存在,请换个名字!";
                    result.Data       = null;
                }
                else
                {
                    user.Password = PwdSecurityHelper.ComputeHash(user.Password);

                    result.Data       = v.UserRepository.Insert(user);
                    result.IsSuccess  = true;
                    result.StatusCode = 1;
                }
            });

            return(result);
            //return ExecFunc(v => v.UserRepository.Insert(user));

            //return ItemSetter(user, (unitOfWork, userEntity) => unitOfWork.UserRepository.Insert(userEntity));

            //using (UnitOfWork)
            //{
            //    user.Password = PwdSecurityHelper.ComputeHash(user.Password);
            //    var userEntity = UnitOfWork.UserRepository.Insert(user);

            //    return userEntity;
            //}
        }