Ejemplo n.º 1
0
        /// <summary>Creates a new, empty RoleUserEntity object.</summary>
        /// <returns>A new, empty RoleUserEntity object.</returns>
        public override IEntity Create()
        {
            IEntity toReturn = new RoleUserEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewRoleUser
            // __LLBLGENPRO_USER_CODE_REGION_END
            return toReturn;
        }
Ejemplo n.º 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="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.º 3
0
        /// <summary>
        /// Adds all users which ID's are stored in UsersToAdd, to the role with ID RoleID.
        /// </summary>
        /// <param name="userIDsToAdd">List with UserIDs of the users to add</param>
        /// <param name="roleID">ID of role the users will be added to</param>
        /// <returns>true if succeeded, false otherwise</returns>
        public static bool AddUsersToRole(List<int> userIDsToAdd, int roleID)
        {
            if(userIDsToAdd.Count<=0)
            {
                return true;
            }

            RoleUserCollection roleUsers = new RoleUserCollection();
            // for each userid in the list, add a new entity to the collection
            foreach(int userID in userIDsToAdd)
            {
                RoleUserEntity newRoleUser = new RoleUserEntity();
                newRoleUser.UserID = userID;
                newRoleUser.RoleID = roleID;
                roleUsers.Add(newRoleUser);
            }

            // save the new role-user combinations
            return (roleUsers.SaveMulti() > 0);
        }