Exemplo n.º 1
0
        private void BtnLogin_Click(object sender, RoutedEventArgs e)
        {
            var    teacherBll = new TeacherBll();
            string userName   = TxtBoxUserName.Text;
            string password   = TxtBoxPassword.Password;

            if (RBtnTeacher.IsChecked == true)
            {
                var teacher = new Teacher()
                {
                    UserName = userName,
                    Password = password
                };

                if (teacherBll.Login(teacher))
                {
                    var teacherDashboard = new TeacherDashboard();
                    //Close();
                    teacherDashboard.Show();
                }
                else
                {
                    MessageBox.Show("Invalid Credentials");
                }
            }
            else if (RBtnStudent.IsChecked == true)
            {
                var studentBll = new StudentBll();
                var student    = new Student()
                {
                    UserName = userName,
                    Password = password
                };
                if (studentBll.Login(student))
                {
                    var studentDashboard = new StudentDashboard();
                    //Close();
                    studentDashboard.Show();
                }
                else
                {
                    MessageBox.Show("Invalid Credentials");
                }
            }
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string op = Request["op"];
                if (op == "login")
                {
                    account  = Request["userName"].Trim();
                    pwd      = Request["pwd"].Trim();
                    captcha  = Request["captcha"].ToLower();
                    usertype = Request["type"].Trim();
                    string Verification = vildata();
                    string roles        = "";
                    if (Verification.Length == 0)
                    {
                        int loginstate       = 0;
                        RSACryptoService rsa = new RSACryptoService();
                        switch (usertype)
                        {
                        case "teacher":
                            TeacherBll teaBll = new TeacherBll();
                            if (teaBll.GetModel(account).TeaType == 1)
                            {
                                Teacher tea = teaBll.Login(account, rsa.Decrypt(pwd));
                                if (tea == null)
                                {
                                    loginstate = 0;
                                }
                                else
                                {
                                    loginstate           = 1;
                                    Session["loginuser"] = tea;
                                    Session["state"]     = 1;
                                    Response.Cookies[FormsAuthentication.FormsCookieName].Value = null;
                                    roles = "teacher";
                                    FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, account, DateTime.Now, DateTime.Now.AddMinutes(30), true, roles); //建立身份验证票对象
                                    string HashTicket = FormsAuthentication.Encrypt(Ticket);                                                                              //加密序列化验证票为字符串
                                    //Session["HashTicket"] = HashTicket;
                                    HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, HashTicket);                                              //生成Cookie
                                    Context.Response.Cookies.Add(UserCookie);                                                                                             //票据写入Cookie
                                    isLogined(account);
                                }
                            }
                            else
                            {
                                Response.Write("管理员");
                                Response.End();
                            }
                            break;

                        case "student":
                            StudentBll sdao = new BLL.StudentBll();
                            Student    stu  = sdao.Login(account, rsa.Decrypt(pwd));

                            if (stu == null)
                            {
                                loginstate = 0;
                            }
                            else
                            {
                                loginstate           = 1;
                                Session["loginuser"] = stu;
                                Session["state"]     = 3;
                                Response.Cookies[FormsAuthentication.FormsCookieName].Value = null;
                                roles = "student";
                                FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, account, DateTime.Now, DateTime.Now.AddMinutes(30), true, roles); //建立身份验证票对象
                                string HashTicket = FormsAuthentication.Encrypt(Ticket);                                                                              //加密序列化验证票为字符串
                                //Session["HashTicket"] = HashTicket;
                                HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, HashTicket);                                              //生成Cookie
                                Context.Response.Cookies.Add(UserCookie);                                                                                             //票据写入Cookie
                                isLogined(account);
                            }
                            break;
                        }
                        if (loginstate == 0)
                        {
                            Response.Write("用户名或密码错误");
                            Response.End();
                        }
                        else if (loginstate == 1)
                        {
                            if (Convert.ToInt32(Session["state"]) == 1)
                            {
                                Teacher tea = (Teacher)Session["loginuser"];
                                LogHelper.Info(this.GetType(), tea.TeaAccount + " - " + tea.TeaName + " - 登录");
                            }
                            else if (Convert.ToInt32(Session["state"]) == 3)
                            {
                                Student stu = (Student)Session["loginuser"];
                                LogHelper.Info(this.GetType(), stu.StuAccount + " - " + stu.RealName + " - 登录");
                            }
                            Response.Write("登录成功");
                            Response.End();
                        }
                        else
                        {
                            Response.Write("登录失败");
                            Response.End();
                        }
                    }
                    else
                    {
                        LogHelper.Error(this.GetType(), account + " - " + Verification);
                        Response.Write(Verification);
                        Response.End();
                    }
                }
            }
            catch
            {
            }
        }
Exemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string op  = Request["op"];
            string pwd = "";

            if (op == "login")
            {
                try
                {
                    teaAccount = Request["userName"].Trim();
                    pwd        = Request["pwd"].Trim();
                    TeacherBll       bll     = new TeacherBll();
                    string           roles   = "administrator";
                    RSACryptoService rsa     = new RSACryptoService();
                    Teacher          teacher = bll.Login(teaAccount, rsa.Decrypt(pwd));
                    if (teacher != null)
                    {
                        if (teacher.TeaType == 0)
                        {
                            Session["user"]  = teacher;
                            Session["state"] = 0;
                            Response.Cookies[FormsAuthentication.FormsCookieName].Value = null;
                            FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, teaAccount, DateTime.Now, DateTime.Now.AddMinutes(30), true, roles); //建立身份验证票对象
                            string HashTicket = FormsAuthentication.Encrypt(Ticket);                                                                                 //加密序列化验证票为字符串
                            //Session["HashTicket"] = HashTicket;
                            HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, HashTicket);                                                 //生成Cookie
                            Context.Response.Cookies.Add(UserCookie);                                                                                                //票据写入Cookie
                            isLogined(teaAccount);
                            LogHelper.Info(this.GetType(), teacher.TeaAccount + " - " + teacher.TeaName + " - 登录");
                            Response.Write("登录成功");
                            Response.End();
                        }
                        else if (teacher.TeaType == 2)
                        {
                            Session["user"]  = teacher;
                            Session["state"] = 2;
                            Response.Cookies[FormsAuthentication.FormsCookieName].Value = null;
                            FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, teaAccount, DateTime.Now, DateTime.Now.AddMinutes(30), true, roles); //建立身份验证票对象
                            string HashTicket = FormsAuthentication.Encrypt(Ticket);                                                                                 //加密序列化验证票为字符串
                            //Session["HashTicket"] = HashTicket;
                            HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, HashTicket);                                                 //生成Cookie
                            Context.Response.Cookies.Add(UserCookie);                                                                                                //票据写入Cookie
                            isLogined(teaAccount);
                            LogHelper.Info(this.GetType(), teacher.TeaAccount + " - " + teacher.TeaName + " - 登录");
                            Response.Write("登录成功");
                            Response.End();
                        }
                        else
                        {
                            LogHelper.Error(this.GetType(), "用户名或密码错误");
                            Response.Write("用户名或密码错误");
                            Response.End();
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Error(this.GetType(), ex);
                }
            }
        }