Exemple #1
0
 public PassportServiceSoapClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
     base(PassportServiceSoapClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
        public IActionResult UnifyAuth(string unifyToken)
        {
            var response = ResponseModelFactory.CreateInstance;
            PassportServiceSoapClient client = new PassportServiceSoapClient(EndpointConfiguration.PassportServiceSoap, "https://sso.haikan.com.cn/api/passportservice.asmx");
            var data = client.TokenGetCertAsync(unifyToken).Result;

            if (data.Body.TokenGetCertResult == null)
            {
                response.SetFailed("token无效请重新登录");
                return(Ok(response));
            }
            BlowFish blowFish = new BlowFish();
            var      info     = blowFish.Decrypt("haikan051030", data.Body.TokenGetCertResult.ToString());
            var      arr      = info.Split('&');
            UserData userdata = new UserData()
            {
                username = arr[0],
                password = arr[1],
            };
            SystemUser user;

            using (_dbContext)
            {
                user = _dbContext.SystemUser.FirstOrDefault(x => x.LoginName == userdata.username.Trim());
                if (user == null || user.IsDeleted == 1)
                {
                    response.SetFailed("用户不存在");
                    return(Ok(response));
                }
                //string s = Haikan3.Utils.DesEncrypt.Encrypt(userdata.password.Trim(), MdDesEncrypt.SecretKey);
                string s = Security.GenerateMD5(userdata.password.Trim());
                //if (user.PassWord != Haikan3.Utils.DesEncrypt.Encrypt(userdata.password.Trim(), MdDesEncrypt.SecretKey))
                if (user.PassWord != Security.GenerateMD5(userdata.password.Trim()))
                {
                    response.SetFailed("密码不正确");
                    return(Ok(response));
                }
                //if (user.IsLocked == CommonEnum.IsLocked.Locked)
                //{
                //    response.SetFailed("账号已被锁定");
                //    return Ok(response);
                //}
                //if (user.Status == UserStatus.Forbidden)
                //{
                //    response.SetFailed("账号已被禁用");
                //    return Ok(response);
                //}

                //获取权限名
                string[] roleid   = user.SystemRoleUuid.TrimEnd(',').Split(",");
                string   rolename = "";
                for (int i = 0; i < roleid.Length; i++)
                {
                    if (!string.IsNullOrEmpty(roleid[i]))
                    {
                        rolename += _dbContext.SystemRole.FirstOrDefault(x => x.SystemRoleUuid == Guid.Parse(roleid[i])).RoleName + ",";
                    }
                }
                string zyz        = "";
                string yh         = "";
                string ddy        = "";
                string sj         = "";
                string superAdmin = "";

                //超管roleid
                var temp5 = _dbContext.SystemRole.Where(x => x.RoleName.Contains("超级")).Select(x => new { x.SystemRoleUuid }).ToList();
                if (temp5.Count > 0)
                {
                    superAdmin = temp5[0].SystemRoleUuid.ToString();
                }
                int usertype = 0;
                if (!user.SystemRoleUuid.Contains(superAdmin))
                {
                    usertype = 2;
                }
                var claimsIdentity = new ClaimsIdentity(new Claim[]
                {
                    new Claim(ClaimTypes.Name, userdata.username),
                    new Claim("guid", user.SystemUserUuid.ToString()),
                    new Claim("avatar", ""),
                    new Claim("displayName", user.RealName),
                    new Claim("loginName", user.LoginName),
                    new Claim("emailAddress", ""),
                    //new Claim("guid",user.SystemUserUuid.ToString()),
                    //new Claim("userType",usertype.ToString()),
                    new Claim("userType", user.UserType.Value.ToString()),
                    new Claim("roleid", user.SystemRoleUuid.TrimEnd(',')),
                    new Claim("roleName", rolename.TrimEnd(',')),
                    new Claim("ZYZ", zyz),
                    new Claim("YH", yh),
                    new Claim("DDY", ddy),
                    new Claim("SJ", sj)
                });
                var token = JwtBearerAuthenticationExtension.GetJwtAccessToken(_appSettings, claimsIdentity);

                response.SetData(token);
                return(Ok(response));
            }
        }
Exemple #3
0
 public PassportServiceSoapClient(EndpointConfiguration endpointConfiguration) :
     base(PassportServiceSoapClient.GetBindingForEndpoint(endpointConfiguration), PassportServiceSoapClient.GetEndpointAddress(endpointConfiguration))
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }