public AccountSignResult BindThirdPassport(ThirdPassport entity)
        {
            if (null == entity || string.IsNullOrEmpty(entity.Platform) || string.IsNullOrEmpty(entity.PlatformPassportId))
            {
                return(null);
            }
            var account = MvcContext.Current.ClientAccount;

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

            var          signStatus   = SignStatus.Error;
            UserPassport userPassport = AccountAuthentication.BindThirdPassport(entity, out signStatus);

            var result = new AccountSignResult();

            result.SignStatus = signStatus;
            if (result.SignStatus == SignStatus.Success)
            {
                result.Account = new AccountEntity(account, userPassport);
                WriteTokenToBrowser(result);
            }
            else
            {
                result.ErrorMessage = "绑定账号失败";
            }
            return(result);
        }
        public static UserPassport BindThirdPassport(ThirdPassport entity, out SignStatus status)
        {
            UserPassport passport = null;

            status = SignStatus.None;

            if (null == entity ||
                string.IsNullOrEmpty(entity.Platform) || string.IsNullOrEmpty(entity.PlatformPassportId))
            {
                return(null);
            }

            MemberShip.BindThirdPassport(entity, out status);
            if (status == SignStatus.Success)
            {
                Authenticate(passport);
            }

            return(passport);
        }
Exemple #3
0
        public void BindThirdAccountTest()
        {
            var thirdPassport = new ThirdPassport()
            {
                Platform = "apitest", PlatformPassportId = Guid.NewGuid().ToString("N")
            };

            thirdPassport.PassportInfo = thirdPassport.ToJson();
            var responseResult = WebApiClient.HttpPost(ApiEnvironment.Account_BindThirdPassport_Endpoint, thirdPassport);

            if (HttpStatusCode.OK != responseResult.StatusCode)
            {
                Console.WriteLine(responseResult.Content);
            }
            Assert.AreEqual(HttpStatusCode.OK, responseResult.StatusCode);

            var signResult = responseResult.Content.ConvertEntity <AccountSignResult>();

            Assert.IsNotNull(signResult);
            Assert.AreEqual(SignStatus.Success, signResult.SignStatus);
            Assert.IsNotNull(signResult.Account);
            Assert.IsTrue(signResult.Account.PassportId > 0);

            responseResult = WebApiClient.HttpPost(ApiEnvironment.Account_BindThirdPassport_Endpoint, thirdPassport);
            if (HttpStatusCode.OK != responseResult.StatusCode)
            {
                Console.WriteLine(responseResult.Content);
            }
            Assert.AreEqual(HttpStatusCode.OK, responseResult.StatusCode);

            var signResult2 = responseResult.Content.ConvertEntity <AccountSignResult>();

            Assert.IsNotNull(signResult2);
            Assert.AreEqual(SignStatus.Success, signResult2.SignStatus);
            Assert.IsNotNull(signResult2.Account);
            Assert.AreEqual(signResult.Account.PassportId, signResult2.Account.PassportId);
        }