protected void btnLogin_Click(object sender, EventArgs e) { BusinessRules.CUser objUser = new BusinessRules.CUser(); string role; role = objUser.login(txtUsername.Text, txtPassword.Text); if (role == "") { lblError.Text = "Invalid Login"; } else { //create an auth ticket to store the identity FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, txtUsername.Text, DateTime.Now, DateTime.Now.AddMinutes(30), true, role, FormsAuthentication.FormsCookiePath); //encrypt the ticket for extra security string hash = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash); Response.Cookies.Add(cookie); Response.Redirect("home.aspx", true); } }
protected void btnRegister_Click(object sender, EventArgs e) { BusinessRules.CUser objUser = new BusinessRules.CUser(); objUser.register(txtUsername.Text, txtPassword.Text, rblRole.SelectedValue); Response.Redirect("login.aspx", true); }
protected void btnLogin_Click(object sender, EventArgs e) { //instantiate the user class BusinessRules.CUser objUser = new BusinessRules.CUser(); string role = objUser.login(txtUsername.Text, txtPassword.Text); //try logging in, show an error if it fails if (role == "") { lblError.Text = "Invalid Login"; } else { //login is valid //create an authentication ticket FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, //version txtUsername.Text, //identity DateTime.Now, //issue date/time DateTime.Now.AddMinutes(30), //30 min default expiry false, //don't persist across browser sessions role, //user role FormsAuthentication.FormsCookiePath); //encrypt the cookie string hash = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash); //save the cookie to the browser Response.Cookies.Add(cookie); Response.Redirect("user.aspx", true); } }
protected void gvUsers_RowDeleting(object sender, GridViewDeleteEventArgs e) { BusinessRules.CUser objUser = new BusinessRules.CUser(); objUser.deleteUser(Convert.ToInt32(gvUsers.DataKeys[e.RowIndex].Values["UserID"].ToString())); getUsers(); }
protected void btnLogin_Click(object sender, EventArgs e) { //instantiate the user class BusinessRules.CUser objUser = new BusinessRules.CUser(); string role = objUser.login(txtUsername.Text, txtPassword.Text); //try logging in, show an error if it fails if (role == "") { lblError.Text = "Invalid Login"; } else { //login is valid //create an authentication ticket FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, //version txtUsername.Text, //identity DateTime.Now, //issue date/time DateTime.Now.AddMinutes(30), //30 min default expiry false, //don't persist across browser sessions role, //user role FormsAuthentication.FormsCookiePath); //encrypt the cookie string hash = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash); //save the cookie to the browser Response.Cookies.Add(cookie); Response.Redirect("user.aspx", true); } }
protected void btnRegister_Click(object sender, EventArgs e) { BusinessRules.CUser objUser = new BusinessRules.CUser(); objUser.register(txtUsername.Text, txtPassword.Text, rblRole.SelectedValue); Response.Redirect("login.aspx", true); }
protected void getCourses() { //instantiate an instance of our supplier class BusinessRules.CUser objUsers = new BusinessRules.CUser(); //call the getSuppliers fn & bind the resulting datareader to the grid gvCourses.DataSource = objUsers.getUsers(); gvCourses.DataBind(); }
protected void btnRegister_Click(object sender, EventArgs e) { //create an instance of our business class BusinessRules.CUser objUser = new BusinessRules.CUser(); //call the register function and redirect the user objUser.register(txtUsername.Text, txtPassword.Text, rblRole.SelectedValue); Response.Redirect("login.aspx", true); }
protected void getCourses() { //instantiate an instance of our supplier class BusinessRules.CUser objUsers = new BusinessRules.CUser(); //call the getSuppliers fn & bind the resulting datareader to the grid gvCourses.DataSource = objUsers.getUsers(); gvCourses.DataBind(); }
protected void getUsers() { BusinessRules.CUser objUser = new BusinessRules.CUser(); gvUsers.DataSource = objUser.getUsers(); gvUsers.DataBind(); if (HttpContext.Current.User.IsInRole("User")) { gvUsers.Columns[3].Visible = false; } }
protected void btnLogin_Click(object sender, EventArgs e) { //hard-code logins into web.config //if (FormsAuthentication.Authenticate(txtUsername.Text, txtPassword.Text)) //{ // FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, true); //} //else //{ // lblError.Visible = true; //} //implement custom role provider string role; BusinessRules.CUser objUser = new BusinessRules.CUser(); role = objUser.login(txtUsername.Text, txtPassword.Text); if (role == "") { lblError.Visible = true; } else { // Create a new ticket used for authentication, credit Heath Stewart FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, // Ticket version txtUsername.Text, // Username associated with ticket DateTime.Now, // Date/time issued DateTime.Now.AddMinutes(30), // Date/time to expire true, // "true" for a persistent user cookie role, // User-data, in this case the roles FormsAuthentication.FormsCookiePath); // Path cookie valid for // Encrypt the cookie using the machine key for secure transport string hash = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash); // Set the cookie's expiration time to the tickets expiration time if (ticket.IsPersistent) { cookie.Expires = ticket.Expiration; } // Add the cookie to the list for outgoing response Response.Cookies.Add(cookie); // Don't call FormsAuthentication.RedirectFromLoginPage since it could replace the authentication ticket (cookie) we just added Response.Redirect("home.aspx", true); } }
protected void getUsers() { //create an instance of Csupplier class BusinessRules.CUser objUsers = new BusinessRules.CUser(); //set the companyID & retrieve the record objUsers.CourseID = Convert.ToInt32(Request.QueryString["CourseID"]); objUsers.getUsers(); txtStudentName.Text = objUsers.StudentName; txtCourseName.Text = objUsers.CourseName; txtCourseTime.Text = objUsers.CourseTime; }
protected void getUsers() { //create an instance of Csupplier class BusinessRules.CUser objUsers = new BusinessRules.CUser(); //set the companyID & retrieve the record objUsers.CourseID = Convert.ToInt32(Request.QueryString["CourseID"]); objUsers.getUsers(); txtStudentName.Text = objUsers.StudentName; txtCourseName.Text = objUsers.CourseName; txtCourseTime.Text = objUsers.CourseTime; }
protected void gvCourses_RowDeleting(object sender, GridViewDeleteEventArgs e) { //instantiate an instance of the User class BusinessRules.CUser objUser = new BusinessRules.CUser(); //Define the id of the record objUser.CourseID = Convert.ToInt32(gvCourses.DataKeys[e.RowIndex].Values["CourseID"]); //Call the delete method objUser.deleteUsers(); //repopulate the grid with our existing function getCourses(); }
protected void gvCourses_RowDeleting(object sender, GridViewDeleteEventArgs e) { //instantiate an instance of the User class BusinessRules.CUser objUser = new BusinessRules.CUser(); //Define the id of the record objUser.CourseID = Convert.ToInt32(gvCourses.DataKeys[e.RowIndex].Values["CourseID"]); //Call the delete method objUser.deleteUsers(); //repopulate the grid with our existing function getCourses(); }
protected void btnSave_Click(object sender, EventArgs e) { //create an instance of Csupplier class BusinessRules.CUser objUsers = new BusinessRules.CUser(); //populate the Course properties with values from the UI objUsers.CourseID = Convert.ToInt32(Request.QueryString["CourseID"]); objUsers.StudentName = txtStudentName.Text; objUsers.CourseName = txtCourseName.Text; objUsers.CourseTime = txtCourseTime.Text; //invoke the save method in the class library objUsers.saveUsers(); //take the user back to the updated list Response.Redirect("home.aspx", true); }
protected void btnSave_Click(object sender, EventArgs e) { //create an instance of Csupplier class BusinessRules.CUser objUsers = new BusinessRules.CUser(); //populate the Course properties with values from the UI objUsers.CourseID = Convert.ToInt32(Request.QueryString["CourseID"]); objUsers.StudentName = txtStudentName.Text; objUsers.CourseName = txtCourseName.Text; objUsers.CourseTime = txtCourseTime.Text; //invoke the save method in the class library objUsers.saveUsers(); //take the user back to the updated list Response.Redirect("home.aspx", true); }