Esempio n. 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() != "Student")
         {
             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["modifyErrorMsg"] + "','" + Session["modifyErrorMsg"] + "');});", true);
             Session["modifyErrorID"]  = null;
             Session["modifyErrorMsg"] = null;
         }
         if (!IsPostBack)
         {
             Models.Student student = BLL_Student.query(Session["loginSession"].ToString());
             inputUsername.Text        = student.username;
             selectorSex.SelectedIndex = Boolean.Parse(student.sex) ? 0 : 1;
             inputYear.Text            = student.age;
             selectGrade.SelectedValue = student.grade;
             selectMajor.SelectedValue = student.major;
         }
     }
 }
Esempio n. 2
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);
            }
        }
Esempio n. 3
0
        protected void buttonSubmit_Click(object sender, EventArgs e)
        {
            string   username          = inputUsername.Text.Trim();
            string   password          = inputPassword.Text.Trim();
            string   repassword        = inputRepeatPassword.Text.Trim();
            string   sex               = selectorSex.SelectedValue;
            string   age               = inputYear.Text.Trim();
            string   grade             = selectGrade.SelectedValue;
            string   major             = selectMajor.SelectedValue;
            string   checkcode_correct = Session["CheckCode"].ToString(); // 正确验证码
            string   checkcode_user    = checkCode.Text.Trim();
            string   ip    = BLL_IP.GetIP();
            DateTime dtime = DateTime.Now;
            string   time  = dtime.ToString();

            if (!Regex.IsMatch(username, @"^[0-9a-zA-Z_]{1,21}$") ||
                !Regex.IsMatch(password, @"^[!@#$%^&*()0-9a-zA-Z_?<>.]{7,20}$") ||
                password != repassword
                ) // 非法请求
            {
                return;
            }
            if (!checkcode_correct.Equals(checkcode_user))
            {
                Session["regErrorID"] = "stdContentMoudle_stdContent_checkCode";
                Session["regError"]   = "验证码错误!";
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "location.href='/Register.aspx';", true);
                return;
            }

            Models.Student student = new Models.Student(username, password, sex, grade, age, major, ip, time);;
            if (BLL_Student.register(student))
            {
                Session["regSuccess"] = username;
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "location.href='/Login.aspx';", true);
            }
            else
            {
                Session["regErrorID"] = "stdContentMoudle_stdContent_inputUsername";
                Session["regError"]   = "注册失败,请更换用户名后重试!";
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "location.href='/Register.aspx';", true);
            }
        }
Esempio n. 4
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);
                }
            }
        }