Esempio n. 1
0
        /// <summary>
        /// 同步用户
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSynchronous_Click(object sender, EventArgs e)
        {
            //同步系统用户获取系统下所有用户信息
            List <UserInUserInfo> userinfo = SecurityHandler.LoginOn(Request.Cookies.Get("authorizationcode").Value.ToString()).GetUserInfoList();
            //本地用户
            List <Dictuser> allUser           = new DictuserService().GetDictuser().ToList();
            Dictionary <string, Dictuser> map = new Dictionary <string, Dictuser>();

            for (int i = 0; i < allUser.Count; i++)
            {
                map.Add(allUser[i].Usercode, allUser[i]);
            }
            #region 用户数据更新
            foreach (UserInUserInfo sysu in userinfo)
            {
                if (map.ContainsKey(sysu.USERNAME))
                {
                    Dictuser newUser = map[sysu.USERNAME];
                    if (sysu.ECHONAME != null)
                    {
                        newUser.Username = sysu.ECHONAME;
                    }
                    if (sysu.PASSWORD != null)
                    {
                        newUser.Password = sysu.PASSWORD;
                    }
                    try
                    {
                        new DictuserService().SaveDictlab(newUser);
                    }
                    catch (Exception ex)
                    {
                        MessageBoxShow(ex.Message, MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    try
                    {
                        Dictuser newUser = new Dictuser();
                        newUser.Username      = sysu.ECHONAME;
                        newUser.Usercode      = sysu.USERNAME;
                        newUser.Password      = sysu.PASSWORD;
                        newUser.Dictlabid     = 0;
                        newUser.Dictlabdeptid = 0;
                        newUser.Active        = "1";
                        new DictuserService().SaveDictlab(newUser);
                    }
                    catch (Exception ex)
                    {
                        MessageBoxShow(ex.Message, MessageBoxIcon.Error);
                        return;
                    }
                }
            }
            MessageBoxShow("用户已同步!", MessageBoxIcon.Information);
            BindGrid();
            #endregion
        }
Esempio n. 2
0
        protected void btLogin_Click(object sender, EventArgs e)
        {
            try
            {
                if (Session["check"] == null)
                {
                    this.tbCaptcha.Text = string.Empty;
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script language=\"javascript\">alert(\"验证码失效!\")</script>");
                    return;
                }
                if (tbCaptcha.Text != Session["check"].ToString())
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script language=\"javascript\">alert(\"验证码错误!\")</script>");
                    this.tbCaptcha.Text = string.Empty;
                    return;
                }
                string usercode = Server.HtmlEncode(tbUserName.Text);
                string passWord = tbPassWord.Text;
                //进行用户登录,security.LoginResult为null或者security.LoginResult.IsPassed && security.LoginResult.AuthorizationCode != ""
                //都是登录失败
                SecurityHandler security = SecurityHandler.Login(usercode, passWord);
                if (security.LoginResult.SystemCode == null) //判断存不存在
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script language=\"javascript\">alert(\"用户名或密码错误!\")</script>");
                    this.tbUserName.Text = string.Empty;
                    this.tbPassWord.Text = string.Empty;
                    this.tbCaptcha.Text  = string.Empty;
                    return;
                }
                var      aa   = SecurityHandler.LoginOn(security.LoginResult.AuthorizationCode).GetCurrentUserInfo();
                Dictuser user = new Dictuser();
                user.Usercode = aa.USERNAME;
                user          = new DictuserService().GetDictuserInfoByUserCode(user);
                if (user != null)
                {
                    UserInfo userInfo = new UserInfo();
                    userInfo.AuthorizationCode = security.LoginResult.AuthorizationCode;
                    userInfo.userCode          = user.Usercode;
                    userInfo.userName          = user.Username;
                    userInfo.userId            = Convert.ToInt32(user.Dictuserid);
                    userInfo.loginTime         = DateTime.Now;
                    userInfo.joinLabidstr      = user.Joinlabid;
                    userInfo.dictlabid         = user.Dictlabid;
                    userInfo.joinDeptstr       = user.Joindeptid;
                    userInfo.dictlabdeptid     = user.Dictlabdeptid;
                    userInfo.sysSetting        = GetSysSetting();
                    Session["UserInfo"]        = userInfo;
                }

                if (security.LoginResult.IsPassed && security.LoginResult.AuthorizationCode != "")
                {
                    //这里的Cookie名字不能更改
                    HttpCookie cookie = new HttpCookie("authorizationcode");
                    cookie.Value = security.LoginResult.AuthorizationCode;
                    TimeSpan ts = new TimeSpan(1, 0, 0, 0);
                    cookie.Expires = DateTime.Now.Add(ts);//添加作用时间
                    Response.AppendCookie(cookie);

                    if (!RegexPassWordSecurity(passWord))
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "redirectToChangePassword",
                                                           "<script> alert('您的密码安全性较弱,请重新修改密码'); window.location.href='EditPassword.aspx';</script>");

                        return;
                    }

                    Response.Redirect("Main.aspx", false);
                    //////PageContext.RegisterStartupScript("top.location.href = 'Main.aspx';");
                    //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script language=\"javascript\">top.location.href = 'Main.aspx';</script>");
                }
                else
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script language=\"javascript\">alert(\"用户名或密码错误!\")</script>");
                    this.tbUserName.Text = string.Empty;
                    this.tbPassWord.Text = string.Empty;
                    this.tbCaptcha.Text  = string.Empty;
                    return;
                }
            }
            catch (Exception ex)
            {
                Alert.ShowInTop(ex.Message, "体检系统");
            }
        }