Exemple #1
0
        /// <summary>
        /// 无动作名时执行默认方法
        /// </summary>
        public override void DefaultAction()//默认动作
        {
            string state   = ctx.Request["state"];
            string pageUrl = string.Empty;
            var    data    = ctx.Request;  //获取回调响应参数
            var    code    = data["code"]; // 认证返回的code信息;

            if (!string.IsNullOrEmpty(code))
            {
                api                   = new LoginApiHelp(state); //存储用户信息
                threeloginInfo        = api.DealCode(code);      //据code向百度服务器进行交互获取长期的Access Token   并调用api获取数据
                accctx                = AccountsPrincipal.ValidateLogin(threeloginInfo.useName, threeloginInfo.uid);
                ctx.Session["accctx"] = accctx;
                if (string.IsNullOrEmpty(accctx.currentrole.rolename))
                {
                    accctx.currentrole = IocModule.GetEntity <IroleEx>().getAllRole().OrderByDescending(c => c.rolecode).FirstOrDefault();
                }
                ctx.Response.Redirect("/index.ashx?ctrl=index&action=view", false);
            }
        }
Exemple #2
0
        public threeloginInfo DealCode(string code)
        {
            threeloginInfo    tl    = null;
            ThreeLoginFactory three = new ThreeLoginFactory(GetThreeLoginType());
            var token = three.GetLoginHelp().AccessToken(code);

            if (token != null)
            {
                var userInfo = three.GetLoginHelp().UserInfo(token.access_token, token.uid);//调用API  获取用户数据
                if (userInfo != null)
                {
                    var item = IocModule.GetEntity <IthreeloginInfoEx>().getthreeloginInfobyuid(userInfo.userid);
                    tl             = new threeloginInfo();
                    tl.accessToken = token.access_token;
                    tl.code        = code;
                    tl.uid         = userInfo.userid;
                    tl.useImg      = portraiturl + userInfo.portrait;
                    tl.type        = (int)BlakTypeEnum.BAIDU;
                    tl.typeName    = BlakTypeEnum.BAIDU.ToString();
                    //tl.sex = Convert.ToInt32(userInfo.sex);
                    tl.useName = userInfo.username;
                    //tl.refreshToken = token.refresh_token;

                    if (item == null)
                    {
                        #region 第一次第三方登录
                        //存储数据库
                        IocModule.GetEntity <IthreeloginInfoEx>().insert(tl);
                        IocModule.GetEntity <IthreeloginInfoEx>().InsertthreeloginInfo(tl);
                        #endregion
                    }
                    else
                    {
                        tl.id = item.id;
                        IocModule.GetEntity <IthreeloginInfoEx>().update(tl);
                    }
                }
            }
            return(tl);
        }