예제 #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["loginSession"] == null)
     {
         Response.Write("<script>location.href='/Login.aspx';</script>");
         //Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "location.href='/Login.aspx';", true);
         return;
     }
     else
     {
         if (Session["loginIden"].ToString() != "Teacher")
         {
             Response.Write("<script>location.href='/Login.aspx';</script>");
             //Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "location.href='/Login.aspx';", true);
             return;
         }
         if (Session["modifyErrorMsg"] != null) // 修改失败
         {
             Page.ClientScript.RegisterStartupScript(Page.GetType(), "errorMsg",
                                                     "$(document).ready(function(){changeBorderColor('#" + Session["modifyErrorID"] + "','" + Session["modifyErrorMsg"] + "');});", true);
             Session["modifyErrorID"]  = null;
             Session["modifyErrorMsg"] = null;
         }
         if (!IsPostBack)
         {
             Models.Teacher teacher = BLL_Teacher.query(Session["loginSession"].ToString());
             inputUsername.Text        = teacher.username;
             selectorSex.SelectedIndex = Boolean.Parse(teacher.sex) ? 0 : 1;
             inputYear.Text            = teacher.age;
         }
     }
 }
예제 #2
0
        protected void buttonSubmit_Click(object sender, EventArgs e)
        {
            if (Session["loginSession"] == null || Session["loginIden"].ToString() != "Teacher")
            {
                return;
            }

            string username    = Session["loginSession"].ToString();
            string oldpassword = inputOldPassword.Text.Trim();
            string sex         = selectorSex.SelectedValue;
            string password    = inputPassword.Text.Trim();
            string age         = inputYear.Text.Trim();

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

            Models.Teacher teacher = null;
            if (password.Length == 0)
            {
                teacher = new Models.Teacher(username, "", sex, age);
            }
            else
            {
                teacher = new Models.Teacher(username, password, sex, age);
            }

            if (BLL_Teacher.modify(teacher))
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert", "alert('修改成功,刷新页面查看更新后的内容!');", true);
                Response.Write("<script>location.href='/Teacher/Modify.aspx';</script>");
                //Page.ClientScript.RegisterStartupScript(Page.GetType(), "transfer", "location.href='/Teacher/Modify.aspx';", true);
            }
            else
            {
                Session["modifyErrorID"]  = "stdContentMoudle_stdContent_inputOldPassword";
                Session["modifyErrorMsg"] = "原密码输入错误!";
                Response.Write("<script>location.href='/Teacher/Modify.aspx';</script>");
                //Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "location.href='/Teacher/Modify.aspx';", true);
            }
        }
예제 #3
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);
                }
            }
        }