Exemplo n.º 1
0
        public override async Task Login(ZhiHuLoginInfo info, Action <RiBaoAuthoInfo> loginCallback)
        {
            if (IsAuthorized)
            {
                loginCallback?.Invoke(await DataRequester.LoginUsingZhiHu(TokenInfo));
                return;
            }

            if (info == null)
            {
                loginCallback?.Invoke(null);
                return;
            }

            if (info.Captcha != null && !await CheckCaptcha(info.Captcha))
            {
                loginCallback?.Invoke(null);
                return;
            }

            var signInfo = await DataRequester.ZhiHuLogin(info.UserName, info.Password);

            if (!CheckError(signInfo))
            {
                loginCallback?.Invoke(null);
                return;
            }

            var zhiHuAutoInfo = await DataRequester.GetZhiHuAuthorization(signInfo);

            if (!CheckError(zhiHuAutoInfo))
            {
                loginCallback?.Invoke(null);
                return;
            }

            TokenInfo = await DataRequester.GetZhiHuToken(zhiHuAutoInfo);

            if (TokenInfo == null || string.IsNullOrEmpty(TokenInfo.access_token))
            {
                PopupMessage.DisplayMessage(StringUtil.GetString("LoginFailed") + TokenInfo?.Data ?? "");
                loginCallback?.Invoke(null);
                return;
            }
            TokenInfo.LastAuthoDate = DateTime.Now;
            TokenInfo.source        = LoginType.ZhiHu.Convert();
            StoreTokenInfo();
            var autoInfo = await DataRequester.LoginUsingZhiHu(TokenInfo);

            loginCallback?.Invoke(autoInfo);
        }