/// <summary>
 /// 安全退出
 /// </summary>
 /// <returns></returns>
 public ContentResult OutLogin()
 {
     try
     {
         HttpCookie myCookie = new HttpCookie("gm_userinfo", null);
         myCookie.Expires = DateTime.Now.AddDays(-1d);
         Response.Cookies.Add(myCookie);
         string guid = Session["guid"].ToString();
         Session.RemoveAll();
         Basice pLoginModels = new Basice();
         pLoginModels.outLogin(guid);
     }
     catch (Exception ex) { string s = ex.Message; Session.RemoveAll(); }
     return(null);
 }
        public string loginAPI(string userid, string password)
        {
            bool   autoLogin = false;
            string account   = userid;

            try
            {
                HttpCookie myCookie = new HttpCookie("gm_userinfo", null);
                myCookie.Expires = DateTime.Now.AddDays(-1);
                Response.Cookies.Add(myCookie);
                Session.RemoveAll();

                Basice      pLoginModels = new Basice();
                LoginReturn pLoginReturn;
                // 登录唯一凭证
                string tokenValue = Guid.NewGuid().ToString().ToUpper();
                #region /*获得IP*/
                string userIp = "";
                if (Request.ServerVariables["HTTP_VIA"] != null)
                {
                    userIp = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
                }
                else
                {
                    userIp = Request.ServerVariables["REMOTE_ADDR"].ToString();
                }
                #endregion
                // 登录
                if (pLoginModels.Login(account, password, userIp, tokenValue, autoLogin, out pLoginReturn))
                {
                    //session 赋值
                    Session["id"]       = pLoginReturn.ID;
                    Session["name"]     = pLoginReturn.Name;
                    Session["rid"]      = pLoginReturn.Role_ID;
                    Session["guid"]     = tokenValue;
                    Session["Type"]     = pLoginReturn.Type;
                    Session["DataRole"] = pLoginReturn.DataRole;
                    Session["Account"]  = account;

                    //HttpCookie myCookie = new HttpCookie("gm_userinfo", null);
                    //myCookie.Expires = DateTime.Now.AddDays(-1d);
                    //Response.Cookies.Add(myCookie);

                    HttpCookie cookies_ = new HttpCookie("gm_userinfo");
                    cookies_.Values.Add("id", pLoginReturn.ID);
                    cookies_.Values.Add("name", pLoginReturn.Name);
                    cookies_.Values.Add("rid", pLoginReturn.Role_ID);
                    cookies_.Values.Add("guid", tokenValue);
                    cookies_.Values.Add("Type", pLoginReturn.Type);
                    cookies_.Values.Add("DataRole", pLoginReturn.DataRole);
                    cookies_.Values.Add("Account", account);
                    //域
                    if (!autoLogin)
                    {
                        cookies_.Expires = DateTime.Now.AddDays(2);
                    }
                    else
                    {
                        cookies_.Expires = DateTime.Now.AddDays(7);
                    }
                    this.Response.Cookies.Add(cookies_);
                    this.Response.AppendCookie(cookies_);
                    string schoolname = GetSchoolName(pLoginReturn.SchoolId);

                    //string xinfo = Session["Type"].ToString() == "1" ? " 老师" : (Session["Type"].ToString() == "2" ? " 学生" : (Session["Type"].ToString() == "3" ? " 企业" : ""));
                    string url       = GetLoingApi(pLoginReturn.Type, pLoginReturn.IsCmsAdmin, pLoginReturn.IsMonitorAdmin);
                    string userinfor = "{\"Login\":true,\"Type\":\"" + pLoginReturn.Type + "\",\"Name\":\"" + Session["name"] + "\",\"Email\":\"\",\"url\":\"" + url + "\",\"schoolid\":\"" + pLoginReturn.SchoolId + "\",\"schoolname\":\"" + schoolname + "\"}";


                    return(userinfor);
                }
            }
            catch (Exception ex) { string s = ex.Message; }
            return("{\"Login\":false}");
        }
        /// <summary>
        /// 其他系统登录单点登录用
        /// </summary>
        /// <param name="account"></param>
        /// <param name="password"></param>
        /// <param name="autoLogin"></param>
        /// <returns></returns>
        public string LoginSSO(string callback, string userid, string password, string flag)
        {
            bool   autoLogin = false;
            string account   = userid;

            try
            {
                HttpCookie myCookie = new HttpCookie("gm_userinfo", null);
                myCookie.Expires = DateTime.Now.AddDays(-1);
                Response.Cookies.Add(myCookie);
                Session.RemoveAll();

                Basice      pLoginModels = new Basice();
                LoginReturn pLoginReturn;
                // 登录唯一凭证
                string tokenValue = Guid.NewGuid().ToString().ToUpper();
                #region /*获得IP*/
                string userIp = "";
                if (Request.ServerVariables["HTTP_VIA"] != null)
                {
                    userIp = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
                }
                else
                {
                    userIp = Request.ServerVariables["REMOTE_ADDR"].ToString();
                }
                #endregion
                // 登录
                if (pLoginModels.Login(account, password, userIp, tokenValue, autoLogin, out pLoginReturn))
                {
                    //session 赋值
                    Session["id"]       = pLoginReturn.ID;
                    Session["name"]     = pLoginReturn.Name;
                    Session["rid"]      = pLoginReturn.Role_ID;
                    Session["guid"]     = tokenValue;
                    Session["Type"]     = pLoginReturn.Type;
                    Session["DataRole"] = pLoginReturn.DataRole;
                    Session["Account"]  = account;

                    //HttpCookie myCookie = new HttpCookie("gm_userinfo", null);
                    //myCookie.Expires = DateTime.Now.AddDays(-1d);
                    //Response.Cookies.Add(myCookie);

                    HttpCookie cookies_ = new HttpCookie("gm_userinfo");
                    cookies_.Values.Add("id", pLoginReturn.ID);
                    cookies_.Values.Add("name", pLoginReturn.Name);
                    cookies_.Values.Add("rid", pLoginReturn.Role_ID);
                    cookies_.Values.Add("guid", tokenValue);
                    cookies_.Values.Add("Type", pLoginReturn.Type);
                    cookies_.Values.Add("DataRole", pLoginReturn.DataRole);
                    cookies_.Values.Add("Account", account);
                    //域
                    if (!autoLogin)
                    {
                        cookies_.Expires = DateTime.Now.AddDays(2);
                    }
                    else
                    {
                        cookies_.Expires = DateTime.Now.AddDays(7);
                    }
                    this.Response.Cookies.Add(cookies_);
                    this.Response.AppendCookie(cookies_);

                    //string xinfo = Session["Type"].ToString() == "1" ? " 老师" : (Session["Type"].ToString() == "2" ? " 学生" : (Session["Type"].ToString() == "3" ? " 企业" : ""));

                    string userinfor = "{\"Login\":true,\"Type\":\"" + pLoginReturn.Type + "\",\"Name\":\"" + Session["name"] + "\",\"Email\":\"\",\"flag\":\"" + flag + "\"}";
                    Response.AddHeader("P3P", "CP='IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT'");
                    return(callback + "(" + userinfor + ")");
                }
            }
            catch (Exception ex) { string s = ex.Message; }
            Response.AddHeader("P3P", "CP='IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT'");
            return(callback + "({\"Login\":false})");
        }
        public ContentResult LoginOn(string account, string password, bool autoLogin)
        {
            try
            {
                HttpCookie myCookie = new HttpCookie("gm_userinfo", null);
                myCookie.Expires = DateTime.Now.AddDays(-1);
                Response.Cookies.Add(myCookie);
                Session.RemoveAll();

                Basice      pLoginModels = new Basice();
                LoginReturn pLoginReturn;
                // 登录唯一凭证
                string tokenValue = Guid.NewGuid().ToString().ToUpper();
                #region /*获得IP*/
                string userIp = "";
                if (Request.ServerVariables["HTTP_VIA"] != null)
                {
                    userIp = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
                }
                else
                {
                    userIp = Request.ServerVariables["REMOTE_ADDR"].ToString();
                }
                #endregion
                // 登录
                if (pLoginModels.Login(account, password, userIp, tokenValue, autoLogin, out pLoginReturn))
                {
                    //session 赋值
                    Session["id"]       = pLoginReturn.ID;
                    Session["name"]     = pLoginReturn.Name;
                    Session["rid"]      = pLoginReturn.Role_ID;
                    Session["guid"]     = tokenValue;
                    Session["Type"]     = pLoginReturn.Type;
                    Session["DataRole"] = pLoginReturn.DataRole;
                    Session["Account"]  = account;

                    //HttpCookie myCookie = new HttpCookie("gm_userinfo", null);
                    //myCookie.Expires = DateTime.Now.AddDays(-1d);
                    //Response.Cookies.Add(myCookie);

                    HttpCookie cookies_ = new HttpCookie("gm_userinfo");
                    cookies_.Values.Add("id", pLoginReturn.ID);
                    cookies_.Values.Add("name", pLoginReturn.Name);
                    cookies_.Values.Add("rid", pLoginReturn.Role_ID);
                    cookies_.Values.Add("guid", tokenValue);
                    cookies_.Values.Add("Type", pLoginReturn.Type);
                    cookies_.Values.Add("DataRole", pLoginReturn.DataRole);
                    cookies_.Values.Add("Account", account);
                    //域
                    if (!autoLogin)
                    {
                        cookies_.Expires = DateTime.Now.AddDays(2);
                    }
                    else
                    {
                        cookies_.Expires = DateTime.Now.AddDays(7);
                    }
                    this.Response.Cookies.Add(cookies_);
                    this.Response.AppendCookie(cookies_);

                    string xinfo = Session["Type"].ToString() == "1" ? " 老师" : (Session["Type"].ToString() == "2" ? " 学生" : (Session["Type"].ToString() == "3" ? " 企业" : ""));
                    return(Content("[{\"Login\":\"True\",\"Type\":\"" + pLoginReturn.Type + "\",\"STR\":\"" + Session["name"] + xinfo + "\"}]"));
                }
                return(Content("no"));
            }
            catch (Exception ex) { string s = ex.Message; }
            return(null);
        }