Example #1
0
        public async Task <JsonResult> GetBindingThirdPartyList()
        {
            try
            {
                if (!AuthenticationManager.User.Identity.IsAuthenticated)
                {
                    throw new UserFriendlyException("当前用户没有登录");
                }
                var userid       = AuthenticationManager.User.Identity.GetUserId <long>();
                var bindingUsers = await _userRegistrationManager.GetBindingUsersAsync(userid);

                var result = new List <ThirdPartyModel>();
                if (SettingManager.GetSettingValue <bool>(AppSettingNames.OAuth.QQ.IsEnabled))
                {
                    result.Add(new ThirdPartyModel
                    {
                        ThirdParty     = ThirdParty.QQ.ToString(),
                        ThirdPartyName = "QQ",
                        AuthUrl        = _qqAuthService.GetBindingRedirectUrl(),
                        IconUrl        = "/Images/qq.png",
                        IsBinding      = bindingUsers.Exists(u => u.ThirdParty == ThirdParty.QQ.ToString())
                    });
                }
                if (SettingManager.GetSettingValue <bool>(AppSettingNames.OAuth.WeixinOpen.IsEnabled))
                {
                    result.Add(new ThirdPartyModel
                    {
                        ThirdParty     = ThirdParty.Weixin.ToString(),
                        ThirdPartyName = "微信",
                        AuthUrl        = _weixinAuthService.GetBindingRedirectUrl(),
                        IconUrl        = "/Images/wechat.png",
                        IsBinding      = bindingUsers.Exists(u => u.ThirdParty == ThirdParty.Weixin.ToString())
                    });
                }
                if (SettingManager.GetSettingValue <bool>(AppSettingNames.OAuth.Weibo.IsEnabled))
                {
                    result.Add(new ThirdPartyModel
                    {
                        ThirdParty     = ThirdParty.Weibo.ToString(),
                        ThirdPartyName = "微博",
                        AuthUrl        = _weiboAuthService.GetBindingRedirectUrl(),
                        IconUrl        = "/Images/weibo.png",
                        IsBinding      = bindingUsers.Exists(u => u.ThirdParty == ThirdParty.Weibo.ToString())
                    });
                }
                if (SettingManager.GetSettingValue <bool>(AppSettingNames.OAuth.Alipay.IsEnabled))
                {
                    result.Add(new ThirdPartyModel
                    {
                        ThirdParty     = ThirdParty.Alipay.ToString(),
                        ThirdPartyName = "支付宝",
                        AuthUrl        = _alipayAuthService.GetBindingRedirectUrl(),
                        IconUrl        = "/Images/alipay.png",
                        IsBinding      = bindingUsers.Exists(u => u.ThirdParty == ThirdParty.Alipay.ToString())
                    });
                }
                return(Json(new AjaxResponse(result)));
            }
            catch (Exception ex)
            {
                LogHelper.LogException(Logger, ex);
                Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                EventBus.Trigger(this, new AbpHandledExceptionData(ex));
                return(Json(new AjaxResponse(ErrorInfoBuilder.BuildForException(ex))));
            }
        }