//******************************************************* // // The AddUser_Click server event handler is used to add // a new user to this security role // //******************************************************* protected void AddUser_Click(Object sender, EventArgs e) { int userId; IAccountFacade facade = new AccountFacade(); if (((LinkButton) sender).ID == "addNew") { // add new user to users table PortalUser user = new PortalUser(); user.Name = windowsUserName.Text; user.Email = windowsUserName.Text; user.Password = "******"; if ((userId = facade.AddUser(user)) == -1) { Message.Text = "Add New Failed! There is already an entry for <" + "u" + ">" + windowsUserName.Text + "<" + "/u" + "> in the Users database." + "<" + "br" + ">" + "Please use Add Existing for this user."; } } else { //get user id from dropdownlist of existing users userId = Int32.Parse(allUsers.SelectedItem.Value); } if (userId != -1) { // Add a new userRole to the database facade.AddUserRole(roleId, userId); } // Rebind list BindData(); }
//********************************************************************* // // Application_AuthenticateRequest Event // // If the client is authenticated with the application, then determine // which security roles he/she belongs to and replace the "User" intrinsic // with a custom IPrincipal security object that permits "User.IsInRole" // role checks within the application // // Roles are cached in the browser in an in-memory encrypted cookie. If the // cookie doesn't exist yet for this session, create it. // //********************************************************************* protected void Application_AuthenticateRequest(Object sender, EventArgs e) { if (Request.IsAuthenticated) { String[] roles; // Create the roles cookie if it doesn't exist yet for this session. if ((Request.Cookies["portalroles"] == null) || (Request.Cookies["portalroles"].Value == "")) { // Get roles from UserRoles table, and add to cookie IAccountFacade facade = new AccountFacade(); roles = facade.Roles(User.Identity.Name); // Create a string to persist the roles String roleStr = ""; foreach (String role in roles) { roleStr += role; roleStr += ";"; } // Create a cookie authentication ticket. FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, // version Context.User.Identity.Name, // user name DateTime.Now, // issue time DateTime.Now.AddHours(1), // expires every hour false, // don't persist cookie roleStr // roles ); // Encrypt the ticket String cookieStr = FormsAuthentication.Encrypt(ticket); // Send the cookie to the client Response.Cookies["portalroles"].Value = cookieStr; Response.Cookies["portalroles"].Path = "/"; Response.Cookies["portalroles"].Expires = DateTime.Now.AddMinutes(1); } else { // Get roles from roles cookie FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(Context.Request.Cookies["portalroles"].Value); //convert the string representation of the role data into a string array ArrayList userRoles = new ArrayList(); foreach (String role in ticket.UserData.Split(new char[] {';'})) { userRoles.Add(role); } roles = (String[]) userRoles.ToArray(typeof (String)); } // Add our own custom principal to the request containing the roles in the auth ticket Context.User = new GenericPrincipal(Context.User.Identity, roles); } }
//************************************************************************************* // // The Register.aspx page is used to enable clients to register a new unique username // and password with the portal system. The page contains a single server event // handler -- RegisterBtn_Click -- that executes in response to the page's Register // Button being clicked. // // The Register.aspx page uses the UsersDB class to manage the actual account creation. // Note that the Usernames and passwords are stored within a table in a SQL database. // //************************************************************************************* protected void RegisterBtn_Click(Object sender, EventArgs E) { // Only attempt a login if all form fields on the page are valid if (Page.IsValid == true) { IAccountFacade facade = new AccountFacade(); // Add New User to Portal User Database PortalUser user=new PortalUser(); user.Name = Name.Text; user.Email = Email.Text; user.Password = PortalSecurity.Encrypt(Password.Text); if (facade.AddUser(user) > -1) { // Set the user's authentication name to the userId FormsAuthentication.SetAuthCookie(Email.Text, false); // Redirect browser back to home page Response.Redirect("~/DesktopDefault.aspx"); } else { Message.Text = "Registration Failed! <" + "u" + ">" + Email.Text + "<" + "/u" + "> is already registered." + "<" + "br" + ">" + "Please register using a different email address."; } } }
//******************************************************* // // The DeleteUser_Click server event handler is used to add // a new security role for this portal // //******************************************************* protected void DeleteUser_Click(Object Sender, ImageClickEventArgs e) { IAccountFacade facade = new AccountFacade(); // get user id from dropdownlist of users facade.DeleteUser(Int32.Parse(allUsers.SelectedItem.Value)); // Rebind list BindData(); }
//******************************************************* // // The RolesList_ItemCommand server event handler on this page // is used to handle the user editing and deleting roles // from the RolesList asp:datalist control // //******************************************************* protected void RolesList_ItemCommand(object sender, DataListCommandEventArgs e) { int roleId = (int) rolesList.DataKeys[e.Item.ItemIndex]; IAccountFacade facade = new AccountFacade(); if (e.CommandName == "edit") { // Set editable list item index if "edit" button clicked next to the item rolesList.EditItemIndex = e.Item.ItemIndex; // Repopulate the datalist control BindData(); } else if (e.CommandName == "apply") { // Apply changes String _roleName = ((TextBox) e.Item.FindControl("roleName")).Text; // update database PortalRole role = new PortalRole(); role.RoleID = roleId; role.RoleName = _roleName; facade.UpdateRole(role); // Disable editable list item access rolesList.EditItemIndex = -1; // Repopulate the datalist control BindData(); } else if (e.CommandName == "delete") { // update database facade.DeleteRole(roleId); // Ensure that item is not editable rolesList.EditItemIndex = -1; // Repopulate list BindData(); } else if (e.CommandName == "members") { // Save role name changes first String _roleName = ((TextBox) e.Item.FindControl("roleName")).Text; PortalRole role = new PortalRole(); role.RoleID = roleId; role.RoleName = _roleName; facade.UpdateRole(role); // redirect to edit page Response.Redirect("~/Admin/SecurityRoles.aspx?roleId=" + roleId + "&rolename=" + _roleName + "&tabindex=" + tabIndex + "&tabid=" + tabId); } }
public void AddRoleTest() { //int AddRole(int portalId, String roleName) AccountFacade facade = new AccountFacade(); PortalRole role = new PortalRole(); role.PortalID = 0; role.RoleName = "role" + DateTime.Now.Ticks; facade.AddRole(role); }
public void AddUser() { //int AddUser(string fullName, string email, string password) AccountFacade facade = new AccountFacade(); PortalUser user = new PortalUser(); user.Name="user" + DateTime.Now.Ticks; user.Email = "e"; user.Password = "******"; facade.AddUser(user); }
public void AddUserRoleTest() { //void AddUserRole(int roleId, int userId) AccountFacade facade = new AccountFacade(); int UserID = facade.Users()[0].UserID; PortalRole role = new PortalRole(); role.PortalID = 0; role.RoleName = "role" + DateTime.Now.Ticks; int RoleID = facade.AddRole(role); facade.AddUserRole(RoleID, UserID); }
//******************************************************* // // The AddRole_Click server event handler is used to add // the user to this security role // //******************************************************* protected void AddRole_Click(Object sender, EventArgs e) { int roleId; //get user id from dropdownlist of existing users roleId = Int32.Parse(allRoles.SelectedItem.Value); // Add a new userRole to the database IAccountFacade facade = new AccountFacade(); facade.AddUserRole(roleId, userId); // Rebind list BindData(); }
//******************************************************* // // The AddRole_Click server event handler is used to add // a new security role for this portal // //******************************************************* protected void AddRole_Click(Object Sender, EventArgs e) { // Obtain PortalSettings from Current Context PortalSettings portalSettings = (PortalSettings) Context.Items["PortalSettings"]; // Add a new role to the database IAccountFacade facade = new AccountFacade(); PortalRole role = new PortalRole(); role.PortalID = portalSettings.PortalId; role.RoleName = "�½�ɫ"; facade.AddRole(role); // set the edit item index to the last item rolesList.EditItemIndex = rolesList.Items.Count; // Rebind list BindData(); }
protected void LoginBtn_Click(Object sender, ImageClickEventArgs e) { // Attempt to Validate User Credentials using UsersDB IAccountFacade facade = new AccountFacade(); String userId = facade.Login(email.Text, PortalSecurity.Encrypt(password.Text)); if ((userId != null) && (userId != "")) { // Use security system to set the UserID within a client-side Cookie FormsAuthentication.SetAuthCookie(email.Text, RememberCheckbox.Checked); // Redirect browser back to originating page Response.Redirect("DesktopDefault.aspx"); } else { Message.Text = "<" + "br" + ">Login Failed!" + "<" + "br" + ">"; } }
//******************************************************* // // The BindData helper method is used to bind the list of // security roles for this portal to an asp:datalist server control // //******************************************************* private void BindData() { // Obtain PortalSettings from Current Context PortalSettings portalSettings = (PortalSettings) Context.Items["PortalSettings"]; // Get the portal's roles from the database IAccountFacade facade = new AccountFacade(); rolesList.DataSource = facade.PortalRoles(portalSettings.PortalId); rolesList.DataBind(); }
//******************************************************* // // The Page_Load server event handler on this page is used // to populate the role information for the page // //******************************************************* protected void Page_Load(Object Sender, EventArgs e) { // Verify that the current user has access to access this page if (PortalSecurity.IsInRoles("Admins") == false) { Response.Redirect("~/Errors/EditAccessDenied.aspx"); } // Calculate userid if (Request.Params["userid"] != null) { userId = Int32.Parse(Request.Params["userid"]); } if (Request.Params["username"] != null) { userName = (String) Request.Params["username"]; } if (Request.Params["tabid"] != null) { tabId = Int32.Parse(Request.Params["tabid"]); } if (Request.Params["tabindex"] != null) { tabIndex = Int32.Parse(Request.Params["tabindex"]); } // If this is the first visit to the page, bind the role data to the datalist if (Page.IsPostBack == false) { // new user? if (userName == "") { // make a unique new user record int uid = -1; int i = 0; while (uid == -1) { String friendlyName = "New User created " + DateTime.Now; userName = "******" + i; IAccountFacade facade = new AccountFacade(); PortalUser user = new PortalUser(); user.Name = friendlyName; user.Email = userName; user.Password = ""; uid = facade.AddUser(user); i++; } // redirect to this page with the corrected querystring args Response.Redirect("~/Admin/ManageUsers.aspx?userId=" + uid + "&username="******"&tabindex=" + tabIndex + "&tabid=" + tabId); } BindData(); } }
public void PortalRolesTest() { //IList<PortalRole> GetPortalRoles(int portalId) AccountFacade facade = new AccountFacade(); facade.PortalRoles(0); }
public void RoleMembersTest() { //IList<PortalUser> GetRoleMembers(int roleId) AccountFacade facade = new AccountFacade(); facade.RoleMembers(0); }
public void DeleteUserRoleTest() { //void DeleteUserRole(int roleId, int userId) AccountFacade facade = new AccountFacade(); facade.DeleteUserRole(0, 0); }
public void UpdateRoleTest() { //void UpdateRole(int roleId, String roleName) AccountFacade facade = new AccountFacade(); PortalRole role = new PortalRole(); role.PortalID = 0; role.RoleName = "rl"; facade.UpdateRole(role); }
//******************************************************* // // The BindData helper method is used to populate a asp:datalist // server control with the current "edit access" permissions // set within the portal configuration system // //******************************************************* protected void BindData() { // Obtain PortalSettings from Current Context PortalSettings portalSettings = (PortalSettings) HttpContext.Current.Items["PortalSettings"]; object value = GetModule(); if (value != null) { Nairc.KPWPortal.ModuleSettings m = (Nairc.KPWPortal.ModuleSettings) value; // Update Textbox Settings moduleTitle.Text = m.ModuleTitle; cacheTime.Text = m.CacheTime.ToString(); showMobile.Checked = m.ShowMobile; // Populate checkbox list with all security roles for this portal // and "check" the ones already configured for this module IAccountFacade facade = new AccountFacade(); IList<PortalRole> roles = facade.PortalRoles(portalSettings.PortalId); // Clear existing items in checkboxlist authEditRoles.Items.Clear(); ListItem allItem = new ListItem(); allItem.Text = "�����û�"; if (m.AuthorizedEditRoles.LastIndexOf("All Users") > -1) { allItem.Selected = true; } authEditRoles.Items.Add(allItem); foreach(PortalRole role in roles) { ListItem item = new ListItem(); item.Text = role.RoleName; item.Value = role.RoleID.ToString(); if ((m.AuthorizedEditRoles.LastIndexOf(item.Text)) > -1) { item.Selected = true; } authEditRoles.Items.Add(item); } } }
public void RolesByUserTest() { //IList<PortalRole> RolesByUser(string email) AccountFacade facade = new AccountFacade(); facade.RolesByUser("e"); }
//******************************************************* // // The usersInRole_ItemCommand server event handler on this page // is used to handle the user editing and deleting roles // from the usersInRole asp:datalist control // //******************************************************* protected void usersInRole_ItemCommand(object sender, DataListCommandEventArgs e) { int userId = (int) usersInRole.DataKeys[e.Item.ItemIndex]; if (e.CommandName == "delete") { IAccountFacade facade = new AccountFacade(); // update database facade.DeleteUserRole(roleId, userId); // Ensure that item is not editable usersInRole.EditItemIndex = -1; // Repopulate list BindData(); } }
public void SingleUserTest() { //PortalRole SingleUser(string email) AccountFacade facade = new AccountFacade(); facade.SingleUser("e"); }
public void UsersTest() { //IList<PortalUser> GetUsers() AccountFacade facade = new AccountFacade(); facade.Users(); }
public void RolesTest() { //string[] Roles(string email) AccountFacade facade = new AccountFacade(); facade.Roles("e"); }
public void LoginTest() { //string Login(string email, string password) AccountFacade facade = new AccountFacade(); facade.Login("e", "a"); }
//******************************************************* // // The ApplyChanges_Click server event handler on this page is used // to save the module settings into the portal configuration system // //******************************************************* protected void ApplyChanges_Click(Object Sender, EventArgs e) { // Obtain PortalSettings from Current Context PortalSettings portalSettings = (PortalSettings) HttpContext.Current.Items["PortalSettings"]; object value = GetModule(); if (value != null) { Nairc.KPWPortal.ModuleSettings m = (Nairc.KPWPortal.ModuleSettings) value; // Construct Authorized User Roles String String editRoles = ""; foreach (ListItem item in authEditRoles.Items) { if (item.Selected == true) { editRoles = editRoles + item.Text + ";"; } } // update module Nairc.KPWPortal.Configuration config = new Nairc.KPWPortal.Configuration(); config.UpdateModule(moduleId, m.ModuleOrder, m.PaneName, moduleTitle.Text, Int32.Parse(cacheTime.Text), editRoles, showMobile.Checked); // Update Textbox Settings moduleTitle.Text = m.ModuleTitle; cacheTime.Text = m.CacheTime.ToString(); // Populate checkbox list with all security roles for this portal // and "check" the ones already configured for this module IAccountFacade facade = new AccountFacade(); IList<PortalRole> roles = facade.PortalRoles(portalSettings.PortalId); // Clear existing items in checkboxlist authEditRoles.Items.Clear(); ListItem allItem = new ListItem(); allItem.Text = "�����û�"; if (m.AuthorizedEditRoles.LastIndexOf("All Users") > -1) { allItem.Selected = true; } authEditRoles.Items.Add(allItem); foreach(PortalRole role in roles) { ListItem item = new ListItem(); item.Text = role.RoleName; item.Value = role.RoleID.ToString(); if ((m.AuthorizedEditRoles.LastIndexOf(item.Text)) > -1) { item.Selected = true; } authEditRoles.Items.Add(item); } } // Navigate back to admin page Response.Redirect("TabLayout.aspx?tabid=" + tabId); }
public void UpdateUser() { //void UpdateUser(int userId, string email, string password) AccountFacade facade = new AccountFacade(); PortalUser user= new PortalUser(); user.UserID=0; user.Email = "e"; user.Password = "******"; facade.UpdateUser(user); }
//******************************************************* // // The BindData helper method is used to bind the list of // security roles for this portal to an asp:datalist server control // //******************************************************* private void BindData() { // unhide the Windows Authentication UI, if application if (User.Identity.AuthenticationType != "Forms") { windowsUserName.Visible = true; addNew.Visible = true; } // add the role name to the title if (roleName != "") { title.InnerText = "��ɫ��ϵ: " + roleName; } IAccountFacade facade = new AccountFacade(); // Get the portal's roles from the database // bind users in role to DataList usersInRole.DataSource = facade.RoleMembers(roleId); usersInRole.DataBind(); // bind all portal users to dropdownlist allUsers.DataSource = facade.Users(); allUsers.DataBind(); }
public void DeleteRoleTest() { //void DeleteRole(int roleId) AccountFacade facade = new AccountFacade(); facade.DeleteRole(0); }
/// <summary>The BindData helper method is used to update the tab's /// layout panes with the current configuration information /// </summary> private void BindData() { // Obtain PortalSettings from Current Context PortalSettings portalSettings = (PortalSettings) Context.Items["PortalSettings"]; TabSettings tab = portalSettings.ActiveTab; // Populate Tab Names, etc. tabName.Text = tab.TabName; mobileTabName.Text = tab.MobileTabName; showMobile.Checked = tab.ShowMobile; // Populate checkbox list with all security roles for this portal // and "check" the ones already configured for this tab IAccountFacade facade = new AccountFacade(); System.Collections.Generic.IList<PortalRole> roles = facade.PortalRoles(portalSettings.PortalId); // Clear existing items in checkboxlist authRoles.Items.Clear(); ListItem allItem = new ListItem(); allItem.Text = "�����û�"; if (tab.AuthorizedRoles.LastIndexOf("All Users") > -1) { allItem.Selected = true; } authRoles.Items.Add(allItem); foreach(PortalRole role in roles) { ListItem item = new ListItem(); item.Text = role.RoleName; item.Value = role.RoleID.ToString(); if ((tab.AuthorizedRoles.LastIndexOf(item.Text)) > -1) { item.Selected = true; } authRoles.Items.Add(item); } // Populate the "Add Module" Data Configuration config = new Configuration(); moduleType.DataSource = config.GetModuleDefinitions(portalSettings.PortalId); moduleType.DataBind(); // Populate Right Hand Module Data rightList = GetModules("RightPane"); rightPane.DataBind(); // Populate Content Pane Module Data contentList = GetModules("ContentPane"); contentPane.DataBind(); // Populate Left Hand Pane Module Data leftList = GetModules("LeftPane"); leftPane.DataBind(); }
public void DeleteUser() { //void DeleteUser(int userId) AccountFacade facade = new AccountFacade(); facade.DeleteUser(0); }