Ejemplo 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);
        }
Ejemplo n.º 2
0
        private async Task <bool> CheckCaptcha(string captcha)
        {
            var captchaChecked = await DataRequester.CheckCaptcha(captcha);

            if (captchaChecked != null && captchaChecked.Success)
            {
                return(true);
            }

            if (captchaChecked != null && captchaChecked.Error != null && !string.IsNullOrEmpty(captchaChecked.Error.Message))
            {
                PopupMessage.DisplayMessage(captchaChecked.Error.Message);
            }
            else
            {
                PopupMessage.DisplayMessageInRes("CaptchaCheckFailed");
            }

            return(false);
        }
Ejemplo n.º 3
0
        private async void GetCaptchaImage()
        {
            var captcha = await DataRequester.GetCaptchaImage();

            if (captcha == null)
            {
                PopupMessage.DisplayMessage(StringUtil.GetString("GetCaptchaFailed"));
                CaptchaImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/CaptchaFailed.png"));
                return;
            }

            if (!string.IsNullOrEmpty(captcha.Img_Base64))
            {
                NeedCaptcha = true;
                ResUtil.SetBase64ToImage((BitmapSource)CaptchaImage.Source, captcha.Img_Base64);
            }
            else
            {
                NeedCaptcha = false;
            }
        }
Ejemplo n.º 4
0
        private async void CreateCircle(object sender, RoutedEventArgs arg)
        {
            var title = CircleTitle.Text;
            var desc  = CircleDesc.Text;

            if (string.IsNullOrEmpty(title))
            {
                PopupMessage.DisplayMessageInRes("CreateCircleError");
                return;
            }

            var rst = await DataRequester.CreateCircle(title, desc);

            if (rst.Id < 1)
            {
                PopupMessage.DisplayMessage(rst.Error_Msg);
                return;
            }

            PopupMessage.DisplayMessageInRes("CreateCircleSuccess");
            NavigationManager.Instance.GoBack();
        }
Ejemplo n.º 5
0
        private bool CheckError(ErrorBase error)
        {
            if (error == null)
            {
                PopupMessage.DisplayMessageInRes("LoginFailed");
                return(false);
            }
            if (error.Error != null)
            {
                if (string.IsNullOrEmpty(error.Error.Message))
                {
                    PopupMessage.DisplayMessageInRes("LoginFailed");
                }
                else
                {
                    PopupMessage.DisplayMessage(error.Error.Message);
                }

                return(false);
            }

            return(true);
        }