예제 #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);
        }
예제 #2
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="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 async Task <int> RegisterNewUserAsync(string nickName, DateTime?dateOfBirth, string emailAddress, bool emailAddressIsPublic, string iconUrl,
                                                            string ipNumber, string location, string occupation, string signature, string website,
                                                            Dictionary <string, string> emailData, bool autoSubscribeThreads, short defaultMessagesPerPage)
        {
            var newUser = new UserEntity
            {
                AmountOfPostings     = 0,
                DateOfBirth          = dateOfBirth,
                EmailAddress         = emailAddress,
                EmailAddressIsPublic = emailAddressIsPublic,
                IPNumber             = ipNumber,
                IconURL    = iconUrl,
                IsBanned   = false,
                JoinDate   = DateTime.Now,
                Location   = location,
                NickName   = nickName,
                Occupation = occupation,
                Signature  = signature,
                Website    = website
            };

            var password = HnDGeneralUtils.GenerateRandomPassword();

            newUser.Password = HnDGeneralUtils.HashPassword(password, performPreMD5Hashing: true);

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

            //Fetch the SystemDataEntity to use the "DefaultUserTitleNewUser" as the user title & the "DefaultRoleNewUser" as the roleID of the newly
            //created RoleUserEntity.
            var systemData = await SystemGuiHelper.GetSystemSettingsAsync();

            newUser.UserTitleID = systemData.DefaultUserTitleNewUser;
            newUser.RoleUser.Add(new RoleUserEntity {
                RoleID = systemData.DefaultRoleNewUser
            });

            // 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.
            using (var adapter = new DataAccessAdapter())
            {
                if (await adapter.SaveEntityAsync(newUser).ConfigureAwait(false))
                {
                    // all ok, Email the password
                    await HnDGeneralUtils.EmailPassword(password, emailAddress, emailData);
                }
            }

            return(newUser.UserID);
        }
예제 #3
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);
        }