Exemplo n.º 1
0
        public ActionResult Auth()
        {
            string url   = string.Empty;
            string vtype = RouteData.Values["id"]?.ToString().ToLower();

            switch (vtype)
            {
            case "qq":
                url = QQ.AuthorizationHref(new QQ_Authorization_RequestEntity());
                break;

            case "weibo":
                url = Weibo.AuthorizeHref(new Weibo_Authorize_RequestEntity());
                break;

            case "github":
                url = GitHub.AuthorizeHref(new GitHub_Authorize_RequestEntity());
                break;

            case "taobao":
                url = Taobao.AuthorizeHref(new Taobao_Authorize_RequestEntity());
                break;

            case "microsoft":
                url = MicroSoft.AuthorizeHref(new MicroSoft_Authorize_RequestEntity());
                break;
            }
            if (string.IsNullOrWhiteSpace(url))
            {
                url = "/account/login";
            }

            //已登录 && 从绑定页面点击
            if (HttpContext.User.Identity.IsAuthenticated && Request.Headers["Referer"].ToString().ToLower().Contains("authbind"))
            {
                //写入绑定标识cookie
                var hc = new HttpCookie("AccountBindOAuth", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
                {
                    Expires = DateTime.Now.AddMinutes(2)
                };
                Response.Cookies.Add(hc);
            }
            else
            {
                //删除绑定标识
                Response.Cookies.Remove("AccountBindOAuth");
            }
            return(Redirect(url));
        }
Exemplo n.º 2
0
        public IActionResult Auth()
        {
            string url = string.Empty;

            if (Enum.TryParse(RouteData.Values["id"]?.ToString().ToLower(), out ValidateloginType vtype))
            {
                switch (vtype)
                {
                case ValidateloginType.qq:
                    url = QQ.AuthorizationHref(new QQ_Authorization_RequestEntity());
                    break;

                case ValidateloginType.weibo:
                    url = Weibo.AuthorizeHref(new Weibo_Authorize_RequestEntity());
                    break;

                case ValidateloginType.github:
                    url = GitHub.AuthorizeHref(new GitHub_Authorize_RequestEntity());
                    break;

                case ValidateloginType.taobao:
                    url = Taobao.AuthorizeHref(new Taobao_Authorize_RequestEntity());
                    break;

                case ValidateloginType.microsoft:
                    url = MicroSoft.AuthorizeHref(new MicroSoft_Authorize_RequestEntity());
                    break;
                }
            }

            if (string.IsNullOrWhiteSpace(url))
            {
                url = "/account/login";
            }

            //未登录
            if (!User.Identity.IsAuthenticated)
            {
                //删除绑定标识
                Response.Cookies.Delete("AccountBindOAuth");
            }
            return(Redirect(url));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 生成请求链接
        /// </summary>
        /// <returns></returns>
        public string Auth(LoginBase.LoginType loginType)
        {
            var url = string.Empty;

            switch (loginType)
            {
            case LoginBase.LoginType.QQ:
                url = QQ.AuthorizationHref(new QQ_Authorization_RequestEntity());
                break;

            case LoginBase.LoginType.WeiBo:
                url = Weibo.AuthorizeHref(new Weibo_Authorize_RequestEntity());
                break;

            case LoginBase.LoginType.WeChat:
                url = WeChat.AuthorizationHref(new WeChat_Authorization_RequestEntity());
                break;

            case LoginBase.LoginType.GitHub:
                url = GitHub.AuthorizeHref(new GitHub_Authorize_RequestEntity());
                break;

            case LoginBase.LoginType.TaoBao:
                url = Taobao.AuthorizeHref(new Taobao_Authorize_RequestEntity());
                break;

            case LoginBase.LoginType.MicroSoft:
                url = MicroSoft.AuthorizeHref(new MicroSoft_Authorize_RequestEntity());
                break;

            default:
                break;
            }

            return(url);
        }