コード例 #1
0
ファイル: XslHelper.cs プロジェクト: divyang4481/appleseedapp
        /// <summary>
        ///   Initializes a new instance of the <see cref = "XslHelper" /> class.
        /// </summary>
        public XslHelper()
        {
            if (HttpContext.Current != null)
            {
                this.PortalSettings = (PortalSettings)HttpContext.Current.Items["PortalSettings"];

                var users = new UsersDB();
                this.user = users.GetSingleUser(HttpContext.Current.User.Identity.Name, this.PortalSettings.PortalAlias);
            }
        }
コード例 #2
0
        /// <summary>
        /// The AddUser_Click server event handler is used to add
        /// a new user to this security role.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        protected void AddUser_Click(Object sender, EventArgs e)
        {
            //get user id from dropdownlist of existing users
            Guid userID = new Guid(allUsers.SelectedItem.Value);

            if (!userID.Equals(Guid.Empty))
            {
                // Add a new userRole to the database
                UsersDB users = new UsersDB();
                users.AddUserRole(roleId, userID, this.PortalSettings.PortalAlias);
            }

            // Rebind list
            BindData();
        }
コード例 #3
0
        /// <summary>
        /// The BindData helper method is used to update the tab's
        /// layout panes with the current configuration information
        /// </summary>
        private void BindData()
        {
            PageSettings tab = this.PortalSettings.ActivePage;

            // Populate Page Names, etc.
            tabName.Text = "New Page";
            mobilePageName.Text = "";
            showMobile.Checked = false;

            // Populate the "ParentPage" Data
            PagesDB t = new PagesDB();
            IList<PageItem> items = t.GetPagesParent( this.PortalSettings.PortalID, PageID );
            parentPage.DataSource = items;
            parentPage.DataBind();

            // Translate
            if ( parentPage.Items.FindByText( " ROOT_LEVEL" ) != null )
                parentPage.Items.FindByText( " ROOT_LEVEL" ).Text =
                    General.GetString( "ROOT_LEVEL", "Root Level", parentPage );

            // Populate checkbox list with all security roles for this portal
            // and "check" the ones already configured for this tab
            UsersDB users = new UsersDB();
            IList<AppleseedRole> roles = users.GetPortalRoles( this.PortalSettings.PortalAlias );

            // Clear existing items in checkboxlist
            authRoles.Items.Clear();

            foreach ( AppleseedRole role in roles ) {
                ListItem item = new ListItem();
                item.Text = role.Name;
                item.Value = role.Id.ToString();

                if ( ( tab.AuthorizedRoles.LastIndexOf( item.Text ) ) > -1 )
                    item.Selected = true;

                authRoles.Items.Add( item );
            }
        }
コード例 #4
0
        /// <summary>
        /// deletex
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.Web.UI.WebControls.GridViewDeleteEventArgs"/> instance containing the event data.</param>
        protected void allUsers_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            GridView usersGrid = (GridView) sender;
            GridViewRow row = usersGrid.Rows[e.RowIndex];
            Guid _userID = new Guid(((Appleseed.Framework.Web.UI.WebControls.LinkButton) row.FindControl("DeleteBtn")).CommandArgument);

            // TODO: Fix this
            UsersDB users = new UsersDB();
            users.DeleteUser(_userID);

            OnDelete();
        }
コード例 #5
0
ファイル: MDFHelper.cs プロジェクト: divyang4481/appleseedapp
        /// <summary>
        /// Fills all MDF settings. Returns true if no problems reading and
        /// parsing all MDF settings.
        /// </summary>
        /// <param name="pmc">The PMC.</param>
        /// <param name="itemTableName">Name of the item table.</param>
        /// <param name="titleFieldName">Name of the title field.</param>
        /// <param name="selectFieldList">The select field list.</param>
        /// <param name="searchFieldList">The search field list.</param>
        /// <returns></returns>
        public bool Populate(PortalModuleControl pmc, string itemTableName, string titleFieldName, string selectFieldList, string searchFieldList)
        {
            bool PopulateDone;
            try
            {
                _applyMDF = bool.Parse(pmc.Settings[NameApplyMDF].ToString());

                string ds = pmc.Settings[NameDataSource].ToString();
                if (ds == DataSourceType.This.ToString())
                    _dataSource = DataSourceType.This;
                else if (ds == DataSourceType.All.ToString())
                    _dataSource = DataSourceType.All;
                else if (ds == DataSourceType.List.ToString())
                    _dataSource = DataSourceType.List;

                _maxHits = int.Parse(pmc.Settings[NameMaxHits].ToString());
                _moduleList = pmc.Settings[NameModuleList].ToString();
                _allNotInList = bool.Parse(pmc.Settings[NameAllNotInList].ToString());
                _sortField = pmc.Settings[NameSortField].ToString();
                _sortDirection = pmc.Settings[NameSortDirection].ToString();
                _searchString = pmc.Settings[NameSearchString].ToString();
                _searchField = pmc.Settings[NameSearchField].ToString();
                _mobileOnly = bool.Parse(pmc.Settings[NameMobileOnly].ToString());

                if (_dataSource == DataSourceType.This)
                    _moduleList = pmc.ModuleID.ToString();

                if (_moduleList == "" && _dataSource == DataSourceType.List)
                {
                    // Create data to lazy user that forgot to enter data in field Module List
                    _moduleList = pmc.ModuleID.ToString();
                }

                if (pmc.SupportsWorkflow)
                {
                    _supportsWorkflow = pmc.SupportsWorkflow;
                    _workflowVersion = pmc.Version;
                }

                _itemTableName = itemTableName;
                _titleFieldName = titleFieldName;
                _selectFieldList = selectFieldList;
                _searchFieldList = searchFieldList;

                _portalID = pmc.PortalID;
                UsersDB u = new UsersDB();
                SqlDataReader dr = u.GetSingleUser(PortalSettings.CurrentUser.Identity.Email);
                if (dr.Read())
                    _userID = Int32.Parse(dr["UserID"].ToString());

                PopulateDone = true;
            }
            catch (Exception)
            {
                PopulateDone = false;
            }
            return PopulateDone;
        }
コード例 #6
0
        public static string SignOn(string user, string password, bool persistent, string redirectPage)
        {
            // Obtain PortalSettings from Current Context
            PortalSettings portalSettings = (PortalSettings)HttpContext.Current.Items[strPortalSettings];

            MembershipUser usr;
            UsersDB accountSystem = new UsersDB();

            // Attempt to Validate User Credentials using UsersDB
            usr = accountSystem.Login(user, password, portalSettings.PortalAlias);

            // Thierry (tiptopweb), 12 Apr 2003: Save old ShoppingCartID
            //			ShoppingCartDB shoppingCart = new ShoppingCartDB();
            //			string tempCartID = ShoppingCartDB.GetCurrentShoppingCartID();

            if (usr != null)
            {
                // Ender, 31 July 2003: Support for the monitoring module by Paul Yarrow
                if (Config.EnableMonitoring)
                {
                    try
                    {
                        Monitoring.LogEntry((Guid)usr.ProviderUserKey, portalSettings.PortalID, -1, "Logon", string.Empty);
                    }
                    catch
                    {
                        ErrorHandler.Publish(LogLevel.Info, "Cannot monitoring login user " + usr.UserName);
                    }
                }

                // Use security system to set the UserID within a client-side Cookie
                FormsAuthentication.SetAuthCookie(usr.ToString(), persistent);

                // Appleseed Security cookie Required if we are sharing a single domain
                // with portal Alias in the URL

                // Set a cookie to persist authentication for each portal
                // so user can be reauthenticated
                // automatically if they chose to Remember Login
                HttpCookie hck = HttpContext.Current.Response.Cookies["Appleseed_" + portalSettings.PortalAlias.ToLower()];
                hck.Value = usr.ToString(); //Fill all data: name + email + id
                hck.Path = "/";

                if (persistent) // Keep the cookie?
                {
                    hck.Expires = DateTime.Now.AddYears(50);
                }
                else
                {
                    //jminond - option to kill cookie after certain time always
                    // jes1111
                    //					if(ConfigurationSettings.AppSettings["CookieExpire"] != null)
                    //					{
                    //						int minuteAdd = int.Parse(ConfigurationSettings.AppSettings["CookieExpire"]);
                    int minuteAdd = Config.CookieExpire;

                    DateTime time = DateTime.Now;
                    TimeSpan span = new TimeSpan(0, 0, minuteAdd, 0, 0);

                    hck.Expires = time.Add(span);
                    //					}
                }

                if (redirectPage == null || redirectPage.Length == 0)
                {
                    // Redirect browser back to originating page
                    if (HttpContext.Current.Request.UrlReferrer != null)
                    {
                        HttpContext.Current.Response.Redirect(HttpContext.Current.Request.UrlReferrer.ToString());
                    }
                    else
                    {
                        HttpContext.Current.Response.Redirect(Path.ApplicationRoot);
                    }
                    return usr.Email;
                }
                else
                {
                    HttpContext.Current.Response.Redirect(redirectPage);
                }
            }
            return null;
        }
コード例 #7
0
        /// <summary>
        /// The BindData helper method is used to update the tab's
        ///   layout panes with the current configuration information
        /// </summary>
        /// <remarks>
        /// </remarks>
        private void BindData()
        {
            var page = this.PortalSettings.ActivePage;

            // Populate Page Names, etc.
            this.tabName.Text = page.PageName;
            this.mobilePageName.Text = page.MobilePageName;
            this.showMobile.Checked = page.ShowMobile;

            // Populate the "ParentPage" Data
            var t = new PagesDB();
            var items = t.GetPagesParent(this.PortalSettings.PortalID, this.PageID);
            this.parentPage.DataSource = items;
            this.parentPage.DataBind();

            if (this.parentPage.Items.FindByValue(page.ParentPageID.ToString()) != null)
            {
                // parentPage.Items.FindByValue( tab.ParentPageID.ToString() ).Selected = true;
                this.parentPage.SelectedValue = page.ParentPageID.ToString();
            }

            // Translate
            if (this.parentPage.Items.FindByText(" ROOT_LEVEL") != null)
            {
                this.parentPage.Items.FindByText(" ROOT_LEVEL").Text = General.GetString(
                    "ROOT_LEVEL", "Root Level", this.parentPage);
            }

            // Populate checkbox list with all security roles for this portal
            // and "check" the ones already configured for this tab
            var users = new UsersDB();
            var roles = users.GetPortalRoles(this.PortalSettings.PortalAlias);

            // Clear existing items in checkboxlist
            this.authRoles.Items.Clear();

            foreach (var role in roles)
            {
                var item = new ListItem();
                item.Text = role.Name;
                item.Value = role.Id.ToString();

                if (page.AuthorizedRoles.LastIndexOf(item.Text) > -1)
                {
                    item.Selected = true;
                }

                this.authRoles.Items.Add(item);
            }

            // Populate the "Add Module" Data
            var m = new ModulesDB();
            var modules = new SortedList<string, string>();
            var drCurrentModuleDefinitions = m.GetCurrentModuleDefinitions(this.PortalSettings.PortalID);
            //if (PortalSecurity.IsInRoles("Admins") || !bool.Parse(drCurrentModuleDefinitions["Admin"].ToString()))
            //{
            var htmlId = "0";
            try {
                while (drCurrentModuleDefinitions.Read()) {
                    if ((!modules.ContainsKey(drCurrentModuleDefinitions["FriendlyName"].ToString())) &&
                        (PortalSecurity.IsInRoles("Admins") || !bool.Parse(drCurrentModuleDefinitions["Admin"].ToString()))) {
                        modules.Add(
                            // moduleType.Items.Add(
                            // new ListItem(drCurrentModuleDefinitions["FriendlyName"].ToString(),
                            // drCurrentModuleDefinitions["ModuleDefID"].ToString()));
                            drCurrentModuleDefinitions["FriendlyName"].ToString(),
                            drCurrentModuleDefinitions["ModuleDefID"].ToString());
                        if (drCurrentModuleDefinitions["FriendlyName"].ToString().Equals("HTML Content"))
                            htmlId = drCurrentModuleDefinitions["ModuleDefID"].ToString();
                    }
                }
            }
            finally {
                drCurrentModuleDefinitions.Close();
            }
            //}

            // Dictionary<string, string> actions = ModelServices.GetMVCActionModules();
            // foreach (string key in actions.Keys) {
            // modules.Add(key, actions[key]);
            // }
            this.moduleType.DataSource = modules;
            this.moduleType.DataBind();
            this.moduleType.SelectedValue = htmlId;

            // Now it's the load is by ajax 1/september/2011
            // Populate Top Pane Module Data
            //this.topList = this.GetModules("TopPane");
            //this.topPane.DataBind();

            //// Populate Left Hand Pane Module Data
            //this.leftList = this.GetModules("LeftPane");
            //this.leftPane.DataBind();

            //// Populate Content Pane Module Data
            //this.contentList = this.GetModules("ContentPane");
            //this.contentPane.DataBind();

            //// Populate Right Hand Module Data
            //this.rightList = this.GetModules("RightPane");
            //this.rightPane.DataBind();

            //// Populate Bottom Module Data
            //this.bottomList = this.GetModules("BottomPane");
            //this.bottomPane.DataBind();
        }
コード例 #8
0
        /// <summary>
        /// The BindData helper method is used to bind the list of
        /// security roles for this portal to an asp:datalist server control
        /// </summary>
        private void BindData()
        {
            // add the role name to the title
            if (roleId != Guid.Empty)
            {

                AppleseedRoleProvider roleProvider = (AppleseedRoleProvider)System.Web.Security.Roles.Provider;
                AppleseedRole role = roleProvider.GetRoleById(roleId);

                title.InnerText = General.GetString("ROLE_MEMBERSHIP") + role.Name;
            }

            // Get the portal's roles from the database
            UsersDB users = new UsersDB();

            // bind users in role to DataList
            usersInRole.DataSource = users.GetRoleMembers(roleId, this.PortalSettings.PortalAlias);
            usersInRole.DataBind();

            // bind all portal users to dropdownlist
            allUsers.DataSource = users.GetUsers(this.PortalSettings.PortalAlias);
            allUsers.DataBind();
        }
コード例 #9
0
        /// <summary>
        /// The BindData helper method is used to bind the list of
        /// security roles for this portal to an asp:datalist server control
        /// </summary>
        private void BindData()
        {
            // Get the portal's roles from the database
            UsersDB users = new UsersDB();

            IList<AppleseedRole> roles = users.GetPortalRoles(this.PortalSettings.PortalAlias);

            // remove "All Users", "Authenticated Users" and "Unauthenticated Users" pseudo-roles
            AppleseedRole pseudoRole = new AppleseedRole(AppleseedRoleProvider.AllUsersGuid, AppleseedRoleProvider.AllUsersRoleName);
            if (roles.Contains(pseudoRole))
            {
                roles.Remove(pseudoRole);
            }
            pseudoRole = new AppleseedRole(AppleseedRoleProvider.AuthenticatedUsersGuid, AppleseedRoleProvider.AuthenticatedUsersRoleName);
            if (roles.Contains(pseudoRole))
            {
                roles.Remove(pseudoRole);
            }
            pseudoRole = new AppleseedRole(AppleseedRoleProvider.UnauthenticatedUsersGuid, AppleseedRoleProvider.UnauthenticatedUsersRoleName);
            if (roles.Contains(pseudoRole))
            {
                roles.Remove(pseudoRole);
            }

            rolesList.DataSource = roles;
            rolesList.DataBind();
        }
コード例 #10
0
        /// <summary>
        /// Creates the portal.
        /// </summary>
        /// <param name="templateID">The template ID.</param>
        /// <param name="templateAlias">The template alias.</param>
        /// <param name="portalAlias">The portal alias.</param>
        /// <param name="portalName">Name of the portal.</param>
        /// <param name="portalPath">The portal path.</param>
        /// <returns></returns>
        private int CreatePortal(int templateID, string templateAlias, string portalAlias, string portalName,
            string portalPath)
        {
            int newPortalID;

            PortalsDB portals = new PortalsDB();
            PagesDB tabs = new PagesDB();
            ModulesDB modules = new ModulesDB();
            UsersDB users = new UsersDB();

            // create an Array to stores modules ID and GUID for finding them later
            ArrayList templateModules = new ArrayList();
            moduleTemplate module;
            // create an Array to stores tabs ID for finding them later
            ArrayList templateTabs = new ArrayList();
            tabTemplate tab;

            // Create a new portal
            newPortalID = portals.AddPortal(portalAlias, portalName, portalPath);

            // Open the connection to the PortalTemplates Database
            SqlConnection myConnection = GetConnection();
            SqlConnection my2ndConnection = GetConnection();
            SqlConnection my3rdConnection = GetConnection();
            myConnection.Open();
            my2ndConnection.Open();
            my3rdConnection.Open();

            // get module definitions and save them in the new portal
            SqlDataReader myReader = GetTemplateModuleDefinitions(templateID, myConnection);

            // Always call Read before accessing data.
            while (myReader.Read()) {
                module.id = (int)myReader["ModuleDefID"];
                module.GuidID = GetGeneralModuleDefinitionByName(myReader["FriendlyName"].ToString(), my2ndConnection);
                try {
                    // save module definitions in the new portal
                    modules.UpdateModuleDefinitions(module.GuidID, newPortalID, true);
                    // Save the modules into a list for finding them later
                    templateModules.Add(module);
                } catch {
                    // tried to add a Module thas doesn´t exists in this implementation of the portal
                }
            }

            myReader.Close();

            // TODO: Is this still valid? Admin user will be created the first time the portal is accessed
            //if (!Config.UseSingleUserBase)
            //{
            //    // TODO: multiple portals still not supported
            //    Guid userID;

            //    // Create the "admin" User for the new portal
            //    string AdminEmail = "*****@*****.**";
            //    userID = users.AddUser("admin", AdminEmail, "admin", newPortalID);

            //    // Create a new row in a many to many table (userroles)
            //    // giving the "admins" role to the "admin" user
            //    users.AddUserRole("admin", userID);
            //}

            // Get all the Tabs in the Template Portal, store IDs in a list for finding them later
            // and create the Tabs in the new Portal
            myReader = GetTabsByPortal(templateID, myConnection);

            // Always call Read before accessing data.
            while (myReader.Read()) {
                // Save the tabs into a list for finding them later
                tab.oldID = (int)myReader["PageID"];
                tab.newID =
                    tabs.AddPage(newPortalID, myReader["PageName"].ToString(),
                                 Int32.Parse(myReader["PageOrder"].ToString()));
                templateTabs.Add(tab);
            }
            myReader.Close();

            //Clear SiteMaps Cache
            AppleseedSiteMapProvider.ClearAllAppleseedSiteMapCaches();

            // now I have to get them again to set up the ParentID for each Tab
            myReader = GetTabsByPortal(templateID, myConnection);

            // Always call Read before accessing data.
            while (myReader.Read()) {
                // Find the news TabID and ParentTabID
                IEnumerator myEnumerator = templateTabs.GetEnumerator();
                int newTabID = -1;
                int newParentTabID = -1;

                while (myEnumerator.MoveNext() && (newTabID == -1 || newParentTabID == -1)) {
                    tab = (tabTemplate)myEnumerator.Current;
                    if (tab.oldID == (int)myReader["PageID"])
                        newTabID = tab.newID;
                    if (tab.oldID == Int32.Parse("0" + myReader["ParentPageID"]))
                        newParentTabID = tab.newID;
                }

                if (newParentTabID == -1)
                    newParentTabID = 0;

                // Update the Tab in the new portal
                tabs.UpdatePage(newPortalID, newTabID, newParentTabID, myReader["PageName"].ToString(),
                                Int32.Parse(myReader["PageOrder"].ToString()), myReader["AuthorizedRoles"].ToString(),
                                myReader["MobilePageName"].ToString(), (bool)myReader["ShowMobile"]);

                // Finally use GetPortalSettings to access each Tab and its Modules in the Template Portal
                // and create them in the new Portal
                SqlDataReader result;

                try {
                    result = GetPageModules(Int32.Parse(myReader["PageID"].ToString()), my2ndConnection);

                    object myValue;

                    while (result.Read()) {
                        ModuleSettings m = new ModuleSettings();
                        m.ModuleID = (int)result["ModuleID"];
                        m.ModuleDefID = (int)result["ModuleDefID"];
                        m.PageID = newTabID;
                        m.PaneName = (string)result["PaneName"];
                        m.ModuleTitle = (string)result["ModuleTitle"];

                        myValue = result["AuthorizedEditRoles"];
                        m.AuthorizedEditRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty;

                        myValue = result["AuthorizedViewRoles"];
                        m.AuthorizedViewRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty;

                        myValue = result["AuthorizedAddRoles"];
                        m.AuthorizedAddRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty;

                        myValue = result["AuthorizedDeleteRoles"];
                        m.AuthorizedDeleteRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty;

                        myValue = result["AuthorizedPropertiesRoles"];
                        m.AuthorizedPropertiesRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty;

                        myValue = result["AuthorizedMoveModuleRoles"];
                        m.AuthorizedMoveModuleRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty;

                        myValue = result["AuthorizedDeleteModuleRoles"];
                        m.AuthorizedDeleteModuleRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty;

                        myValue = result["AuthorizedPublishingRoles"];
                        m.AuthorizedPublishingRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty;

                        myValue = result["SupportWorkflow"];
                        m.SupportWorkflow = !Convert.IsDBNull(myValue) ? (bool)myValue : false;

                        myValue = result["AuthorizedApproveRoles"];
                        m.AuthorizedApproveRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty;

                        myValue = result["WorkflowState"];
                        m.WorkflowStatus = !Convert.IsDBNull(myValue)
                                               ? (WorkflowState)(0 + (byte)myValue)
                                               : WorkflowState.Original;

                        try {
                            myValue = result["SupportCollapsable"];
                        } catch {
                            myValue = DBNull.Value;
                        }
                        m.SupportCollapsable = DBNull.Value != myValue ? (bool)myValue : false;

                        try {
                            myValue = result["ShowEveryWhere"];
                        } catch {
                            myValue = DBNull.Value;
                        }
                        m.ShowEveryWhere = DBNull.Value != myValue ? (bool)myValue : false;

                        m.CacheTime = int.Parse(result["CacheTime"].ToString());
                        m.ModuleOrder = int.Parse(result["ModuleOrder"].ToString());

                        myValue = result["ShowMobile"];
                        m.ShowMobile = !Convert.IsDBNull(myValue) ? (bool)myValue : false;

                        // Find the new ModuleDefID assigned to the module in the new portal
                        myEnumerator = templateModules.GetEnumerator();
                        int newModuleDefID = 0;

                        while (myEnumerator.MoveNext() && newModuleDefID == 0) {
                            module = (moduleTemplate)myEnumerator.Current;
                            if (module.id == m.ModuleDefID)
                                newModuleDefID = modules.GetModuleDefinitionByGuid(newPortalID, module.GuidID);
                        }

                        if (newModuleDefID > 0) {
                            // add the module to the new tab
                            int newModuleID = modules.AddModule(newTabID, m.ModuleOrder, m.PaneName, m.ModuleTitle,
                                                                newModuleDefID, m.CacheTime, m.AuthorizedEditRoles,
                                                                m.AuthorizedViewRoles,
                                                                m.AuthorizedAddRoles, m.AuthorizedDeleteRoles,
                                                                m.AuthorizedPropertiesRoles,
                                                                m.AuthorizedMoveModuleRoles,
                                                                m.AuthorizedDeleteModuleRoles,
                                                                m.ShowMobile, m.AuthorizedPublishingRoles,
                                                                m.SupportWorkflow,
                                                                m.ShowEveryWhere, m.SupportCollapsable);
                            // At the end, get all ModuleSettings and save them in the new module
                            SqlDataReader dr = GetModuleSettings(m.ModuleID, my3rdConnection);

                            while (dr.Read()) {
                                Framework.Site.Configuration.ModuleSettings.UpdateModuleSetting(newModuleID, dr["SettingName"].ToString(),
                                                                   dr["SettingValue"].ToString());
                            }
                            dr.Close();
                        }
                    }

                    result.Close();
                } catch {
                    // Error? ignore Tab ...
                }
            }
            myReader.Close();

            // Set the CustomSettings of the New Portal based in the Template Portal
            myReader = GetPortalCustomSettings(templateID, myConnection);

            // Always call Read before accessing data.
            while (myReader.Read()) {
                PortalSettings.UpdatePortalSetting(newPortalID, myReader["SettingName"].ToString(),
                                                   myReader["SettingValue"].ToString());
            }

            myReader.Close();

            // close the conections
            myConnection.Close();
            myConnection.Dispose();
            my2ndConnection.Close();
            my2ndConnection.Dispose();
            my3rdConnection.Close();
            my3rdConnection.Dispose();

            // Create paths
            portals.CreatePortalPath(portalPath);

            return newPortalID;
        }
コード例 #11
0
        private int CreatePortal(out bool createdOk)
        {
            string fileName = ddlXMLTemplates.Text;
            string portalAlias = AliasField.Text;
            string portalName = TitleField.Text;
            string portalPath = "/" + PathField.Text;
            IPortalTemplateRepository repository = new PortalTemplateRepository();
            IPortalTemplateServices services = PortalTemplateFactory.GetPortalTemplateServices(repository);
            int newPortalID = 1;

            createdOk = services.DeserializePortal(fileName, portalName, portalAlias, portalPath, PortalSettings.PortalFullPath, out newPortalID);
            if (createdOk && !Config.UseSingleUserBase) {
                string AdminEmail = "*****@*****.**";

                // Create the stradmin User for the new portal
                UsersDB User = new UsersDB();
                // Create the "Admins" role for the new portal
                Guid roleID = User.AddRole(portalAlias, "Admins");
                Guid userID = User.AddUser("admin", AdminEmail, "admin", portalAlias);
                // Create a new row in a many to many table (userroles)
                // giving the "admins" role to the stradmin user
                User.AddUserRole(roleID, userID, portalAlias);
                PortalsDB portals = new PortalsDB();

                portals.CreatePortalPath(portalPath);
            }
            return newPortalID;
        }
コード例 #12
0
        /// <summary>
        /// Populates the roles.
        /// </summary>
        /// <param name="listRoles">The list roles.</param>
        /// <param name="moduleRoles">The module roles.</param>
        private void PopulateRoles(ref CheckBoxList listRoles, string moduleRoles)
        {
            // Get roles from db
            var users = new UsersDB();
            var roles = users.GetPortalRoles(this.PortalSettings.PortalAlias);

            // Clear existing items in checkbox list
            listRoles.Items.Clear();

            // All Users
            var allItem = new ListItem("All Users");
            listRoles.Items.Add(allItem);

            // Authenticated user role added 15 nov 2002 - by manudea
            var authItem = new ListItem("Authenticated Users");
            listRoles.Items.Add(authItem);

            // Unauthenticated user role added 30/01/2003 - by manudea
            var unauthItem = new ListItem("Unauthenticated Users");
            listRoles.Items.Add(unauthItem);

            listRoles.DataSource = roles;
            listRoles.DataTextField = "Name";
            listRoles.DataValueField = "Id";
            listRoles.DataBind();

            // Splits up the role string and use array 30/01/2003 - by manudea
            while (moduleRoles.EndsWith(";"))
            {
                moduleRoles = moduleRoles.Substring(0, moduleRoles.Length - 1);
            }

            var arrModuleRoles = moduleRoles.Split(';');
            var roleCount = arrModuleRoles.GetUpperBound(0);

            // Cycle every role and select it if needed
            foreach (ListItem ls in listRoles.Items)
            {
                for (var i = 0; i <= roleCount; i++)
                {
                    if (arrModuleRoles[i].ToLower() == ls.Text.ToLower())
                    {
                        ls.Selected = true;
                    }
                }
            }
        }
コード例 #13
0
ファイル: PortalsDB.cs プロジェクト: divyang4481/appleseedapp
        public int CreatePortal(int solutionId, string portalAlias, string portalName, string portalPath)
        {
            var tabs = new PagesDB();
            var modules = new ModulesDB();

            // Create a new portal
            var portalId = this.AddPortal(portalAlias, portalName, portalPath);

            // get module definitions
            foreach (var solutionModuleDefinition in modules.GetSolutionModuleDefinitions(solutionId))
            {
                modules.UpdateModuleDefinitions(solutionModuleDefinition.GeneralModuleDefinitionId, portalId, true);
            }

            if (!Config.UseSingleUserBase)
            {
                const string AdminEmail = "*****@*****.**";

                // Create the stradmin User for the new portal
                var user = new UsersDB();

                // Create the "Admins" role for the new portal
                var roleId = user.AddRole(portalAlias, "Admins");
                var userId = user.AddUser(StringsAdmin, AdminEmail, StringsAdmin, portalAlias);

                // Create the "Admins" profile for the new portal
                var profile = ProfileBase.Create(AdminEmail);
                profile.SetPropertyValue("Email", AdminEmail);
                profile.SetPropertyValue("Name", "admin");
                try {
                    profile.Save();

                } catch (Exception exc) {

                }

                // Create a new row in a many to many table (userroles)
                // giving the "admins" role to the stradmin user
                user.AddUserRole(roleId, userId, portalAlias);
            }

            // Create a new Page "home"
            var homePageId = tabs.AddPage(portalId, "Home", 1);

            // Create a new Page "admin"
            var localizedString = General.GetString("ADMIN_TAB_NAME");
            var adminPageId = tabs.AddPage(portalId, localizedString, StrAdmins, 9999);

            // Add Modules for portal use
            // Html Document
            modules.UpdateModuleDefinitions(new Guid(StrGuidhtmlDocument), portalId, true);

            // Add Modules for portal administration
            // Site Settings (Admin)
            localizedString = General.GetString("MODULE_SITE_SETTINGS");
            modules.UpdateModuleDefinitions(new Guid(StrGuidSiteSettings), portalId, true);
            modules.AddModule(
                adminPageId,
                1,
                StrContentPane,
                localizedString,
                modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidSiteSettings)),
                0,
                StrAdmins,
                StrAllUsers,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                false,
                string.Empty,
                false,
                false,
                false);

            // Pages (Admin)
            localizedString = General.GetString("MODULE_TABS");
            modules.UpdateModuleDefinitions(new Guid(StrGuidPages), portalId, true);
            modules.AddModule(
                adminPageId,
                2,
                StrContentPane,
                localizedString,
                modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidPages)),
                0,
                StrAdmins,
                StrAllUsers,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                false,
                string.Empty,
                false,
                false,
                false);

            // Roles (Admin)
            localizedString = General.GetString("MODULE_SECURITY_ROLES");
            modules.UpdateModuleDefinitions(new Guid(StrGuidSecurityRoles), portalId, true);
            modules.AddModule(
                adminPageId,
                3,
                StrContentPane,
                localizedString,
                modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidSecurityRoles)),
                0,
                StrAdmins,
                StrAllUsers,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                false,
                string.Empty,
                false,
                false,
                false);

            // Manage Users (Admin)
            localizedString = General.GetString("MODULE_MANAGE_USERS");
            modules.UpdateModuleDefinitions(new Guid(StrGuidManageUsers), portalId, true);
            modules.AddModule(
                adminPageId,
                4,
                StrContentPane,
                localizedString,
                modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidManageUsers)),
                0,
                StrAdmins,
                StrAllUsers,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                false,
                string.Empty,
                false,
                false,
                false);

            // Module Definitions (Admin)
            localizedString = General.GetString("MODULE_MODULES");
            modules.UpdateModuleDefinitions(new Guid(StrGuidModules), portalId, true);
            modules.AddModule(
                adminPageId,
                1,
                StringsRightPane,
                localizedString,
                modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidModules)),
                0,
                StrAdmins,
                StrAllUsers,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                false,
                string.Empty,
                false,
                false,
                false);

            // End Change [email protected]
            // Change by [email protected]
            // Add Signin Module and put it on the hometab
            // Signin
            localizedString = General.GetString("MODULE_LOGIN", "Login");
            modules.UpdateModuleDefinitions(new Guid(StrGuidLogin), portalId, true);
            modules.AddModule(
                homePageId,
                -1,
                StrLeftPane,
                localizedString,
                modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidLogin)),
                0,
                StrAdmins,
                "Unauthenticated Users;Admins;",
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                false,
                string.Empty,
                false,
                false,
                false);

            // Add language switcher to available modules
            // Language Switcher
            modules.UpdateModuleDefinitions(new Guid(StrGuidLanguageSwitcher), portalId, true);

            // End of change by [email protected]
            // Create paths
            this.CreatePortalPath(portalPath);
            return portalId;
        }
コード例 #14
0
        /// <summary>
        /// Handles the Click event of the SendPasswordBtn control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void SendPasswordBtn_Click( object sender, EventArgs e )
        {
            if ( email.Text == string.Empty ) {
                Message.Text = "Please enter you email address";
                Message.TextKey = "SIGNIN_ENTER_EMAIL_ADDR";
                return;
            }
            // generate random password
            string randomPassword = RandomPassword.Generate( 8, 10 );

            CryptoHelper crypthelp = new CryptoHelper();
            UsersDB usersDB = new UsersDB();

            //Obtain single row of User information
            AppleseedUser user = usersDB.GetSingleUser( email.Text, this.PortalSettings.PortalAlias );

            if ( user != null ) {

                string Pswrd;
                string AppName = this.PortalSettings.PortalName;
                bool encrypted = Config.EncryptPassword;
                string Name = user.Email;
                if ( encrypted ) {
                    Pswrd = randomPassword;
                    crypthelp.ResetPassword( Name, randomPassword );
                }
                else {
                    Pswrd = user.GetPassword();
                }
                crypthelp.ResetPassword( Name, randomPassword );
                string LoginUrl = Path.ApplicationFullPath + "DesktopModules/Admin/Logon.aspx?Usr="******"&Pwd=" +
                                  Pswrd + "&Alias=" + this.PortalSettings.PortalAlias;
                MailMessage mail = new MailMessage();

                // [email protected]
                // Date 19 March 2003
                // We have to use a correct sender address,
                // because most SMTP servers reject it otherwise
                //jes1111 - mail.From = ConfigurationSettings.AppSettings["EmailFrom"].ToString();
                mail.From = Config.EmailFrom;
                mail.To = email.Text;
                mail.Subject = AppName + " - " + General.GetString( "SIGNIN_SEND_PWD", "Send me password", this );

                StringBuilder sb = new StringBuilder();

                sb.Append( Name );
                sb.Append( "," );
                sb.Append( "\r\n\r\n" );
                sb.Append( General.GetString( "SIGNIN_PWD_REQUESTED", "This is the password you requested", this ) );
                sb.Append( " " );
                sb.Append( Pswrd );
                sb.Append( "\r\n\r\n" );
                sb.Append( General.GetString( "SIGNIN_THANK_YOU", "Thanks for your visit.", this ) );
                sb.Append( " " );
                sb.Append( AppName );
                sb.Append( "\r\n\r\n" );
                sb.Append( General.GetString( "SIGNIN_YOU_CAN_LOGIN_FROM", "You can login from", this ) );
                sb.Append( ":" );
                sb.Append( "\r\n" );
                sb.Append( Path.ApplicationFullPath );
                sb.Append( "\r\n\r\n" );
                sb.Append( General.GetString( "SIGNIN_USE_DIRECT_URL", "Or using direct url", this ) );
                sb.Append( "\r\n" );
                sb.Append( LoginUrl );
                sb.Append( "\r\n\r\n" );
                sb.Append(
                    General.GetString( "SIGNIN_URL_WARNING",
                                      "NOTE: The address above may not show up on your screen as one line. This would prevent you from using the link to access the web page. If this happens, just use the 'cut' and 'paste' options to join the pieces of the URL.",
                                      this ) );

                mail.Body = sb.ToString();
                mail.BodyFormat = MailFormat.Text;

                SmtpMail.SmtpServer = Config.SmtpServer;
                SmtpMail.Send( mail );

                Message.Text =
                    General.GetString( "SIGNIN_PWD_WAS_SENT", "Your password was sent to the addess you provided",
                                      this );
                Message.TextKey = "SIGNIN_PWD_WAS_SENT";
            }
            else {
                Message.Text =
                    General.GetString( "SIGNIN_PWD_MISSING_IN_DB",
                                      "The email you specified does not exists on our database", this );
                Message.TextKey = "SIGNIN_PWD_MISSING_IN_DB";
            }
        }
コード例 #15
0
 public JsonResult Delete(Guid userID)
 {
     var users = new UsersDB();
     users.DeleteUser(userID);
     return Json("ok");
 }
コード例 #16
0
        /// <summary>
        /// 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
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.Web.UI.WebControls.DataListCommandEventArgs"/> instance containing the event data.</param>
        protected void rolesList_ItemCommand(object source, DataListCommandEventArgs e)
        {
            //http://sourceforge.net/tracker/index.php?func=detail&aid=828580&group_id=66837&atid=515929
            UsersDB users = new UsersDB();

            bool enable = true; // enable add - bja

            if (e.CommandName == "edit")
            {
                // Set editable list item index if "edit" button clicked next to the item
                rolesList.EditItemIndex = e.Item.ItemIndex;
                // disable the add function
                enable = false;
                // Repopulate the datalist control
                BindData();
            }

            else if (e.CommandName == "apply")
            {

                var _roleName = ((TextBox)e.Item.FindControl("roleName")).Text;
                var _roleId = ((System.Web.UI.WebControls.Label)e.Item.FindControl("roleId")).Text;

                // update database
                users.UpdateRole(new Guid(_roleId), _roleName, this.PortalSettings.PortalAlias);

                // Disable editable list item access
                rolesList.EditItemIndex = -1;

                // Repopulate the datalist control
                BindData();
            }
            else if (e.CommandName == "delete")
            {
                // [email protected]: 30th May 2004: Added Try And Catch To Delete Role
                // update database
                try
                {
                    users.DeleteRole(new Guid(e.CommandArgument.ToString()), this.PortalSettings.PortalAlias);
                }
                catch
                {
                    labelError.Visible = true;
                }
                // End of [email protected] Update

                // Ensure that item is not editable
                rolesList.EditItemIndex = -1;

                // Repopulate list
                BindData();
            }
            else if (e.CommandName == "members")
            {

                string _roleId = ((System.Web.UI.WebControls.Label)e.Item.FindControl("roleId")).Text;

                // Role names shouldn't be editable, it's not supported by the Roles Provider API
                //// Save role name changes first
                //users.UpdateRole( selectedRole.Id, _roleName, portalSettings.PortalAlias );

                // redirect to edit page
                Response.Redirect(
                    HttpUrlBuilder.BuildUrl("~/DesktopModules/CoreModules/Roles/SecurityRoles.aspx", PageID,
                                            "mID=" + ModuleID.ToString() + "&roleID=" + _roleId));
            }
            // reset the enable state of the add
            // set add button -- bja
            AddRoleBtn.Enabled = enable;
        }
コード例 #17
0
        /// <summary>
        /// The BindData helper method is used to bind the list of
        /// security roles for this portal to an asp:datalist server control
        /// </summary>
        private void BindData()
        {
            // Bind the Email and Password
            UsersDB users = new UsersDB();

            Guid currentUserID = this.userID;// PortalSettings.CurrentUser.Identity.ProviderUserKey;
            // bind users in role to DataList
            IList<AppleseedRole> roles = new List<AppleseedRole>();
            try {
                roles = users.GetRolesByUser(currentUserID, this.PortalSettings.PortalAlias);
            } catch (Exception exc) {
                ErrorHandler.Publish(LogLevel.Error, exc);
            }
            userRoles.DataKeyField = "Id";
            userRoles.DataSource = roles;
            userRoles.DataBind();

            // bind all portal roles to dropdownlist
            IList<AppleseedRole> allRolesList = users.GetPortalRoles(this.PortalSettings.PortalAlias);

            // remove "All Users", "Authenticated Users" and "Unauthenticated Users" pseudo-roles
            AppleseedRole pseudoRole = new AppleseedRole(AppleseedRoleProvider.AllUsersGuid, AppleseedRoleProvider.AllUsersRoleName);

            if (allRolesList.Contains(pseudoRole))
            {
                allRolesList.Remove(pseudoRole);
            }
            pseudoRole = new AppleseedRole(AppleseedRoleProvider.AuthenticatedUsersGuid, AppleseedRoleProvider.AuthenticatedUsersRoleName);
            if (allRolesList.Contains(pseudoRole))
            {
                allRolesList.Remove(pseudoRole);
            }
            pseudoRole = new AppleseedRole(AppleseedRoleProvider.UnauthenticatedUsersGuid, AppleseedRoleProvider.UnauthenticatedUsersRoleName);
            if (allRolesList.Contains(pseudoRole))
            {
                allRolesList.Remove(pseudoRole);
            }

            allRoles.DataSource = allRolesList;
            allRoles.DataBind();
        }
コード例 #18
0
        /// <summary>
        /// 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
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.Web.UI.WebControls.DataListCommandEventArgs"/> instance containing the event data.</param>
        protected void usersInRole_ItemCommand(object sender, DataListCommandEventArgs e)
        {
            UsersDB users = new UsersDB();

            Label lblUserEmail = (Label)e.Item.FindControl("lblUserEmail");
            string userName = Membership.GetUserNameByEmail(lblUserEmail.Text);
            AppleseedUser user = (AppleseedUser)Membership.GetUser(userName);

            if (e.CommandName == "delete")
            {
                // update database
                users.DeleteUserRole(roleId, user.ProviderUserKey, this.PortalSettings.PortalAlias);

                // Ensure that item is not editable
                usersInRole.EditItemIndex = -1;

                // Repopulate list
                BindData();
            }
        }
コード例 #19
0
        /// <summary>
        /// The UserRoles_ItemCommand server event handler on this page
        /// is used to handle deleting the user from roles
        /// from the userRoles asp:datalist control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.DataListCommandEventArgs"/> instance containing the event data.</param>
        private void UserRoles_ItemCommand(object sender, DataListCommandEventArgs e)
        {
            UsersDB users = new UsersDB();
            Guid roleID = (Guid)userRoles.DataKeys[e.Item.ItemIndex];

            // update database
            users.DeleteUserRole(roleID, userID, this.PortalSettings.PortalAlias);

            // Ensure that item is not editable
            userRoles.EditItemIndex = -1;

            // Repopulate list
            BindData();
        }
コード例 #20
0
        /// <summary>
        /// The AddRole_Click server event handler is used to add
        /// the user to this security role.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void AddRole_Click(Object sender, EventArgs e)
        {
            Guid roleID;

            //get user id from dropdownlist of existing users
            roleID = new Guid(allRoles.SelectedItem.Value);

            // Add a new userRole to the database
            UsersDB users = new UsersDB();

            users.AddUserRole(roleID, userID, this.PortalSettings.PortalAlias);

            // Rebind list
            BindData();
        }
コード例 #21
0
        /// <summary>
        /// Save user data
        /// </summary>
        /// <returns>
        /// The user id
        /// </returns>
        public Guid SaveUserData()
        {
            var returnId = Guid.Empty;

            if (this.PasswordField.Text.Length > 0 || this.ConfirmPasswordField.Text.Length > 0)
            {
                if (this.PasswordField.Text != this.ConfirmPasswordField.Text)
                {
                    this.ComparePasswords.IsValid = false;
                }
            }

            // Only attempt a login if all form fields on the page are valid
            if (this.Page.IsValid)
            {
                var accountSystem = new UsersDB();

                var countryId = string.Empty;
                if (this.CountryField.SelectedItem != null)
                {
                    countryId = this.CountryField.SelectedItem.Value;
                }

                var stateId = 0;
                if (this.StateField.SelectedItem != null)
                {
                    stateId = Convert.ToInt32(this.StateField.SelectedItem.Value);
                }

                try
                {
                    if (this.UserName == string.Empty)
                    {
                        // Add New User to Portal User Database
                        returnId = accountSystem.AddUser(
                            this.NameField.Text,
                            this.CompanyField.Text,
                            this.AddressField.Text,
                            this.CityField.Text,
                            this.ZipField.Text,
                            countryId,
                            stateId,
                            this.PhoneField.Text,
                            this.FaxField.Text,
                            this.PasswordField.Text,
                            this.EmailField.Text,
                            this.SendNewsletter.Checked,
                            CurrentPortalSettings.PortalAlias);
                    }
                    else
                    {
                        // Update user
                        if (this.PasswordField.Text.Equals(this.ConfirmPasswordField.Text) &&
                            this.PasswordField.Text.Equals(string.Empty))
                        {
                            accountSystem.UpdateUser(
                                this.OriginalUserId,
                                this.NameField.Text,
                                this.CompanyField.Text,
                                this.AddressField.Text,
                                this.CityField.Text,
                                this.ZipField.Text,
                                countryId,
                                stateId,
                                this.PhoneField.Text,
                                this.FaxField.Text,
                                this.EmailField.Text,
                                this.SendNewsletter.Checked);
                        }
                        else
                        {
                            accountSystem.UpdateUser(
                                this.OriginalUserId,
                                this.NameField.Text,
                                this.CompanyField.Text,
                                this.AddressField.Text,
                                this.CityField.Text,
                                this.ZipField.Text,
                                countryId,
                                stateId,
                                this.PhoneField.Text,
                                this.FaxField.Text,
                                this.PasswordField.Text,
                                this.EmailField.Text,
                                this.SendNewsletter.Checked,
                                this.PortalSettings.PortalAlias);
                        }

                        // If we are here no error occurred
                    }
                }
                catch (Exception ex)
                {
                    this.Message.Text = General.GetString("REGISTRATION_FAILED", "Registration failed", this.Message) +
                                        " - ";

                    if (ex is SqlException)
                    {
                        if (((SqlException)ex).Number == 2627)
                        {
                            this.Message.Text = General.GetString(
                                "REGISTRATION_FAILED_EXISTING_EMAIL_ADDRESS",
                                "Registration has failed. This email address has already been registered. Please use a different email address or use the 'Send Password' button on the login page.",
                                this.Message);
                        }
                    }

                    ErrorHandler.Publish(LogLevel.Error, "Error registering user", ex);
                }
            }

            return returnId;
        }
コード例 #22
0
        /// <summary>
        /// Single point get roles
        /// </summary>
        public static IList<AppleseedRole> GetRoles()
        {
            // Obtain PortalSettings from Current Context
            PortalSettings portalSettings = (PortalSettings)HttpContext.Current.Items[strPortalSettings];
            int portalID = portalSettings.PortalID;
            // [email protected]: 29th May 2004 When retrieving/editing/adding roles or users etc then portalID should be 0 if it is shared
            // But I commented this out as this check is done in UsersDB.GetRoles Anyway
            //if (Config.UseSingleUserBase) portalID = 0;

            IList<AppleseedRole> roles;

            // TODO: figure out if we could persist role Guid in cookies

            //// Create the roles cookie if it doesn't exist yet for this session.
            //if ((HttpContext.Current.Request.Cookies["portalroles"] == null) || (HttpContext.Current.Request.Cookies["portalroles"].Value == string.Empty) || (HttpContext.Current.Request.Cookies["portalroles"].Expires < DateTime.Now))
            //{
            try
            {
                // Get roles from UserRoles table, and add to cookie
                UsersDB accountSystem = new UsersDB();
                MembershipUser u = accountSystem.GetSingleUser(HttpContext.Current.User.Identity.Name, portalSettings.PortalAlias);
                roles = accountSystem.GetRoles(u.Email, portalSettings.PortalAlias);
            }
            catch (Exception exc)
            {
                ErrorHandler.Publish(LogLevel.Error, exc);
                //no roles
                roles = new List<AppleseedRole>();
            }

            //    // Create a string to persist the roles
            //    string roleStr = string.Empty;
            //    foreach ( AppleseedRole role in roles )
            //    {
            //        roleStr += role.Name;
            //        roleStr += ";";
            //    }

            //    // Create a cookie authentication ticket.
            //    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket
            //        (
            //        1,                              // version
            //        HttpContext.Current.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
            //    HttpContext.Current.Response.Cookies["portalroles"].Value = cookieStr;
            //    HttpContext.Current.Response.Cookies["portalroles"].Path = "/";
            //    HttpContext.Current.Response.Cookies["portalroles"].Expires = DateTime.Now.AddMinutes(1);
            //}
            //else
            //{
            //    // Get roles from roles cookie
            //    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(HttpContext.Current.Request.Cookies["portalroles"].Value);

            //    //convert the string representation of the role data into a string array
            //    ArrayList userRoles = new ArrayList();

            //    //by Jes
            //    string _ticket = ticket.UserData.TrimEnd(new char[] {';'});
            //    foreach (string role in _ticket.Split(new char[] {';'} ))
            //    {
            //        userRoles.Add(role + ";");
            //    }
            //    roles = (string[]) userRoles.ToArray(typeof(string));
            //}

            return roles;
        }
コード例 #23
0
        /// <summary>
        /// The on load.
        /// </summary>
        /// <param name="e">
        /// Event arguments.
        /// </param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!this.Page.IsPostBack)
            {
                // Edit check
                if (this.EditMode)
                {
                    // Someone requested edit this record
                    // True is use is editing himself, false if is edited by an admin
                    this.SelfEdit = this.UserName == PortalSettings.CurrentUser.Identity.UserName;

                    // Removed by Mario Endara <*****@*****.**> (2004/11/04)
                    // if (PortalSecurity.IsInRoles("Admins") || selfEdit)
                    if (PortalSecurity.HasEditPermissions(this.ModuleID) ||
                        PortalSecurity.HasAddPermissions(this.ModuleID) || this.SelfEdit)
                    {
                        // We can edit

                        // Hide
                        this.RequiredPassword.Visible = false;
                        this.RequiredConfirm.Visible = false;
                        this.EditPasswordRow.Visible = true;
                        this.SaveChangesBtn.Visible = true;
                        this.RegisterBtn.Visible = false;

                        // Obtain a single row of event information
                        var accountSystem = new UsersDB();

                        var memberUser = accountSystem.GetSingleUser(this.UserName, this.PortalSettings.PortalAlias);

                        try
                        {
                            this.NameField.Text = memberUser.Name;
                            this.EmailField.Text = memberUser.Email;
                            this.CompanyField.Text = memberUser.Company;
                            this.AddressField.Text = memberUser.Address;
                            this.ZipField.Text = memberUser.Zip;
                            this.CityField.Text = memberUser.City;

                            this.CountryField.ClearSelection();
                            if (this.CountryField.Items.FindByValue(memberUser.CountryID) != null)
                            {
                                this.CountryField.Items.FindByValue(memberUser.CountryID).Selected = true;
                            }

                            this.BindState();
                            this.StateField.ClearSelection();
                            if (this.StateField.Items.Count > 0 &&
                                this.StateField.Items.FindByValue(memberUser.StateID.ToString()) != null)
                            {
                                this.StateField.Items.FindByValue(memberUser.StateID.ToString()).Selected = true;
                            }

                            this.FaxField.Text = memberUser.Fax;
                            this.PhoneField.Text = memberUser.Phone;
                            this.SendNewsletter.Checked = memberUser.SendNewsletter;

                            // stores original password for later check
                            this.OriginalPassword = memberUser.GetPassword();
                            this.OriginalUserId = memberUser.ProviderUserKey;
                        }
                        catch (ArgumentNullException)
                        {
                            // user doesn't exist
                        }
                    }
                    else
                    {
                        // We do not have rights to do it!
                        PortalSecurity.AccessDeniedEdit();
                    }
                }
                else
                {
                    this.BindState();

                    // No edit
                    this.RequiredPassword.Visible = true;
                    this.RequiredConfirm.Visible = true;
                    this.EditPasswordRow.Visible = false;
                    this.SaveChangesBtn.Visible = false;
                    this.RegisterBtn.Visible = true;
                }
            }
        }
コード例 #24
0
        /// <summary>
        /// Single point logoff
        /// </summary>
        public static void SignOut(string urlToRedirect, bool removeLogin)
        {
            StackTrace st = new StackTrace(new StackFrame(2, true));
            var frames = st.GetFrames();
            string stackString = string.Empty;
            foreach (var frame in frames)
            {
                stackString+= "> " + frame.GetMethod().Name;
            }

            ErrorHandler.Publish(LogLevel.Info, "Hago signout: " + stackString);

            // Log User Off from Cookie Authentication System
            FormsAuthentication.SignOut();

            // Invalidate roles token
            HttpCookie hck = HttpContext.Current.Response.Cookies["portalroles"];
            hck.Value = null;
            hck.Expires = new DateTime(1999, 10, 12);
            hck.Path = "/";

            if (removeLogin)
            {
                // Obtain PortalSettings from Current Context
                PortalSettings portalSettings = (PortalSettings)HttpContext.Current.Items[strPortalSettings];

                // Invalidate Portal Alias Cookie security
                HttpCookie xhck = HttpContext.Current.Response.Cookies["Appleseed_" + portalSettings.PortalAlias.ToLower()];
                xhck.Value = null;
                xhck.Expires = new DateTime(1999, 10, 12);
                xhck.Path = "/";
            }

            // [START]  [email protected] remove user window information
            // User Information
            // valid user
            if (HttpContext.Current.User != null)
            {
                // Obtain PortalSettings from Current Context
                //Ender 4 July 2003: Added to support the Monitoring module by Paul Yarrow
                PortalSettings portalSettings = (PortalSettings)HttpContext.Current.Items[strPortalSettings];

                // User Information
                UsersDB users = new UsersDB();
                MembershipUser user = users.GetSingleUser(HttpContext.Current.User.Identity.Name, portalSettings.PortalAlias);

                if (user != null) {
                    // get user id
                    Guid uid = (Guid)user.ProviderUserKey;

                    if (!uid.Equals(Guid.Empty)) {
                        try {
                            if (Config.EnableMonitoring) {
                                Monitoring.LogEntry(uid, portalSettings.PortalID, -1, "Logoff", string.Empty);
                            }
                        } catch { }
                    }
                }
            }
            // [END ]  [email protected] remove user window information

            //Redirect user back to the Portal Home Page
            if (urlToRedirect.Length > 0)
                HttpContext.Current.Response.Redirect(urlToRedirect);
        }
コード例 #25
0
        /// <summary>
        ///   Initializes a new instance of the <see cref = "Articles" /> class.
        /// </summary>
        public Articles()
        {
            this.SupportsWorkflow = true;

            if (this.PortalSettings == null)
            {
                return;
            }

            // check for avoid design time errors

            // modified by Hongwei Shen([email protected]) 12/9/2005
            const SettingItemGroup Group = SettingItemGroup.MODULE_SPECIAL_SETTINGS;
            const int GroupBase = (int)Group;

            // end of modification

            // Set Editor Settings [email protected] 2004/07/30
            // modified by Hongwei Shen
            // HtmlEditorDataType.HtmlEditorSettings (this._baseSettings, SettingItemGroup.MODULE_SPECIAL_SETTINGS);
            HtmlEditorDataType.HtmlEditorSettings(this.BaseSettings, Group);

            // end of modification

            // Switches date display on/off
            var showDate = new SettingItem<bool, CheckBox>
                {
                    Value = true, EnglishName = "Show Date", Group = Group, Order = GroupBase + 20
                };

            // modified by Hongwei Shen
            // ShowDate.Group = SettingItemGroup.MODULE_SPECIAL_SETTINGS;
            // ShowDate.Order = 10;

            // end of modification
            this.BaseSettings.Add("ShowDate", showDate);

            // Added by Rob Siera
            var defaultVisibleDays = new SettingItem<int, TextBox>
                {
                    Value = 90, EnglishName = "Default Days Visible", Group = Group, Order = GroupBase + 25
                };

            // modified by Hongwei Shen
            // DefaultVisibleDays.Group = SettingItemGroup.MODULE_SPECIAL_SETTINGS;
            // DefaultVisibleDays.Order = 20;

            // end of modification
            this.BaseSettings.Add("DefaultVisibleDays", defaultVisibleDays);

            var richAbstract = new SettingItem<bool, CheckBox>
                {
                    Value = true,
                    EnglishName = "Rich Abstract",
                    Description = "User rich editor for abstract",
                    Group = Group,
                    Order = GroupBase + 30
                };

            // modified by Hongwei Shen
            // RichAbstract.Group = SettingItemGroup.MODULE_SPECIAL_SETTINGS;
            // RichAbstract.Order = 30;

            // end of modification
            this.BaseSettings.Add("ARTICLES_RICHABSTRACT", richAbstract);

            var users = new UsersDB();
            var rolesViewExpiredItems =
                new SettingItem<string, CheckBoxList>(
                    new CheckBoxListDataType(
                        users.GetPortalRoles(this.PortalSettings.PortalAlias), "RoleName", "RoleName"))
                    {
                        Value = "Admins",
                        EnglishName = "Expired items visible to",
                        Description = "Role that can see expire items",
                        Group = Group,
                        Order = GroupBase + 40
                    };

            // modified by Hongwei Shen
            // RolesViewExpiredItems.Group = SettingItemGroup.MODULE_SPECIAL_SETTINGS;
            // RolesViewExpiredItems.Order = 40;

            // end of modification
            this.BaseSettings.Add("EXPIRED_PERMISSION_ROLE", rolesViewExpiredItems);
        }