Exemple #1
0
 /// <summary> Removes the sync logic for member _postedByUser</summary>
 /// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
 /// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
 private void DesetupSyncPostedByUser(bool signalRelatedEntity, bool resetFKFields)
 {
     this.PerformDesetupSyncRelatedEntity( _postedByUser, new PropertyChangedEventHandler( OnPostedByUserPropertyChanged ), "PostedByUser", SD.HnD.DAL.RelationClasses.StaticMessageRelations.UserEntityUsingPostedByUserIDStatic, true, signalRelatedEntity, "PostedMessages", resetFKFields, new int[] { (int)MessageFieldIndex.PostedByUserID } );
     _postedByUser = null;
 }
 /// <summary> setups the sync logic for member _placedInQueueByUser</summary>
 /// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
 private void SetupSyncPlacedInQueueByUser(IEntityCore relatedEntity)
 {
     if(_placedInQueueByUser!=relatedEntity)
     {
         DesetupSyncPlacedInQueueByUser(true, true);
         _placedInQueueByUser = (UserEntity)relatedEntity;
         this.PerformSetupSyncRelatedEntity( _placedInQueueByUser, new PropertyChangedEventHandler( OnPlacedInQueueByUserPropertyChanged ), "PlacedInQueueByUser", SD.HnD.DAL.RelationClasses.StaticSupportQueueThreadRelations.UserEntityUsingPlacedInQueueByUserIDStatic, true, ref _alreadyFetchedPlacedInQueueByUser, new string[] {  } );
     }
 }
Exemple #3
0
 /// <summary>
 /// Checks if the user with the given UserID exists in the database.
 /// </summary>
 /// <param name="userID">The UserID of the user to check if he/she exists in the database</param>
 /// <returns>true if user exists, false otherwise. </returns>
 public static bool DoesUserExist(int userID)
 {
     UserEntity user = new UserEntity(userID);
     // return true if the user entity was fetched succesfully, i.e.: the entity isn't new anymore.
     return (!user.IsNew);
 }
Exemple #4
0
 /// <summary> setups the sync logic for member _setByUser</summary>
 /// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
 private void SetupSyncSetByUser(IEntityCore relatedEntity)
 {
     if(_setByUser!=relatedEntity)
     {
         DesetupSyncSetByUser(true, true);
         _setByUser = (UserEntity)relatedEntity;
         this.PerformSetupSyncRelatedEntity( _setByUser, new PropertyChangedEventHandler( OnSetByUserPropertyChanged ), "SetByUser", SD.HnD.DAL.RelationClasses.StaticIPBanRelations.UserEntityUsingIPBanSetByUserIDStatic, true, ref _alreadyFetchedSetByUser, new string[] { "SetByUserNickName" } );
     }
 }
        /// <summary>Private CTor for deserialization</summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        protected SupportQueueThreadEntityBase(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            _supportQueue = (SupportQueueEntity)info.GetValue("_supportQueue", typeof(SupportQueueEntity));
            if(_supportQueue!=null)
            {
                _supportQueue.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _supportQueueReturnsNewIfNotFound = info.GetBoolean("_supportQueueReturnsNewIfNotFound");
            _alwaysFetchSupportQueue = info.GetBoolean("_alwaysFetchSupportQueue");
            _alreadyFetchedSupportQueue = info.GetBoolean("_alreadyFetchedSupportQueue");

            _claimedByUser = (UserEntity)info.GetValue("_claimedByUser", typeof(UserEntity));
            if(_claimedByUser!=null)
            {
                _claimedByUser.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _claimedByUserReturnsNewIfNotFound = info.GetBoolean("_claimedByUserReturnsNewIfNotFound");
            _alwaysFetchClaimedByUser = info.GetBoolean("_alwaysFetchClaimedByUser");
            _alreadyFetchedClaimedByUser = info.GetBoolean("_alreadyFetchedClaimedByUser");

            _placedInQueueByUser = (UserEntity)info.GetValue("_placedInQueueByUser", typeof(UserEntity));
            if(_placedInQueueByUser!=null)
            {
                _placedInQueueByUser.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _placedInQueueByUserReturnsNewIfNotFound = info.GetBoolean("_placedInQueueByUserReturnsNewIfNotFound");
            _alwaysFetchPlacedInQueueByUser = info.GetBoolean("_alwaysFetchPlacedInQueueByUser");
            _alreadyFetchedPlacedInQueueByUser = info.GetBoolean("_alreadyFetchedPlacedInQueueByUser");
            _thread = (ThreadEntity)info.GetValue("_thread", typeof(ThreadEntity));
            if(_thread!=null)
            {
                _thread.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _threadReturnsNewIfNotFound = info.GetBoolean("_threadReturnsNewIfNotFound");
            _alwaysFetchThread = info.GetBoolean("_alwaysFetchThread");
            _alreadyFetchedThread = info.GetBoolean("_alreadyFetchedThread");
            this.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance());
            // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
            // __LLBLGENPRO_USER_CODE_REGION_END
        }
Exemple #6
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;
        }
Exemple #7
0
 /// <summary>
 /// Encodes some of the user text fields in the passed in entity. Encoding is done here so the data is HtmlEncoded when it's saved into the database.
 /// This routine is used in code to store data. It's stored encoded so viewing logic isn't relying on the encoding code inside the page, which might be
 /// absent and which then would create a potential cross-site scripting error. 
 /// </summary>
 /// <param name="toEncode">To encode.</param>
 /// <remarks>Fields which are filled in by the user are encoded using HtmlEncoding. The signature is parsed by the UBB parser and therefore already 
 /// is free from potential scripting code as tag markers are already converted to html encoded characters. </remarks>
 private static void EncodeUserTextFields(UserEntity toEncode)
 {
     toEncode.EmailAddress = HttpUtility.HtmlEncode(toEncode.EmailAddress);
     toEncode.Occupation = HttpUtility.HtmlEncode(toEncode.Occupation);
     toEncode.Location = HttpUtility.HtmlEncode(toEncode.Location);
     toEncode.Website = HttpUtility.HtmlEncode(toEncode.Website);
     toEncode.IconURL = HttpUtility.HtmlEncode(toEncode.IconURL);
 }
 /// <summary> setups the sync logic for member _userAudited</summary>
 /// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
 private void SetupSyncUserAudited(IEntityCore relatedEntity)
 {
     if(_userAudited!=relatedEntity)
     {
         DesetupSyncUserAudited(true, true);
         _userAudited = (UserEntity)relatedEntity;
         this.PerformSetupSyncRelatedEntity( _userAudited, new PropertyChangedEventHandler( OnUserAuditedPropertyChanged ), "UserAudited", SD.HnD.DAL.RelationClasses.StaticAuditDataCoreRelations.UserEntityUsingUserIDStatic, true, ref _alreadyFetchedUserAudited, new string[] {  } );
     }
 }
 /// <summary> setups the sync logic for member _user</summary>
 /// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
 private void SetupSyncUser(IEntityCore relatedEntity)
 {
     if(_user!=relatedEntity)
     {
         DesetupSyncUser(true, true);
         _user = (UserEntity)relatedEntity;
         this.PerformSetupSyncRelatedEntity( _user, new PropertyChangedEventHandler( OnUserPropertyChanged ), "User", SD.HnD.DAL.RelationClasses.StaticThreadSubscriptionRelations.UserEntityUsingUserIDStatic, true, ref _alreadyFetchedUser, new string[] {  } );
     }
 }
        /// <summary>Private CTor for deserialization</summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        protected AuditDataCoreEntityBase(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            _auditAction = (AuditActionEntity)info.GetValue("_auditAction", typeof(AuditActionEntity));
            if(_auditAction!=null)
            {
                _auditAction.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _auditActionReturnsNewIfNotFound = info.GetBoolean("_auditActionReturnsNewIfNotFound");
            _alwaysFetchAuditAction = info.GetBoolean("_alwaysFetchAuditAction");
            _alreadyFetchedAuditAction = info.GetBoolean("_alreadyFetchedAuditAction");

            _userAudited = (UserEntity)info.GetValue("_userAudited", typeof(UserEntity));
            if(_userAudited!=null)
            {
                _userAudited.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _userAuditedReturnsNewIfNotFound = info.GetBoolean("_userAuditedReturnsNewIfNotFound");
            _alwaysFetchUserAudited = info.GetBoolean("_alwaysFetchUserAudited");
            _alreadyFetchedUserAudited = info.GetBoolean("_alreadyFetchedUserAudited");
            this.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance());
            // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
            // __LLBLGENPRO_USER_CODE_REGION_END
        }
 /// <summary> Removes the sync logic for member _userAudited</summary>
 /// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
 /// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
 private void DesetupSyncUserAudited(bool signalRelatedEntity, bool resetFKFields)
 {
     this.PerformDesetupSyncRelatedEntity( _userAudited, new PropertyChangedEventHandler( OnUserAuditedPropertyChanged ), "UserAudited", SD.HnD.DAL.RelationClasses.StaticAuditDataCoreRelations.UserEntityUsingUserIDStatic, true, signalRelatedEntity, "LoggedAudits", resetFKFields, new int[] { (int)AuditDataCoreFieldIndex.UserID } );
     _userAudited = null;
 }
Exemple #12
0
 /// <summary> Removes the sync logic for member _userWhoStartedThread</summary>
 /// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
 /// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
 private void DesetupSyncUserWhoStartedThread(bool signalRelatedEntity, bool resetFKFields)
 {
     this.PerformDesetupSyncRelatedEntity( _userWhoStartedThread, new PropertyChangedEventHandler( OnUserWhoStartedThreadPropertyChanged ), "UserWhoStartedThread", SD.HnD.DAL.RelationClasses.StaticThreadRelations.UserEntityUsingStartedByUserIDStatic, true, signalRelatedEntity, "StartedThreads", resetFKFields, new int[] { (int)ThreadFieldIndex.StartedByUserID } );
     _userWhoStartedThread = null;
 }
Exemple #13
0
        /// <summary>Private CTor for deserialization</summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        protected ThreadEntityBase(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            _auditDataThreadRelated = (SD.HnD.DAL.CollectionClasses.AuditDataThreadRelatedCollection)info.GetValue("_auditDataThreadRelated", typeof(SD.HnD.DAL.CollectionClasses.AuditDataThreadRelatedCollection));
            _alwaysFetchAuditDataThreadRelated = info.GetBoolean("_alwaysFetchAuditDataThreadRelated");
            _alreadyFetchedAuditDataThreadRelated = info.GetBoolean("_alreadyFetchedAuditDataThreadRelated");

            _presentInBookmarks = (SD.HnD.DAL.CollectionClasses.BookmarkCollection)info.GetValue("_presentInBookmarks", typeof(SD.HnD.DAL.CollectionClasses.BookmarkCollection));
            _alwaysFetchPresentInBookmarks = info.GetBoolean("_alwaysFetchPresentInBookmarks");
            _alreadyFetchedPresentInBookmarks = info.GetBoolean("_alreadyFetchedPresentInBookmarks");

            _messages = (SD.HnD.DAL.CollectionClasses.MessageCollection)info.GetValue("_messages", typeof(SD.HnD.DAL.CollectionClasses.MessageCollection));
            _alwaysFetchMessages = info.GetBoolean("_alwaysFetchMessages");
            _alreadyFetchedMessages = info.GetBoolean("_alreadyFetchedMessages");

            _threadSubscription = (SD.HnD.DAL.CollectionClasses.ThreadSubscriptionCollection)info.GetValue("_threadSubscription", typeof(SD.HnD.DAL.CollectionClasses.ThreadSubscriptionCollection));
            _alwaysFetchThreadSubscription = info.GetBoolean("_alwaysFetchThreadSubscription");
            _alreadyFetchedThreadSubscription = info.GetBoolean("_alreadyFetchedThreadSubscription");
            _usersWhoBookmarkedThread = (SD.HnD.DAL.CollectionClasses.UserCollection)info.GetValue("_usersWhoBookmarkedThread", typeof(SD.HnD.DAL.CollectionClasses.UserCollection));
            _alwaysFetchUsersWhoBookmarkedThread = info.GetBoolean("_alwaysFetchUsersWhoBookmarkedThread");
            _alreadyFetchedUsersWhoBookmarkedThread = info.GetBoolean("_alreadyFetchedUsersWhoBookmarkedThread");

            _usersWhoPostedInThread = (SD.HnD.DAL.CollectionClasses.UserCollection)info.GetValue("_usersWhoPostedInThread", typeof(SD.HnD.DAL.CollectionClasses.UserCollection));
            _alwaysFetchUsersWhoPostedInThread = info.GetBoolean("_alwaysFetchUsersWhoPostedInThread");
            _alreadyFetchedUsersWhoPostedInThread = info.GetBoolean("_alreadyFetchedUsersWhoPostedInThread");

            _usersWhoSubscribedThread = (SD.HnD.DAL.CollectionClasses.UserCollection)info.GetValue("_usersWhoSubscribedThread", typeof(SD.HnD.DAL.CollectionClasses.UserCollection));
            _alwaysFetchUsersWhoSubscribedThread = info.GetBoolean("_alwaysFetchUsersWhoSubscribedThread");
            _alreadyFetchedUsersWhoSubscribedThread = info.GetBoolean("_alreadyFetchedUsersWhoSubscribedThread");
            _forum = (ForumEntity)info.GetValue("_forum", typeof(ForumEntity));
            if(_forum!=null)
            {
                _forum.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _forumReturnsNewIfNotFound = info.GetBoolean("_forumReturnsNewIfNotFound");
            _alwaysFetchForum = info.GetBoolean("_alwaysFetchForum");
            _alreadyFetchedForum = info.GetBoolean("_alreadyFetchedForum");

            _userWhoStartedThread = (UserEntity)info.GetValue("_userWhoStartedThread", typeof(UserEntity));
            if(_userWhoStartedThread!=null)
            {
                _userWhoStartedThread.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _userWhoStartedThreadReturnsNewIfNotFound = info.GetBoolean("_userWhoStartedThreadReturnsNewIfNotFound");
            _alwaysFetchUserWhoStartedThread = info.GetBoolean("_alwaysFetchUserWhoStartedThread");
            _alreadyFetchedUserWhoStartedThread = info.GetBoolean("_alreadyFetchedUserWhoStartedThread");
            _supportQueueThread = (SupportQueueThreadEntity)info.GetValue("_supportQueueThread", typeof(SupportQueueThreadEntity));
            if(_supportQueueThread!=null)
            {
                _supportQueueThread.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _supportQueueThreadReturnsNewIfNotFound = info.GetBoolean("_supportQueueThreadReturnsNewIfNotFound");
            _alwaysFetchSupportQueueThread = info.GetBoolean("_alwaysFetchSupportQueueThread");
            _alreadyFetchedSupportQueueThread = info.GetBoolean("_alreadyFetchedSupportQueueThread");
            this.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance());
            // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
            // __LLBLGENPRO_USER_CODE_REGION_END
        }
Exemple #14
0
 /// <summary>
 /// Checks if the user with the given NickName exists in the database. This is necessary to check if a user which gets authenticated through
 /// forms authentication is still available in the database.
 /// </summary>
 /// <param name="nickName">The nickname of the user to check if he/she exists in the database</param>
 /// <param name="user">The user object is returned</param>
 /// <returns>true if user exists, false otherwise.</returns>
 public static bool DoesUserExist(string nickName, out UserEntity user)
 {
     user = new UserEntity();
     // fetch the user using the unique constraint functionality.
     return user.FetchUsingUCNickName(nickName);
 }
Exemple #15
0
        /// <summary>Private CTor for deserialization</summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        protected MessageEntityBase(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            _attachments = (SD.HnD.DAL.CollectionClasses.AttachmentCollection)info.GetValue("_attachments", typeof(SD.HnD.DAL.CollectionClasses.AttachmentCollection));
            _alwaysFetchAttachments = info.GetBoolean("_alwaysFetchAttachments");
            _alreadyFetchedAttachments = info.GetBoolean("_alreadyFetchedAttachments");

            _auditDataMessageRelated = (SD.HnD.DAL.CollectionClasses.AuditDataMessageRelatedCollection)info.GetValue("_auditDataMessageRelated", typeof(SD.HnD.DAL.CollectionClasses.AuditDataMessageRelatedCollection));
            _alwaysFetchAuditDataMessageRelated = info.GetBoolean("_alwaysFetchAuditDataMessageRelated");
            _alreadyFetchedAuditDataMessageRelated = info.GetBoolean("_alreadyFetchedAuditDataMessageRelated");
            _thread = (ThreadEntity)info.GetValue("_thread", typeof(ThreadEntity));
            if(_thread!=null)
            {
                _thread.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _threadReturnsNewIfNotFound = info.GetBoolean("_threadReturnsNewIfNotFound");
            _alwaysFetchThread = info.GetBoolean("_alwaysFetchThread");
            _alreadyFetchedThread = info.GetBoolean("_alreadyFetchedThread");

            _postedByUser = (UserEntity)info.GetValue("_postedByUser", typeof(UserEntity));
            if(_postedByUser!=null)
            {
                _postedByUser.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _postedByUserReturnsNewIfNotFound = info.GetBoolean("_postedByUserReturnsNewIfNotFound");
            _alwaysFetchPostedByUser = info.GetBoolean("_alwaysFetchPostedByUser");
            _alreadyFetchedPostedByUser = info.GetBoolean("_alreadyFetchedPostedByUser");
            this.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance());
            // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
            // __LLBLGENPRO_USER_CODE_REGION_END
        }
Exemple #16
0
        /// <summary>Creates a new, empty UserEntity object.</summary>
        /// <returns>A new, empty UserEntity object.</returns>
        public override IEntity Create()
        {
            IEntity toReturn = new UserEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewUser
            // __LLBLGENPRO_USER_CODE_REGION_END
            return toReturn;
        }
Exemple #17
0
 /// <summary> setups the sync logic for member _postedByUser</summary>
 /// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
 private void SetupSyncPostedByUser(IEntityCore relatedEntity)
 {
     if(_postedByUser!=relatedEntity)
     {
         DesetupSyncPostedByUser(true, true);
         _postedByUser = (UserEntity)relatedEntity;
         this.PerformSetupSyncRelatedEntity( _postedByUser, new PropertyChangedEventHandler( OnPostedByUserPropertyChanged ), "PostedByUser", SD.HnD.DAL.RelationClasses.StaticMessageRelations.UserEntityUsingPostedByUserIDStatic, true, ref _alreadyFetchedPostedByUser, new string[] {  } );
     }
 }
Exemple #18
0
 /// <summary> Removes the sync logic for member _user</summary>
 /// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
 /// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
 private void DesetupSyncUser(bool signalRelatedEntity, bool resetFKFields)
 {
     this.PerformDesetupSyncRelatedEntity( _user, new PropertyChangedEventHandler( OnUserPropertyChanged ), "User", SD.HnD.DAL.RelationClasses.StaticRoleUserRelations.UserEntityUsingUserIDStatic, true, signalRelatedEntity, "RoleUser", resetFKFields, new int[] { (int)RoleUserFieldIndex.UserID } );
     _user = null;
 }
Exemple #19
0
        /// <summary>
        /// Resets the user's Password by generating a new random password which is mailed to
        /// the emailaddress specified. Will fail if the nickname doesn't exist or the emailaddress
        /// doesn't match with the specified emailaddress of the nickname in the database.
        /// </summary>
        /// <param name="nickName">Nickname of user which password should be reset</param>
        /// <param name="emailAddress">Emailaddress of user</param>
        /// <param name="emailTemplate">The email template.</param>
        /// <param name="emailData">The email data.</param>
        /// <returns>true if succeed, false otherwise</returns>
        /// <exception cref="NickNameNotFoundException">Throws NickNameNotFoundException when the nickname isn't found.</exception>
        /// <exception cref="EmailAddressDoesntMatchException">Throws EmailAddressDoesntMatchException when the emailaddress of the nickname isn't matching
        /// with the emailaddress specified.</exception>
        public static bool ResetPassword(string nickName, string emailAddress, string emailTemplate, Dictionary<string, string> emailData)
        {
            UserEntity user = new UserEntity();
            // fetch the user using the unique constraint fetch logic on nickname
            bool fetchResult = user.FetchUsingUCNickName(nickName);
            if(!fetchResult)
            {
                // not found
                throw new NickNameNotFoundException("Nickname: '" + nickName + "' not found");
            }

            // check emailaddress
            if(user.EmailAddress.ToLowerInvariant() != emailAddress.ToLowerInvariant())
            {
                // no match
                throw new EmailAddressDoesntMatchException("Emailaddress '" + emailAddress + "' doesn't match.");
            }

            // does match, reset the password
            string newPassword = HnDGeneralUtils.GenerateRandomPassword();

            // hash the password with an MD5 hash and store that hashed value into the database.
            user.Password = HnDGeneralUtils.CreateMD5HashedBase64String(newPassword);

            // store it
            bool result = user.Save();
            if(result)
            {
                // mail it
                result = HnDGeneralUtils.EmailPassword(newPassword, emailAddress, emailTemplate, emailData);
            }

            //done
            return result;
        }
Exemple #20
0
        /// <summary>
        /// Updates the user/forum/thread statistics after a message insert. Also makes sure if the thread isn't in a queue and the forum has a default support
        /// queue that the thread is added to that queue
        /// </summary>
        /// <param name="threadID">The thread ID.</param>
        /// <param name="userID">The user ID.</param>
        /// <param name="transactionToUse">The transaction to use.</param>
        /// <param name="postingDate">The posting date.</param>
        /// <param name="addToQueueIfRequired">if set to true, the thread will be added to the default queue of the forum the thread is in, if the forum
        /// has a default support queue and the thread isn't already in a queue.</param>
        /// <remarks>Leaves the passed in transaction open, so it doesn't commit/rollback, it just performs a set of actions inside the
        /// passed in transaction.</remarks>
        internal static void UpdateStatisticsAfterMessageInsert(int threadID, int userID, Transaction transactionToUse, DateTime postingDate, bool addToQueueIfRequired, bool subscribeToThread)
        {
            // user statistics
            UserEntity userUpdater = new UserEntity();
            // set the amountofpostings field to an expression so it will be increased with 1.
            userUpdater.Fields[(int)UserFieldIndex.AmountOfPostings].ExpressionToApply = (UserFields.AmountOfPostings + 1);
            UserCollection users = new UserCollection();
            transactionToUse.Add(users);
            users.UpdateMulti(userUpdater, (UserFields.UserID == userID));	// update directly on the DB.

            // thread statistics
            ThreadEntity threadUpdater = new ThreadEntity();
            threadUpdater.ThreadLastPostingDate = postingDate;
            threadUpdater.MarkedAsDone = false;
            ThreadCollection threads = new ThreadCollection();
            transactionToUse.Add(threads);
            threads.UpdateMulti(threadUpdater, (ThreadFields.ThreadID == threadID));

            // forum statistics. Load the forum from the DB, as we need it later on. Use a fieldcompareset predicate to fetch the forum as we don't know the
            // forumID as we haven't fetched the thread
            ForumCollection forums = new ForumCollection();
            transactionToUse.Add(forums);
            // use a fieldcompare set predicate to select the forumid based on the thread. This filter is equal to
            // WHERE ForumID == (SELECT ForumID FROM Thread WHERE ThreadID=@ThreadID)
            var forumFilter = new FieldCompareSetPredicate(
                                ForumFields.ForumID, ThreadFields.ForumID, SetOperator.Equal, (ThreadFields.ThreadID == threadID));
            forums.GetMulti(forumFilter);
            ForumEntity containingForum = null;
            if(forums.Count>0)
            {
                // forum found. There's just one.
                containingForum = forums[0];
                containingForum.ForumLastPostingDate = postingDate;
                // save the forum. Just save the collection
                forums.SaveMulti();
            }

            if(addToQueueIfRequired)
            {
                // If the thread involved isn't in a queue, place it in the default queue of the forum (if applicable)
                SupportQueueEntity containingQueue = SupportQueueGuiHelper.GetQueueOfThread(threadID, transactionToUse);
                if((containingQueue == null) && (containingForum != null) && (containingForum.DefaultSupportQueueID.HasValue))
                {
                    // not in a queue, and the forum has a default queue. Add the thread to the queue of the forum
                    SupportQueueManager.AddThreadToQueue(threadID, containingForum.DefaultSupportQueueID.Value, userID, transactionToUse);
                }
            }

            //subscribe to thread if indicated
            if(subscribeToThread)
            {
                UserManager.AddThreadToSubscriptions(threadID, userID, transactionToUse);
            }
        }
Exemple #21
0
 /// <summary> Removes the sync logic for member _setByUser</summary>
 /// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
 /// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
 private void DesetupSyncSetByUser(bool signalRelatedEntity, bool resetFKFields)
 {
     this.PerformDesetupSyncRelatedEntity( _setByUser, new PropertyChangedEventHandler( OnSetByUserPropertyChanged ), "SetByUser", SD.HnD.DAL.RelationClasses.StaticIPBanRelations.UserEntityUsingIPBanSetByUserIDStatic, true, signalRelatedEntity, "IPBansSet", resetFKFields, new int[] { (int)IPBanFieldIndex.IPBanSetByUserID } );
     _setByUser = null;
 }
Exemple #22
0
 /// <summary>
 /// Returns the user entity of the user with ID userID
 /// </summary>
 /// <param name="userID">The user ID.</param>
 /// <returns>entity with data requested or null if not found.</returns>
 public static UserEntity GetUser(int userID)
 {
     UserEntity user = new UserEntity(userID);
     if(user.IsNew)
     {
         // not found
         return null;
     }
     return user;
 }
Exemple #23
0
 /// <summary>Private CTor for deserialization</summary>
 /// <param name="info"></param>
 /// <param name="context"></param>
 protected IPBanEntityBase(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     _setByUser = (UserEntity)info.GetValue("_setByUser", typeof(UserEntity));
     if(_setByUser!=null)
     {
         _setByUser.AfterSave+=new EventHandler(OnEntityAfterSave);
     }
     _setByUserReturnsNewIfNotFound = info.GetBoolean("_setByUserReturnsNewIfNotFound");
     _alwaysFetchSetByUser = info.GetBoolean("_alwaysFetchSetByUser");
     _alreadyFetchedSetByUser = info.GetBoolean("_alreadyFetchedSetByUser");
     this.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance());
     // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
     // __LLBLGENPRO_USER_CODE_REGION_END
 }
Exemple #24
0
        /// <summary>
        /// Returns the user entity of the user with ID userID, With A UserEntityTitle prefetched.
        /// </summary>
        /// <param name="userID">The user ID.</param>
        /// <returns>entity with data requested</returns>
        public static UserEntity GetUserWithTitleDescription(int userID)
        {
            PrefetchPath prefetchPath = new PrefetchPath((int)EntityType.UserEntity);
            prefetchPath.Add(UserEntity.PrefetchPathUserTitle);

            UserEntity user = new UserEntity(userID, prefetchPath);
            if(user.IsNew)
            {
                // not found
                return null;
            }
            return user;
        }
 /// <summary> Removes the sync logic for member _placedInQueueByUser</summary>
 /// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
 /// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
 private void DesetupSyncPlacedInQueueByUser(bool signalRelatedEntity, bool resetFKFields)
 {
     this.PerformDesetupSyncRelatedEntity( _placedInQueueByUser, new PropertyChangedEventHandler( OnPlacedInQueueByUserPropertyChanged ), "PlacedInQueueByUser", SD.HnD.DAL.RelationClasses.StaticSupportQueueThreadRelations.UserEntityUsingPlacedInQueueByUserIDStatic, true, signalRelatedEntity, "SupportQueueThreadsPlaced", resetFKFields, new int[] { (int)SupportQueueThreadFieldIndex.PlacedInQueueByUserID } );
     _placedInQueueByUser = null;
 }
Exemple #26
0
 /// <summary>
 /// Checks if the given nickname is already taken. If so, true is returned, otherwise false.
 /// </summary>
 /// <param name="sNickName">NickName to check</param>
 /// <returns>true if nickname already exists in the database, false otherwise</returns>
 public static bool CheckIfNickNameExists(string nickName)
 {
     UserEntity user = new UserEntity();
     user.FetchUsingUCNickName(nickName);
     return !user.IsNew;
 }
 /// <summary> Retrieves the related entity of type 'UserEntity', using a relation of type 'n:1'</summary>
 /// <param name="forceFetch">if true, it will discard any changes currently in the currently loaded related entity and will refetch the entity from the persistent storage</param>
 /// <returns>A fetched entity of type 'UserEntity' which is related to this entity.</returns>
 public virtual UserEntity GetSinglePlacedInQueueByUser(bool forceFetch)
 {
     if( ( !_alreadyFetchedPlacedInQueueByUser || forceFetch || _alwaysFetchPlacedInQueueByUser) && !this.IsSerializing && !this.IsDeserializing  && !this.InDesignMode)
     {
         bool performLazyLoading = this.CheckIfLazyLoadingShouldOccur(Relations.UserEntityUsingPlacedInQueueByUserID);
         UserEntity newEntity = new UserEntity();
         bool fetchResult = false;
         if(performLazyLoading)
         {
             AddToTransactionIfNecessary(newEntity);
             fetchResult = newEntity.FetchUsingPK(this.PlacedInQueueByUserID);
         }
         if(fetchResult)
         {
             newEntity = (UserEntity)GetFromActiveContext(newEntity);
         }
         else
         {
             if(!_placedInQueueByUserReturnsNewIfNotFound)
             {
                 RemoveFromTransactionIfNecessary(newEntity);
                 newEntity = null;
             }
         }
         this.PlacedInQueueByUser = newEntity;
         _alreadyFetchedPlacedInQueueByUser = fetchResult;
     }
     return _placedInQueueByUser;
 }
Exemple #28
0
        /// <summary>
        /// Authenticates the user with the given Nickname and the given Password.
        /// </summary>
        /// <param name="nickName">Nickname of the user</param>
        /// <param name="password">Password of the user</param>
        /// <returns>AuthenticateResult.AllOk if the user could be authenticated, 
        ///	AuthenticateResult.WrongUsernamePassword if user couldn't be authenticated given the current credentials,
        /// AuthenticateResult.IsBanned if the user is banned. </returns>
        public static AuthenticateResult AuthenticateUser(string nickName, string password, out UserEntity user)
        {
            // fetch the Roles related to the user when fetching the user, using a prefetchPath object.
            PrefetchPath prefetchPath = new PrefetchPath((int)EntityType.UserEntity);
            prefetchPath.Add(UserEntity.PrefetchPathRoles);

            // fetch the user data using the nickname which has a unique constraint
            user = new UserEntity();
            bool fetchResult = user.FetchUsingUCNickName(nickName, prefetchPath);

            if(!fetchResult)
            {
                // not found. Simply return that the user has specified a wrong username/password combination.
                return AuthenticateResult.WrongUsernamePassword;
            }

            // user was found, check if the user can be authenticated and has specified the correct password.
            if(user.IsBanned)
            {
                // user is banned. We'll report that to the caller
                return AuthenticateResult.IsBanned;
            }
            else
            {
                // check password and UserID. We disallow the user with id 0 to login as that's the anonymous coward ID for a user not logged in.
                string md5HashedPassword = HnDGeneralUtils.CreateMD5HashedBase64String(password);
                if((md5HashedPassword == user.Password)&&(user.UserID != Globals.UserIDToDenyLogin))
                {
                    // correct username/password combination
                    return AuthenticateResult.AllOk;
                }
                else
                {
                    // something was wrong, report wrong authentication combination
                    return AuthenticateResult.WrongUsernamePassword;
                }
            }
        }