Пример #1
0
        protected void buttonSubmit_Click(object sender, EventArgs e)
        {
            if (Session["loginSession"] == null || Session["loginIden"].ToString() != "Student")
            {
                return;
            }

            string username    = Session["loginSession"].ToString();
            string oldpassword = inputOldPassword.Text.Trim();
            string password    = inputPassword.Text.Trim();
            string sex         = selectorSex.SelectedIndex == 0 ? "1" : "0";
            string age         = inputYear.Text.Trim();
            string grade       = selectGrade.SelectedValue;
            string major       = selectMajor.SelectedValue;

            if (!BLL_Student.login(username, oldpassword))
            {
                Session["modifyErrorID"]  = "stdContentMoudle_stdContent_inputOldPassword";
                Session["modifyErrorMsg"] = "原密码输入错误!";
                Response.Write("<script>location.href='/Student/Modify.aspx';</script>");
                //Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "location.href='/Student/Modify.aspx';", true);
                return;
            }

            Models.Student student = null;
            if (password.Length == 0)
            {
                student = new Models.Student(username, "", sex, grade, age, major, "", "");
            }
            else
            {
                student = new Models.Student(username, password, sex, grade, age, major, "", "");
            }

            if (BLL_Student.modify(student))
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert", "alert('修改成功,刷新页面查看更新后的内容!');", true);
                Response.Write("<script>location.href='/Student/Modify.aspx';</script>");
                //Page.ClientScript.RegisterStartupScript(Page.GetType(), "transfer", "location.href='/Student/Modify.aspx';", true);
            }
            else
            {
                Session["modifyErrorID"]  = "stdContentMoudle_stdContent_inputOldPassword";
                Session["modifyErrorMsg"] = "原密码输入错误!";
                Response.Write("<script>location.href='/Student/Modify.aspx';</script>");
                //Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "location.href='/Student/Modify.aspx';", true);
            }
        }
Пример #2
0
        /// <summary>
        /// 登录按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Click_Login(object sender, EventArgs e)
        {
            string username          = inputUsername.Text.Trim();
            string password          = inputPassword.Text.Trim();
            string checkcode_correct = Session["CheckCode"].ToString(); // 正确验证码
            string checkcode_user    = checkCode.Text.Trim();

            checkcode_user = checkcode_user.ToLower();
            if (!Regex.IsMatch(username, @"^[0-9a-zA-Z_]{1,21}$") ||
                !Regex.IsMatch(password, @"^[!@#$%^&*()0-9a-zA-Z_?<>.]{7,20}$")
                ) // 非法请求
            {
                return;
            }
            if (checkBoxRemember.Checked) // 记住用户名
            {
                Response.Cookies["loginCookies"].Value   = username;
                Response.Cookies["loginCookies"].Expires = DateTime.Now.AddDays(7);
            }
            else
            {
                Response.Cookies["loginCookies"].Value   = "";
                Response.Cookies["loginCookies"].Expires = DateTime.Now.AddDays(-7);
            }
            if (!checkcode_user.Equals(checkcode_correct)) // 校验验证码
            {
                Session["loginErrorID"] = "stdContentMoudle_stdContent_checkCode";
                Session["loginError"]   = "验证码错误!";
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "location.href='/Login.aspx';", true);
                return;
            }

            bool loginResult = false;

            if (checkBoxTeacher.Checked)
            {
                loginResult = BLL_Teacher.login(username, password);
            }
            else
            {
                loginResult = BLL_Student.login(username, password);
            }

            if (!loginResult) // 登录失败
            {
                Session["loginErrorID"] = "stdContentMoudle_stdContent_inputPassword";
                Session["loginError"]   = "用户名或密码错误!";
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "location.href='/Login.aspx';", true);
            }
            else
            {
                Session["loginSession"] = username;
                if (checkBoxTeacher.Checked)
                {
                    Session["loginIden"] = "Teacher";
                    Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "location.href='/Teacher/Default.aspx';", true);
                }
                else
                {
                    Session["loginIden"] = "Student";
                    Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "location.href='/Student/Default.aspx';", true);
                }
            }
        }