Welcome Guest! To enable all features please Login or Register.
Options
View
Go to last post Go to first unread
Offline BBQTom  
#1 Posted : Tuesday, August 15, 2017 2:16:03 PM(UTC)
BBQTom


Rank: YAF Forumling

Reputation:

Joined: 9/29/2016(UTC)
Posts: 2
Location: Milton

Thanks: 1 times
Hello,

I normally code in C#

I have a website that has it's own user database, not using the ASP.NET Membership provider. In fact, this website doesn't have any log in at all, but user details are stored when people register for the organization.

So, I have a database with email addresses and names and I want to add these users to the YAF user database and assign a password for them.

My thought is that my program would run every day and automatically add any users who have registered on the original site and send them an email with their password.

I have added the connectionStrings and system.web sections to my app.config exactly as they are in the YAF configs.

I have also added the YAF.dll to my references.

I can run YAF.Providers.Membership.DB.Current.CreateUser("YetAnotherForum", "TestUser", FormsAuthentication.HashPasswordForStoringInConfigFile("TestPassword!", "SHA1"Wink, "", 0, "test@email.com", "", "", true, YAF.Providers.Profile.DB.Current.GetProviderUserKey("YetAnotherForum", "TestUser"Wink);

I get no errrors, but the user does not appear in the YAF database or Admin panel.

If you could offer any help on what I am missing or doing wrong I would appreciate it.

Thanks in advance!
Sponsor
Offline tha_watcha  
#2 Posted : Thursday, August 17, 2017 1:50:04 AM(UTC)
tha_watcha


Rank: YAF.NET Project Lead

Reputation:

Medals: Medal of Honor: Portal Puzzle Master: Portal Puzzle Master for DNNMedal of Honor Key: Given to pillars of the community who are key players in the YAF community and project.DNN Master: DNN Module ManBug Killer Medal of Honor: Medal for being a kick-ass bug killer!Medal of Honor for the Support King: Support King! Amazing asset to the YAF.NET Community.

Joined: 3/6/2010(UTC)
Posts: 3,736
Germany

Thanks: 70 times
Was thanked: 1149 time(s) in 979 post(s)
Here is the full code to register a user and send the user an email

Code:
 MembershipCreateStatus status;

            var pass = Membership.GeneratePassword(32, 16);
            var securityAnswer = Membership.GeneratePassword(64, 30);
            var securityQuestion = "Answer is a generated Pass";

            var user = YafContext.Current.Get<MembershipProvider>().CreateUser(
               "username",
                pass,
                "user@email.com",
                this.Get<MembershipProvider>().RequiresQuestionAndAnswer ? securityQuestion : null,
                this.Get<MembershipProvider>().RequiresQuestionAndAnswer ? securityAnswer : null,
                true,
                null,
                out status);

            // setup inital roles (if any) for this user
            RoleMembershipHelper.SetupUserRoles(YafContext.Current.PageBoardID, "username");

            // create the user in the YAF DB as well as sync roles...
            int? userID = RoleMembershipHelper.CreateForumUser(user, YafContext.Current.PageBoardID);

            // create empty profile just so they have one
            YafUserProfile userProfile = YafUserProfile.GetProfile( "username");

            userProfile.Save();

            // send user register notification to the new users
            this.Get<ISendNotification>().SendRegistrationNotificationToUser(
                user, pass, securityAnswer, "NOTIFICATION_ON_REGISTER");

            LegacyDb.user_save(
                userId,
                YafContext.Current.PageBoardID,
                "username",
                "username",
                "username@email.com",
               0,
                null,
                null,
                true,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null);

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

            // save the settings...
            LegacyDb.user_savenotification(
                userId,
                true,
                autoWatchTopicsEnabled,
                this.Get<YafBoardSettings>().DefaultNotificationSetting,
                this.Get<YafBoardSettings>().DefaultSendDigestEmail);
thanks 1 user thanked tha_watcha for this useful post.
BBQTom on 8/17/2017(UTC)
Rss Feed  Atom Feed
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Notification

Icon
Error