/// <summary>
        /// 登录
        /// </summary>
        /// <param name="userDTO"></param>
        /// <returns></returns>
        public OperationResult Login(UserDTO userDTO)
        {
            OperationResult result = new OperationResult();

            if (!string.IsNullOrWhiteSpace(userDTO.EmailAddress) || !string.IsNullOrWhiteSpace(userDTO.Password))
            {
                result.Success = false;
                result.Messages.Add("请填写用户名和密码");
                result.Code = ((int)RequestFailCode.ParametersMissing).ToString();
            }

            var user = _userDomainService.GetUser(userDTO.EmailAddress, userDTO.Password);

            if (user == null)
            {
                result.Success = false;
                result.Messages.Add("用户名或密码不正确");
                result.Code = ((int)RequestFailCode.PasswordError).ToString();
                return(result);
            }

            //如果存在的化,保存到Redis
            var tokenModel = new TokenDTO()
            {
                TokenId        = GuidUtility.GetGuid(),
                UserId         = user.Id,
                ExpiredDate    = DateTime.Now.AddSeconds(3600),
                RefreshTokenId = GuidUtility.GetGuid()
            };

            RedisRepository.SaveUserToken(tokenModel);

            result.Success = true;
            result.Data    = tokenModel;

            return(result);
        }
 public async Task <ViewUserDTO> GetUser(long id)
 {
     return(_autoMapper.Map <ViewUserDTO>(await _userDomainService.GetUser(GetCurrentUserId(), id)));
 }
示例#3
0
        /// <summary>
        /// 获取用户
        /// </summary>
        /// <param name="filter">筛选信息</param>
        /// <returns></returns>
        public UserDto GetUser(UserFilterDto filter)
        {
            IQuery query = CreateQueryObject(filter);

            return(UserDomainService.GetUser(query).MapTo <UserDto>());
        }