greg_926
  •  greg_926
  • 54.8% (Neutral)
  • YAF Forumling Topic Starter
2009-09-18T03:22:16Z
Hi,

I have tried searching for this and can't seem to find it anywhere so I do apologise if this is a repost.

Could someone give me some indication on how to add users programatically to the forum with VB.NET? I have integrated the login and that works fine but I can't figure out how to add someone to the forum. What steps do I need to take?

Regards,

Greg
Sponsor
greg_926
  •  greg_926
  • 54.8% (Neutral)
  • YAF Forumling Topic Starter
2009-09-20T21:03:20Z
Has anyone got any idea on how to do this?

Surely someone has used their own forum registration page to register someone to the forum. If anyone knows how to do this, please let me know.
jshepler
2009-09-22T00:04:54Z
Yaf uses the .net membership framework - so use that. System.Web.Security.Membership.CreateUser() will create a user in the membership framework and the first time that user visits the forum, yaf will sync itself.

not jsheLPer
greg_926
  •  greg_926
  • 54.8% (Neutral)
  • YAF Forumling Topic Starter
2009-09-23T02:24:37Z
Hi,

Thanks for your post.

I couldn't get the following to work as you suggested because it always logged me into my website but not the forum. I have no idea why.

Dim memStatus As New MembershipCreateStatus
Membership.CreateUser(strUsername, strPassword, strEmail, "", "", True, memStatus)
Roles.AddUserToRole(strUsername, "registered")


But I added what I saw someone else has added to their code as follows:


Dim strHash As String = FormsAuthentication.HashPasswordForStoringInConfigFile(strPassword, "SHA1")
Dim objUserKey As Object = YAF.Providers.Profile.DB.GetProviderUserKey(strAppName, strUsername)
YAF.Providers.Membership.DB.CreateUser(strAppName, strUsername, strHash, "", 0, strEmail, "", "", True, objUserKey)
YAF.Providers.Roles.DB.AddUserToRole(strAppName, strUsername, "Registered")


The second lot of code above logs me into my site as well as the YAF forum and I can then see the new user added to the yaf_User table but the forum is empty for the user once logged in, same with the Active Discussions. If the user has been created by the forums register section then it shows everything fine.

I saw another post on here with this problem but no one responded.

Anyone else experiencing this or has any solution?
greg_926
  •  greg_926
  • 54.8% (Neutral)
  • YAF Forumling Topic Starter
2009-09-29T19:50:15Z
There HAS to be an answer to this.

Anyone who has added a new user through their code surely knows how it's done with the code examples I gave above.

Please help. I am completely lost where to go from here.
imukai
2009-10-01T06:51:35Z
I don't have my codebase in front of me, but I'll try to help you off the top of my head because I've been similarly frustrated many times. This might not help directly but might put you on the right track.

YAF uses the Role Provider, but also has its own internal notion of Groups. Each Role is also a Group inside YAF, and there's two database tables - yaf_Group, and yaf_UserGroup. The former is a list of Groups (Roles), the latter is the relationship between yaf_User and yaf_Group to handle group (role) membership. This is seperate and distinct from the Role Provider itself.

When you call the Providers.Role.AddUserToRole, it does NOT add them to the yaf_UserGroup. That would have to be done as a seperate measure. Perhaps this is a flaw in the design, I cannot say.

The reverse is also true - if you call the DB method to associate a user into yaf_UserGroup (I forget the DB call offhand that does that), then it is NOT added into the Provider Role membership.

Different parts of YAF look at different things. The admin page for the user, for example, reads and saves UserGroup based off the Provider Roles - so if you had programmatically added them to a UserGroup without adding them to the Provider, that UserGroup setting is deleted immediately upon bringing up their admin page and clicking on the tab to even view the groups.

I'd wager that logging in and looking at the forums, however, doesn't consider the Role Provider memberships - only the YAF UserGroup membership. The registration process & admin pages flag both sources when making changes so that's why a page-registered user works fine, but if you're doing it programmatically, you need to keep this duality in mind.

HTH
greg_926
  •  greg_926
  • 54.8% (Neutral)
  • YAF Forumling Topic Starter
2009-10-01T22:06:41Z
Hi,

Thank you so very much for the information. I appreciate it a lot.

So what is the answer to my problem? I understand what is going wrong now but I don't know how to fix it.

You said when I call the Providers.Role.AddUserToRole, it does NOT add them to the yaf_UserGroup. That would have to be done as a seperate measure. So what is the code to do this?
Bonescan
2009-10-15T17:05:20Z
//Login to YAF
String password = FormsAuthentication.HashPasswordForStoringInConfigFile(Login1.Password, "md5");
Object userID = DB.user_login(1, Login1.UserName, password);

if (userID == DBNull.Value)
{
string strHash = FormsAuthentication.HashPasswordForStoringInConfigFile(Login1.Password, "md5");
object objUserKey = YAF.Providers.Profile.DB.GetProviderUserKey("xxxx", Login1.UserName);
YAF.Providers.Membership.DB.CreateUser("xxxx", Login1.UserName, strHash, "", 0, currentUser.Email1, "", "", true, objUserKey);
YAF.Providers.Roles.DB.AddUserToRole("xxxx", Login1.UserName, "Registered");
objUserKey = YAF.Providers.Profile.DB.GetProviderUserKey("xxxx", Login1.UserName);
userID = YAF.Classes.Data.DB.user_aspnet(1, Login1.UserName, currentUser.Email1, objUserKey, true);

foreach (string role in Roles.GetRolesForUser(Login1.UserName))
{
YAF.Classes.Data.DB.user_setrole(1, objUserKey, role);
}
}

string idName = string.Format("{0};{1};{2}", userID, 1, Login1.UserName);
FormsAuthentication.SetAuthCookie(idName, Login1.RememberMeSet);
bbobb
  •  bbobb
  • 100% (Exalted)
  • YAF Developer
2009-10-15T17:33:35Z
If you compile YAF from svn in debug mode, you'll see option Generate Test Data in Database section. It contains all the simple logic to add users to Registered group and Newbie Rank.
JamesM
  •  JamesM
  • 50.6% (Neutral)
  • YAF Forumling
2009-10-22T11:41:54Z
Hi,

I'm busy integrating YAF into a site. Using Bonescan's suggestions I'm able to log in a user if they already exist and create a new user if they don't.

The problem I'm having is that yaf_user_aspnet creates a user with password '-' and next time they try and log in yaf_user_login doesn't recognize the user. How should I set the password?

I'm using version 1.9.3.

Thanks



Anthony Smith
2014-12-05T18:07:49Z
Hi. I am an Admin at http://coupon-codes-bonus-codes.com 
We are using YAF 2.1.1 | YAF © 2003-2014, Yet Another Forum.NET
Maybe this feature was not available in older versions of YAF being that the question was asked 5 years ago.

How to simply create and new add users on a YAF Site.

Go to Admin area of your YAF Site and Click on Users and Roles. Then Click Users.
Coupon Codes - Bonus Codes » Administration » Users
http://lite-report.com/Lite-Report_News/images/Create-New-User.jpg
Click to View Full Size 



Then at the Bottom, Click New User Button.
It should Navigate you to the Create New User Page.
http://lite-report.com/Lite-Report_News/images/Create-New-User-2.jpg
Click to View Full Size 

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