Ejemplo n.º 1
0
        private void UserCheck()
        {
            if (Request.QueryString["userid"] == null)
            {
                Response.Redirect("http://caslogin.ecnu.edu.cn/login.aspx?url=" + Request.Url.ToString() + "");
            }

            string userid = Request.QueryString["userid"].ToString(); //获取userid
            string token  = Request.QueryString["token"].ToString();  //获取token

            Session["userid"] = userid;
            Session["token"]  = token;
            var     ecnuws  = new cn.edu.ecnu.datawebservice.ECNUWebService();
            DataSet tokends = ecnuws.CASLOGIN_Check(userid, token); //调用webservice接口,详细接口信息查看相关webservice接口文档

            if (tokends == null)
            {
                Response.Redirect("http://caslogin.ecnu.edu.cn/login.aspx?url=" + Request.Url.ToString() + "&error=webservice出错, 请从网站登录页面登录");
            }

            if (tokends.Tables[0].Rows[0][0].ToString().Contains("OK:"))
            {
                //此处为认证部分结束,由业务系统自定义代码,跳转其他页面
                //判断本地是否有用户
                var user = new WebForm.Common.UserService().CreateNewUser(userid);

                //保存用户信息
                FoWoSoft.Platform.OnlineUsers bou = new FoWoSoft.Platform.OnlineUsers();
                Guid uniqueID = Guid.NewGuid();
                Session[FoWoSoft.Utility.Keys.SessionKeys.UserID.ToString()]       = user.ID;
                Session[FoWoSoft.Utility.Keys.SessionKeys.UserUniqueID.ToString()] = uniqueID;
                bou.Add(user, uniqueID);
            }
            else  //认证出错后继续跳转到统一身份认证页面加上ERROR参数
            {
                string url = Request.Url.ToString();
                Response.Redirect("http://caslogin.ecnu.edu.cn/login.aspx?url=" + url + "&error=" + tokends.Tables[0].Rows[0][0].ToString() + ",请从网站登录页面登录");
            }
        }
Ejemplo n.º 2
0
        private void check()
        {
            string isVcodeSessionKey = FoWoSoft.Utility.Keys.SessionKeys.IsValidateCode.ToString();
            string vcodeSessionKey   = FoWoSoft.Utility.Keys.SessionKeys.ValidateCode.ToString();

            string account       = Request.Form["Account"];
            string password      = Request.Form["Password"];
            string force         = Request.Form["Force"];
            string vcode         = Request.Form["VCode"];
            bool   isSessionLost = "1" == Request.QueryString["session"];//是否是超时后再登录

            if (Session[isVcodeSessionKey] != null &&
                "1" == Session[isVcodeSessionKey].ToString() &&
                (Session[vcodeSessionKey] == null ||
                 string.Compare(Session[vcodeSessionKey].ToString(), vcode.Trim(), true) != 0))
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "error", "alert('验证码错误!');", true);
            }
            else if (account.IsNullOrEmpty() || password.IsNullOrEmpty())
            {
                Session[isVcodeSessionKey] = "1";
                FoWoSoft.Platform.Log.Add("用户登录失败", string.Concat("用户:", account, "登录失败,帐号或密码为空"), FoWoSoft.Platform.Log.Types.用户登录);
                Script = "alert('帐号或密码不能为空!');";
            }
            else
            {
                FoWoSoft.Platform.Users busers = new FoWoSoft.Platform.Users();
                var user = busers.GetByAccount(account.Trim());
                if (user == null || string.Compare(user.Password, busers.GetUserEncryptionPassword(user.ID.ToString(), password.Trim()), false) != 0)
                {
                    Session[isVcodeSessionKey] = "1";
                    FoWoSoft.Platform.Log.Add("用户登录失败", string.Concat("用户:", account, "登录失败,帐号或密码错误"), FoWoSoft.Platform.Log.Types.用户登录);
                    Script = "alert('帐号或密码错误!');";
                }
                else if (user.Status == 1)
                {
                    Session[isVcodeSessionKey] = "1";
                    FoWoSoft.Platform.Log.Add("用户登录失败", string.Concat("用户:", account, "登录失败,帐号已被冻结"), FoWoSoft.Platform.Log.Types.用户登录);
                    Script = "alert('帐号已被冻结!');";
                }
                else
                {
                    FoWoSoft.Platform.OnlineUsers bou = new FoWoSoft.Platform.OnlineUsers();
                    var onUser = bou.Get(user.ID);
                    if (onUser != null && "1" != force)
                    {
                        string ip = onUser.IP;
                        Session.Remove(isVcodeSessionKey);
                        Script = "if(confirm('当前帐号已经在" + ip + "登录,您要强行登录吗?')){$('#Account').val('" + account + "');$('#Password').val('" + password + "');$('#Force').val('1');$('#form1').submit();}";
                    }
                    else
                    {
                        Guid uniqueID = Guid.NewGuid();
                        Session[FoWoSoft.Utility.Keys.SessionKeys.UserID.ToString()]       = user.ID;
                        Session[FoWoSoft.Utility.Keys.SessionKeys.UserUniqueID.ToString()] = uniqueID;
                        bou.Add(user, uniqueID);
                        Session.Remove(isVcodeSessionKey);
                        FoWoSoft.Platform.Log.Add("用户登录成功", string.Concat("用户:", user.Name, "(", user.ID, ")登录成功"), FoWoSoft.Platform.Log.Types.用户登录);
                        if (isSessionLost)
                        {
                            Script = "alert('登录成功!');new RoadUI.Window().close();";
                        }
                        else
                        {
                            Script = "top.location='" + Common.Tools.BaseUrl + "Default.aspx';";
                        }
                    }
                }
            }
        }