示例#1
0
        public ActionResult CallBack(string code)
        {
            //如果能过授权
            if (!string.IsNullOrEmpty(code))
            {
                Wbm.SinaV2API.oAuthSina oauth = Wbm.SinaV2API.SinaBase.oAuth();
                try
                {
                    oauth.GetAccessToken(); //获取认证信息
                    if (!string.IsNullOrEmpty(oauth.AccessToken))
                    {
                        Wbm.SinaV2API.SinaBase.UpdateCache(oauth.AccessToken);//缓存认证信息

                        #region sina login

                        var sinaUser = Wbm.SinaV2API.SinaControllers.UserController.GetUser();

                        if (sinaUser != null)
                        {
                            string sinaId   = sinaUser.id.ToString();
                            string sinaName = sinaUser.screen_name;
                            if (!string.IsNullOrEmpty(sinaId))
                            {
                                var sinaLoginModel = userService.GetUserBySina(sinaId);
                                //如果存在
                                if (sinaLoginModel != null && sinaLoginModel.id > 0)
                                {
                                    var currentUserDto = AutoMapper.Mapper.Map <iPow.Infrastructure.Data.DataSys.Sys_AdminUser,
                                                                                iPow.Service.SSO.Entity.User>(sinaLoginModel);
                                    currentUserDto.LoginDomain    = "http://sso.ipow.cn";
                                    currentUserDto.LoginIpAddress = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetRealIP();
                                    //添加到SsoUserList中
                                    //用户已登录
                                    return(UserLoginedAndRedirect(currentUserDto));
                                }
                                //不存在
                                else
                                {
                                    #region  存在

                                    iPow.Infrastructure.Data.DataSys.Sys_AdminUser user     = new Infrastructure.Data.DataSys.Sys_AdminUser();
                                    iPow.Infrastructure.Data.DataSys.Sys_UserRoles userRole = new Infrastructure.Data.DataSys.Sys_UserRoles();
                                    iPow.Infrastructure.Data.DataSys.Sys_AdminUser perUser  = new Infrastructure.Data.DataSys.Sys_AdminUser();
                                    userRole.RoleID = 8;

                                    user.UserType = "xl";
                                    user.username = sinaUser.screen_name;
                                    user.truename = sinaUser.screen_name;
                                    perUser.id    = 1;
                                    userService.Add(user, userRole, perUser);
                                    if (user.id != 0)
                                    {
                                        //添加用户扩展信息
                                        var userExtension = new Infrastructure.Data.DataSys.Sys_AdminUserExtension();
                                        userExtension.AddTime               = System.DateTime.Now;
                                        userExtension.QQId                  = "";
                                        userExtension.QQScreenName          = "";
                                        userExtension.SinaId                = sinaUser.id.ToString();
                                        userExtension.SinaScreenName        = sinaUser.screen_name;
                                        userExtension.Sort                  = 0;
                                        userExtension.State                 = true;
                                        userExtension.UserId                = user.id;
                                        userExtension.SinaAccessToken       = oauth.AccessToken;
                                        userExtension.SinaAccessTokenSecret = "";
                                        userExtensionService.Add(userExtension, perUser);
                                        //end 添加用户扩展信息

                                        var currentRegisterUserDto = AutoMapper.Mapper.Map <iPow.Infrastructure.Data.DataSys.Sys_AdminUser, iPow.Service.SSO.Entity.User>(user);
                                        if (currentRegisterUserDto.id > 0)
                                        {
                                            //用户登录后返回的地址
                                            currentRegisterUserDto.LoginDomain    = "http://sso.ipow.cn";
                                            currentRegisterUserDto.LoginIpAddress = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetRealIP();
                                            //添加到SsoUserList中
                                            //用户已登录
                                            return(UserLoginedAndRedirect(currentRegisterUserDto));
                                        }
                                        else
                                        {
                                            ViewBag.message  = "亲爱的用户,您是第一次用新浪帐号登陆IPOW网站<br/>";
                                            ViewBag.message += "但登陆过程中出了点小毛病,<a href='/sina/logon/'>您愿意再试一次嘛</a>";
                                            return(View());
                                        }
                                    }
                                    else
                                    {
                                        ViewBag.message  = "亲爱的用户,您是第一次用新浪帐号登陆IPOW网站<br/>";
                                        ViewBag.message += "但登陆过程中出了点小毛病,<a href='/sina/logon/'>您愿意再试一次嘛</a>";
                                        return(View());
                                    }
                                    #endregion
                                }
                            }
                            else
                            {
                                ViewBag.message = "貌似登陆过程中出现了点小问题,貌似你没有新浪ID哦,<a href='/sina/logon/'>再登陆一次吧<a>";
                                return(View());
                            }
                        }
                        else
                        {
                            ViewBag.message = "登陆过程中,我们没有获取到新浪信息,你可以尝试<a href='/sina/logon/'>再登陆一次</a>";
                            return(View());
                        }

                        #endregion
                    }
                    else
                    {
                        ViewBag.message = "在连接新浪失败了,<a href='/sina/logon/'>请再试试</a>";
                        return(View());
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.message = "在连接新浪失败了,<a href='/sina/logon/'>请再试试</a>";
                    return(View());
                }
            }
            else
            {
                ViewBag.message = "不正确的访问方式";
                return(View());
            }
        }
示例#2
0
        public ActionResult CallBack(string code, string state)
        {
            if (code != null && Session[Infrastructure.Crosscutting.Comm.Service.ConstService.SessionNameTencentOauthToken] != null)
            {
                var    verifier = code;
                string token    = Session[Infrastructure.Crosscutting.Comm.Service.ConstService.SessionNameTencentOauthToken].ToString();
                var    qzone    = new QConnectSDK.QOpenClient(verifier, token);
                Session[Infrastructure.Crosscutting.Comm.Service.ConstService.SessionNameTencentOauthTokenSecret] = qzone;
                var currentQQUserWebbo = qzone.GetWeiboUserInfo();
                var accessToken        = qzone.OAuthToken != null ? qzone.OAuthToken.AccessToken : "";
                var openId             = qzone.OAuthToken != null ? qzone.OAuthToken.OpenId : "";
                if (null != currentQQUserWebbo.Data && !string.IsNullOrEmpty(currentQQUserWebbo.Data.Nick))
                {
                    //是否存在一下用户
                    var qqLoginModel = userService.GetUserByQQ(openId);
                    //如果存在
                    if (qqLoginModel != null && qqLoginModel.id > 0)
                    {
                        var currentUserDto = AutoMapper.Mapper.Map <iPow.Infrastructure.Data.DataSys.Sys_AdminUser,
                                                                    iPow.Service.SSO.Entity.User>(qqLoginModel);
                        currentUserDto.LoginDomain    = "http://sso.ipow.cn";
                        currentUserDto.LoginIpAddress = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetRealIP();
                        //添加到SsoUserList中
                        //用户已登录
                        return(UserLoginedAndRedirect(currentUserDto));
                    }
                    //不存在
                    else
                    {
                        #region  存在
                        iPow.Infrastructure.Data.DataSys.Sys_AdminUser user     = new Infrastructure.Data.DataSys.Sys_AdminUser();
                        iPow.Infrastructure.Data.DataSys.Sys_UserRoles userRole = new Infrastructure.Data.DataSys.Sys_UserRoles();
                        iPow.Infrastructure.Data.DataSys.Sys_AdminUser perUser  = new Infrastructure.Data.DataSys.Sys_AdminUser();
                        userRole.RoleID = 9;
                        user.UserType   = "tx";
                        user.username   = currentQQUserWebbo.Data.Nick;
                        user.truename   = currentQQUserWebbo.Data.Nick;
                        if (currentQQUserWebbo.Data.Sex == 1)
                        {
                            user.sex = "男";
                        }
                        else if (currentQQUserWebbo.Data.Sex == 2)
                        {
                            user.sex = "女";
                        }
                        else
                        {
                            user.sex = "未知";
                        }
                        perUser.id = 1;
                        userService.Add(user, userRole, perUser);
                        if (user.id != 0)
                        {
                            //添加用户扩展信息
                            var userExtension = new Infrastructure.Data.DataSys.Sys_AdminUserExtension();
                            userExtension.AddTime                  = System.DateTime.Now;
                            userExtension.QQId                     = openId;
                            userExtension.QQScreenName             = currentQQUserWebbo.Data.Nick;
                            userExtension.TenecntAccessToken       = accessToken;
                            userExtension.TenecntAccessTokenSecret = "";
                            userExtension.SinaId                   = "";
                            userExtension.SinaScreenName           = "";
                            userExtension.Sort                     = 0;
                            userExtension.State                    = true;
                            userExtension.UserId                   = user.id;

                            userExtensionService.Add(userExtension, perUser);
                            //end 添加用户扩展信息

                            var currentRegisterUserDto = AutoMapper.Mapper.Map <iPow.Infrastructure.Data.DataSys.Sys_AdminUser, iPow.Service.SSO.Entity.User>(user);
                            if (currentRegisterUserDto.id > 0)
                            {
                                //用户登录后返回的地址
                                currentRegisterUserDto.LoginDomain    = "http://sso.ipow.cn";
                                currentRegisterUserDto.LoginIpAddress = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetRealIP();
                                //添加到SsoUserList中
                                //用户已登录
                                return(UserLoginedAndRedirect(currentRegisterUserDto));
                            }
                            else
                            {
                                ViewBag.message  = "亲爱的用户,您是第一次用腾讯帐号登陆IPOW网站<br/>";
                                ViewBag.message += "但登陆过程中出了点小毛病,<a href='/tencent/logon/'>您愿意再试一次嘛</a>";
                                return(View());
                            }
                        }
                        else
                        {
                            ViewBag.message  = "亲爱的用户,您是第一次用腾讯帐号登陆IPOW网站<br/>";
                            ViewBag.message += "但登陆过程中出了点小毛病,<a href='/tencent/logon/'>您愿意再试一次嘛</a>";
                            return(View());
                        }
                        #endregion
                    }
                }
                else
                {
                    ViewBag.message = "在连接腾讯失败了,<a href='/tencent/logon/'>请再试试</a>";
                    return(View());
                }
            }
            else
            {
                ViewBag.message = "不正确的访问方式";
                return(View());
            }
        }