louis
  •  louis
  • 50.2% (Neutral)
  • YAF Forumling Topic Starter
2012-12-04T11:13:40Z
Hi,

I'm new to Yaf and trying to create a user without using the form Register form. So, going through the Yaf classes to create a user in the database. Is this possible? Does the functionality even exist?

Thanks
Sponsor
tha_watcha
2012-12-05T09:53:25Z
Yes of course its possible just look at the register.ascx.cs page how its done


MembershipCreateStatus status;

var pass = "Password"// Membership.GeneratePassword(32, 16);
var securityQuestion = "Security Question";
var securityAnswer = "Security Answer";
var userName = "UserName";

MembershipUser user = YafContext.Current.Get<MembershipProvider>().CreateUser(
                            userName, pass, email, securityQuestion, securityAnswer, 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);

// Set profile properties?!
userProfile.Homepage = "http://www.test.com";

// setup their inital profile information
 userProfile.Save();

if (YafContext.Current.Get<YafBoardSettings>().NotificationOnUserRegisterEmailList.IsSet())
{
// send user register notification to the following admin users...
SendRegistrationNotificationEmail(user);
}

// save the time zone...
 int userId = UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey);

 LegacyDb.user_save(
                            userId,
                            YafContext.Current.PageBoardID,
                           UserName,
                            null,
                            email,
                            0,
                            null,
                            null,
                            null,
                            true,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null);

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

                        // save the settings...
LegacyDb.user_savenotification(
                            userId,
                            true,
                            autoWatchTopicsEnabled,
                            YafContext.Current.Get<YafBoardSettings>().DefaultNotificationSetting,
                            YafContext.Current.Get<YafBoardSettings>().DefaultSendDigestEmail);

UserPostedImage

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