Esempio n. 1
0
        /// <summary>
        /// 保存资料
        /// </summary>
        protected void SaveInfo()
        {
            SysUser user = new SysUser();

            if (WS.RequestInt("id") > 0)
            {
                user = SysUserView.GetModelByID(WS.RequestInt("id").ToString());
            }
            else if (txt_Password.Text.Length == 0)
            {
                Js.AlertAndGoback("新增用户时,密码不能为空");
            }

            user.UserName = txt_UserName.Text;
            if (txt_Password.Text.Length > 0)
            {
                user.UserPass = Voodoo.Security.Encrypt.Md5(txt_Password.Text);
            }

            user.SafeQuestion = ddl_Question.SelectedValue;
            user.SafeAnswer   = txt_Answer.Text;
            user.Email        = txt_Email.Text;
            user.TelNumber    = txt_TelNumber.Text;
            user.Department   = ddl_Department.SelectedValue.ToInt32();
            user.UserGroup    = ddl_Group.SelectedValue.ToInt32();
            user.ChineseName  = txt_ChineseName.Text;
            user.Enabled      = chk_Enable.Checked;

            if (WS.RequestInt("id") > 0)
            {
                //修改
                SysUserView.Update(user);
                Js.AlertAndChangUrl("修改成功!", "SysUserList.aspx");
            }
            else
            {
                user.LastLoginTime = DateTime.Now;
                user.LastLoginIP   = WS.GetIP();
                Result r = SysUserAction.UserAdd(user);

                if (r.Success)
                {
                    Js.AlertAndChangUrl(r.Text, "SysUserList.aspx");
                }
                else
                {
                    Js.AlertAndGoback(r.Text);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 用户登陆
        /// </summary>
        /// <param name="UserName">账号</param>
        /// <param name="PassWord">密码</param>
        /// <param name="Question">问题</param>
        /// <param name="Answer">答案</param>
        /// <returns></returns>
        public static Result UserLogin(string UserName, string PassWord, string Question, string Answer)
        {
            Result r = new Result();

            SysUser user = SysUserView.Find(string.Format("UserName='******'", UserName));

            if (user.UserPass == null || user.UserPass != Encrypt.Md5(PassWord))
            {
                r.Success = false;
                r.Text    = "账号或密码错误";
                return(r);
            }
            else
            {
                //验证问答
                if (user.SafeQuestion != Question || user.SafeAnswer != Answer)
                {
                    r.Success = false;
                    r.Text    = "问题或者回答错误!";
                    return(r);
                }
                else
                {
                    if (user.Enabled == false)
                    {
                        r.Success = false;
                        r.Text    = "用户账号已经停用!";
                        return(r);
                    }
                    else
                    {
                        //更新登陆记录
                        user.Logincount++;
                        user.LastLoginIP   = WS.GetIP();
                        user.LastLoginTime = DateTime.Now;
                        SysUserView.Update(user);

                        //写入Session

                        System.Web.HttpContext.Current.Session["sys_user"] = user.ID;

                        r.Success = true;
                        r.Text    = "登陆成功!";
                        return(r);
                    }
                }
            }
        }