BBQTom
  • Posts: 2
  • Joined: 29/09/2016
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"), "", 0, "test@email.com", "", "", true, YAF.Providers.Profile.DB.Current.GetProviderUserKey("YetAnotherForum", "TestUser"));

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!
tha_watcha
  • Posts: 4037
  • Joined: 06/03/2010
Here is the full code to register a user and send the user an email

 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);

UserPostedImage
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.

About Us

The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

Powered by Resharper Donate with PayPal button

Project Twitter Updates

Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved