예제 #1
0
        protected void btLogin_Click(object sender, EventArgs e)
        {
            try
            {
                String          empId    = tbLoginUserName.Text.Trim();
                String          password = tbLoginPassword.Text.Trim();
                DataAccessLayer dal      = new DataAccessLayer();
                Employee        emp      = null;
                int             ret      = dal.ValidateUserLogin(empId, password, ref emp);

                if (ret == 1)
                {
                    loginAlert.Style.Add("display", "none");
                    if (chbRememberMe.Checked)
                    {
                        // Encode cookie for username
                        HttpCookie cookieUserName = new HttpCookie("UserName");
                        cookieUserName.Value   = AppSecurity.Base64Encode(empId);
                        cookieUserName.Expires = DateTime.Now.AddDays(7);

                        //Encode cookie for password
                        HttpCookie cookiePassword = new HttpCookie("Password");
                        cookiePassword.Value   = AppSecurity.Base64Encode(password);
                        cookiePassword.Expires = DateTime.Now.AddDays(7);

                        //Add cookies to response
                        Response.Cookies.Add(cookieUserName);
                        Response.Cookies.Add(cookiePassword);
                    }
                    else
                    {
                        Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(-1);
                        Response.Cookies["Password"].Expires = DateTime.Now.AddDays(-1);
                    }

                    if (emp != null)
                    {
                        Session["EmployeeId"] = empId;
                        Session["FirstName"]  = emp.FirstName;
                        Session["LastName"]   = emp.LastName;
                        Session["EMAIL"]      = emp.Email;
                        Session["USER_GUID"]  = emp.GUID;
                        if (emp.IsAdmin)
                        {
                            Session["isAdmin"] = true;
                            Response.Redirect("AdminHomePage.aspx");
                        }
                        else
                        {
                            Session["isAdmin"] = false;
                            Response.Redirect("UserHomePage.aspx");
                        }
                    }
                }
                else if (ret == -1)
                {
                    signupbox.Style.Add("display", "none");
                    loginbox.Style.Add("display", "inline");
                    loginAlert.Style.Add("display", "inline");
                    loginAlert.Attributes.Add("class", "alert-danger");
                    loginAlert.InnerText = "Incorrect Login Credentials";
                }
            }
            catch
            {
                throw;
            }
        }