YAFLogo

benicillin
  • benicillin
  • 51.8% (Neutral)
  • YAF Forumling Topic Starter
7 years ago
I am creating users myself using the membership provider CreateUser function

I can call YAF.Classes.Data.LegacyDb.user_savenotification but i only want to change the notificationType value, and i need to be able to supply the userID. the function expects parameters userID, pmNotification, autoWatchTopics, notificationType, and dailyDigest.

1) How do I find the userID? (is this the ProviderUserKey stored in the object that is created by the CreateUser function?)

2) Can i set just the notificationType object, or do i need to also provide the pmNotiication object, autoWatchTopics object, and dailyDigest object? if so, how do i pull the values for those objects for the specified user?

Sponsor

tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 3.0.3
7 years ago
Simply check the standard yaf process in the register.ascx.cs page on how to create a user

Quote:

1) How do I find the userID? (is this the ProviderUserKey stored in the object that is created by the CreateUser function?)

No, but you can retrieve the userid via the provideruserkey

 var userId = UserMembershipHelper.GetUserIDFromProviderUserKey(PROVIDERKEY);

Quote:

2) Can i set just the notificationType object, or do i need to also provide the pmNotiication object, autoWatchTopics object, and dailyDigest object? if so, how do i pull the values for those objects for the specified user?

you need all values which you can get from the boardsettings

bool autoWatchTopicsEnabled = this.Get<YafBoardSettings>().DefaultNotificationSetting
                                              == UserNotificationSetting.TopicsIPostToOrSubscribeTo;

// save the settings...
                LegacyDb.user_savenotification(
                    userId,
                    true,
                    autoWatchTopicsEnabled,
                    this.Get<YafBoardSettings>().DefaultNotificationSetting,
                    this.Get<YafBoardSettings>().DefaultSendDigestEmail);
benicillin
  • benicillin
  • 51.8% (Neutral)
  • YAF Forumling Topic Starter
7 years ago
Thanks for the quick reply. Great project.

Just for the record, those values are stored in the yaf_User table under the field name autoWatchTopics (boolean) and NotificationType (integer)

i used the following code to set a NEW user notification settings by default to receive PM notifications by email, auto watch topics, receive notifications for topics i post or subscribe to, and NOT receive the digest.

code is VB not C#:

Dim userId As Integer = UserMembershipHelper.GetUserIDFromProviderUserKey(forumuser.ProviderUserKey)
YAF.Classes.Data.LegacyDb.user_savenotification(forumUserID, True, True, YAF.Types.Constants.UserNotificationSetting.TopicsIPostToOrSubscribeTo, False)

where forumUser is a MembershipUser object created by the membership provider's "CreateUser" function.

i added this to my createYAFUser function just after the blank profile is created - i worked off the YAFNET sample project.