Ejemplo n.º 1
0
        /// <summary>
        /// Registers a new user, using the properties of this class.
        /// </summary>
        /// <param name="nickName">Name of the nick.</param>
        /// <param name="dateOfBirth">The date of birth.</param>
        /// <param name="emailAddress">The email address.</param>
        /// <param name="emailAddressIsPublic">flag to signal if the emailaddress is visible for everyone or not</param>
        /// <param name="iconURL">The icon URL.</param>
        /// <param name="ipNumber">The ip number.</param>
        /// <param name="location">The location.</param>
        /// <param name="occupation">The occupation.</param>
        /// <param name="signature">The signature.</param>
        /// <param name="website">The website.</param>
        /// <param name="emailTemplatePath">The email template path.</param>
        /// <param name="emailData">The email data.</param>
        /// <param name="autoSubscribeThreads">Default value when user creates new threads.</param>
        /// <param name="defaultMessagesPerPage">Messages per page to display</param>
        /// <returns>
        /// UserID of new user or 0 if registration failed.
        /// </returns>
        public static int RegisterNewUser(string nickName, DateTime?dateOfBirth, string emailAddress, bool emailAddressIsPublic, string iconURL,
                                          string ipNumber, string location, string occupation, string signature, string website, string emailTemplatePath, Dictionary <string, string> emailData, ParserData parserData,
                                          bool autoSubscribeThreads, short defaultMessagesPerPage)
        {
            UserEntity newUser = new UserEntity();

            // initialize objects
            newUser.AmountOfPostings     = 0;
            newUser.DateOfBirth          = dateOfBirth;
            newUser.EmailAddress         = emailAddress;
            newUser.EmailAddressIsPublic = emailAddressIsPublic;
            newUser.IPNumber             = ipNumber;
            newUser.IconURL    = iconURL;
            newUser.IsBanned   = false;
            newUser.JoinDate   = DateTime.Now;
            newUser.Location   = location;
            newUser.NickName   = nickName;
            newUser.Occupation = occupation;
            newUser.Signature  = signature;
            newUser.Website    = website;
            string password = HnDGeneralUtils.GenerateRandomPassword();

            newUser.Password = HnDGeneralUtils.CreateMD5HashedBase64String(password);

            //Preferences
            newUser.AutoSubscribeToThread          = autoSubscribeThreads;
            newUser.DefaultNumberOfMessagesPerPage = defaultMessagesPerPage;

            if (!string.IsNullOrEmpty(signature))
            {
                newUser.SignatureAsHTML = TextParser.TransformSignatureUBBStringToHTML(signature, parserData);
            }
            else
            {
                newUser.SignatureAsHTML = "";
            }
            //Fetch the SystemDataEntity to use the "DefaultUserTitleNewUser" as the user title & the "DefaultRoleNewUser"
            // as the roleID of the newly created RoleUserEntity.
            SystemDataEntity systemData = SystemGuiHelper.GetSystemSettings();

            newUser.UserTitleID = systemData.DefaultUserTitleNewUser;

            RoleUserEntity roleUser = new RoleUserEntity();

            roleUser.RoleID = systemData.DefaultRoleNewUser;
            roleUser.User   = newUser;

            // first encode fields which could lead to cross-site-scripting attacks
            EncodeUserTextFields(newUser);

            // now save the new user entity and the new RoleUser entity recursively in one go. This will create a transaction for us
            // under the hood so we don't have to do that ourselves.
            if (newUser.Save(true))
            {
                // all ok, Email the password
                bool result = HnDGeneralUtils.EmailPassword(password, emailAddress, emailTemplatePath, emailData);
            }

            return(newUser.UserID);
        }
Ejemplo n.º 2
0
        /// <summary>Creates a new, empty SystemDataEntity object.</summary>
        /// <returns>A new, empty SystemDataEntity object.</returns>
        public override IEntity Create()
        {
            IEntity toReturn = new SystemDataEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewSystemData
            // __LLBLGENPRO_USER_CODE_REGION_END
            return(toReturn);
        }
Ejemplo n.º 3
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            // If the user doesn't have any access rights to management stuff, the user should
            // be redirected to the default of the global system.
            if (!SessionAdapter.HasSystemActionRights())
            {
                // doesn't have system rights. redirect.
                Response.Redirect("../Default.aspx", true);
            }

            // Check if the user has the right systemright
            if (!SessionAdapter.HasSystemActionRight(ActionRights.SystemManagement))
            {
                // no, redirect to admin default page, since the user HAS access to the admin menu.
                Response.Redirect("Default.aspx", true);
            }

            if (!Page.IsPostBack)
            {
                // load the data into the dropdown boxes.
                RoleCollection allRoles = SecurityGuiHelper.GetAllRoles();

                cbxDefaultRoleNewUsers.DataSource     = allRoles;
                cbxDefaultRoleNewUsers.DataTextField  = "RoleDescription";
                cbxDefaultRoleNewUsers.DataValueField = "RoleID";
                cbxDefaultRoleNewUsers.DataBind();

                cbxAnonymousUserRole.DataSource     = allRoles;
                cbxAnonymousUserRole.DataTextField  = "RoleDescription";
                cbxAnonymousUserRole.DataValueField = "RoleID";
                cbxAnonymousUserRole.DataBind();

                UserTitleCollection userTitles = UserGuiHelper.GetAllUserTitles();

                cbxDefaultUserTitleNewUsers.DataSource     = userTitles;
                cbxDefaultUserTitleNewUsers.DataTextField  = "UserTitleDescription";
                cbxDefaultUserTitleNewUsers.DataValueField = "UserTitleID";
                cbxDefaultUserTitleNewUsers.DataBind();

                // preselect the current values of the system parameters.
                SystemDataEntity systemData = CacheManager.GetSystemData();

                cbxDefaultRoleNewUsers.SelectedValue      = systemData.DefaultRoleNewUser.ToString();
                cbxAnonymousUserRole.SelectedValue        = systemData.AnonymousRole.ToString();
                cbxDefaultUserTitleNewUsers.SelectedValue = systemData.DefaultUserTitleNewUser.ToString();

                tbxActiveThreadsThreshold.Text             = systemData.HoursThresholdForActiveThreads.ToString();
                tbxMinNumberOfNonStickyVisibleThreads.Text = systemData.MinNumberOfNonStickyVisibleThreads.ToString();
                tbxMinNumberOfThreadsToFetch.Text          = systemData.MinNumberOfThreadsToFetch.ToString();
                tbxPageSizeInSearchResults.Text            = systemData.PageSizeSearchResults.ToString();

                chkSendReplyNotifications.Checked = systemData.SendReplyNotifications;

                ViewState.Add("ID", systemData.ID);
            }
        }
Ejemplo n.º 4
0
    /// <summary>
    /// Gets the system data entity from the cache. If the entity isn't found in the cache, it's loaded first, stored in the cache and then returned.
    /// </summary>
    /// <returns>entity with system data, or null if not found.</returns>
    public static SystemDataEntity GetSystemData()
    {
        Cache            activeCache = HttpRuntime.Cache;
        SystemDataEntity toReturn    = (SystemDataEntity)activeCache[CacheKeys.SystemData];

        if (toReturn == null)
        {
            toReturn = SystemGuiHelper.GetSystemSettings();
            if (toReturn != null)
            {
                // found, cache it
                activeCache.Insert(CacheKeys.SystemData, toReturn);
            }
        }
        return(toReturn);
    }
Ejemplo n.º 5
0
        /// <summary>
        /// Will overwrite the system settings stored in SystemData. As there's just one record and that record is already there, it's just overwriting the
        /// existing entity.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="newDefaultUserRoleNewUsers">The new default user role for new users.</param>
        /// <param name="newAnonymousRole">The new anonymous role.</param>
        /// <param name="newUserTitleNewUsers">The new user title for new users.</param>
        /// <param name="hoursThresholdForActiveThreads">The hours threshold for active threads.</param>
        /// <param name="pageSizeSearchResults">The page size search results.</param>
        /// <param name="minimalNumberOfThreadsToFetch">The minimal number of threads to fetch.</param>
        /// <param name="minimalNumberOfNonStickyVisibleThreads">The minimal number of non sticky visible threads.</param>
        /// <param name="sendReplyNotifications">The setting to send notification emails or not. If set to false the system won't send
        /// notification emails and users can't subscribe / unsubscribe to threads.</param>
        /// <returns>
        /// true if save was succeeded, false otherwise
        /// </returns>
        public static bool StoreNewSystemSettings(int id, int newDefaultUserRoleNewUsers, int newAnonymousRole, int newUserTitleNewUsers,
                                                  short hoursThresholdForActiveThreads, short pageSizeSearchResults, short minimalNumberOfThreadsToFetch,
                                                  short minimalNumberOfNonStickyVisibleThreads, bool sendReplyNotifications)
        {
            // fetch the existing system data entity.
            SystemDataEntity systemData = new SystemDataEntity(id);

            // update its parameters.
            systemData.DefaultRoleNewUser                 = newDefaultUserRoleNewUsers;
            systemData.AnonymousRole                      = newAnonymousRole;
            systemData.DefaultUserTitleNewUser            = newUserTitleNewUsers;
            systemData.HoursThresholdForActiveThreads     = hoursThresholdForActiveThreads;
            systemData.PageSizeSearchResults              = pageSizeSearchResults;
            systemData.MinNumberOfNonStickyVisibleThreads = minimalNumberOfNonStickyVisibleThreads;
            systemData.MinNumberOfThreadsToFetch          = minimalNumberOfThreadsToFetch;
            systemData.SendReplyNotifications             = sendReplyNotifications;
            return(systemData.Save());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Constructs a dataview with all the roles available, complete with statistics (#users, if the role is used as anonymous role or default user role)
        /// </summary>
        /// <returns>DataView with all the Roles available, directly bindable to webcontrols</returns>
        public static DataView GetAllRolesWithStatisticsAsDataView()
        {
            // create dynamic list, with all fields of Role and 3 extra fields: one field for the # of users in the role, one field which
            // signals if the role is the defaultnewuserrole and one field which signals if the role is the anonymous role. The # of users field is
            // used in the query, the other two fields are added later for efficiency.
            var qf = new QueryFactory();
            var q  = qf.Create()
                     .Select(RoleFields.RoleID,
                             RoleFields.RoleDescription,
                             // now add the # of users subquery to the resultset. This will result in the query:
                             // (
                             //    SELECT   COUNT(UserID)
                             //    FROM	RoleUser
                             //    WHERE RoleUser.RoleID = Role.RoleID
                             // ) AS AmountUsersInRole
                             qf.Create()
                             .Select(RoleUserFields.UserID.Count())
                             .CorrelatedOver(RoleUserFields.RoleID == RoleFields.RoleID)
                             .ToScalar()
                             .As("AmountUsersInRole"))
                     .OrderBy(RoleFields.RoleDescription.Ascending());
            var dao     = new TypedListDAO();
            var results = dao.FetchAsDataTable(q);

            // we now fetch the system data which contains the two role id's we've to check with in the results to return.
            SystemDataEntity systemData = SystemGuiHelper.GetSystemSettings();

            // now add 2 columns to the datatable, booleans, which are used to store the flags for IsDefaultNewUserRole and IsAnonymousRole, so the complete
            // set of data can be processed in a list form.
            results.Columns.Add(new DataColumn("IsDefaultNewUserRole", typeof(bool)));
            results.Columns.Add(new DataColumn("IsAnonymousRole", typeof(bool)));
            foreach (DataRow row in results.Rows)
            {
                row["IsDefaultNewUserRole"] = ((int)row["RoleID"] == systemData.DefaultRoleNewUser);
                row["IsAnonymousRole"]      = ((int)row["RoleID"] == systemData.AnonymousRole);
            }

            // done, return the dataview of this datatable
            return(results.DefaultView);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Handles the Load event of the Page 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 Page_Load(object sender, System.EventArgs e)
        {
            int forumID = HnDGeneralUtils.TryConvertToInt(Request.QueryString["ForumID"]);

            bool userHasAccess = SessionAdapter.CanPerformForumActionRight(forumID, ActionRights.AccessForum);

            if (!userHasAccess)
            {
                // doesn't have access to this forum. redirect
                Response.Redirect("default.aspx");
            }

            bool userCanCreateThreads = (SessionAdapter.CanPerformForumActionRight(forumID, ActionRights.AddNormalThread) ||
                                         SessionAdapter.CanPerformForumActionRight(forumID, ActionRights.AddStickyThread));

            // Controls are visible by default. Hide them when the user can't create threads on this forum
            if (!userCanCreateThreads)
            {
                lnkNewThreadBottom.Visible = false;
                lnkNewThreadTop.Visible    = false;
            }

            // fill the page's content
            ForumEntity forum = CacheManager.GetForum(forumID);

            if (forum == null)
            {
                // not found.
                Response.Redirect("default.aspx");
            }
            _forumName = forum.ForumName;

            if (!Page.IsPostBack)
            {
                cbxThreadListInterval.SelectedValue = forum.DefaultThreadListInterval.ToString();

                string forumNameEncoded = HttpUtility.HtmlEncode(_forumName);
                lblForumName.Text        = forumNameEncoded;
                lblForumName_Header.Text = HttpUtility.HtmlEncode(_forumName);
                lblForumDescription.Text = HttpUtility.HtmlEncode(forum.ForumDescription);
                lblSectionName.Text      = CacheManager.GetSectionName(forum.SectionID);

                string newThreadURL = string.Format("{0}?ForumID={1}", lnkNewThreadTop.NavigateUrl, forumID);
                lnkNewThreadTop.NavigateUrl    = newThreadURL;
                lnkNewThreadBottom.NavigateUrl = newThreadURL;
                if (forum.HasRSSFeed)
                {
                    lnkForumRSS.NavigateUrl += string.Format("?ForumID={0}", forumID);
                }
                else
                {
                    lnkForumRSS.Visible        = false;
                    litRssButtonSpacer.Visible = false;
                }
            }

            SystemDataEntity systemData = CacheManager.GetSystemData();
            int      postLimiter        = HnDGeneralUtils.TryConvertToInt(cbxThreadListInterval.SelectedValue);
            DataView threadsView        = ForumGuiHelper.GetAllThreadsInForumAsDataView(forumID, (ThreadListInterval)(byte)postLimiter,
                                                                                        systemData.MinNumberOfThreadsToFetch, systemData.MinNumberOfNonStickyVisibleThreads,
                                                                                        SessionAdapter.CanPerformForumActionRight(forumID, ActionRights.ViewNormalThreadsStartedByOthers),
                                                                                        SessionAdapter.GetUserID());

            rpThreads.DataSource = threadsView;
            rpThreads.DataBind();
            threadsView.Dispose();
        }