YAFLogo

abhijeet
  • abhijeet
  • 51.2% (Neutral)
  • YAF Forumling Topic Starter
12 years ago
Hey I'm new to YAF!!!

In my website I have my own login & registration modules.And i'm not using ASP.net membership.

I want to integrate YAF into my website.

As far as I know YAF requires ASP.net membership,googled alot :?: ,but unable to figure out how to achieve my login & registraion for YAF???

Thanks in advance!!!


Abhijeet Gupta

www.addya.in

Sponsor
abhijeet
  • abhijeet
  • 51.2% (Neutral)
  • YAF Forumling Topic Starter
12 years ago
Solved my issue!!

I followed steps from:

YAF With Existing Website Running On asp.net 4.0 

And added following code into my sign up code:

private void CreateUser(String sApplicationName, String sUserName, String sPassword, String sEmail)

{

YafMembershipProvider mb = (YafMembershipProvider)System.Web.Security.Membership.Providers["YafMembershipProvider"];

int? forumUserID = 0;

if (!mb.ValidateUser(sUserName, sPassword))

{

MembershipCreateStatus status;

MembershipUser forumUser = mb.CreateUser(sUserName, sUserName, sUserName, "question", "answer", true, null, out status);

// create the user in the YAF DB as well as sync roles...

forumUserID = RoleMembershipHelper.CreateForumUser(forumUser, 1);

RoleMembershipHelper.SetupUserRoles(1, sUserName);

RoleMembershipHelper.AddUserToRole(sUserName, "Registered");

// create empty profile just so they have one

YafUserProfile userProfile = YafUserProfile.GetProfile(sUserName);

userProfile.Homepage = "fwd.com";

// setup their inital profile information

userProfile.Save();

}

else

{

DataTable results =(DataTable) YAF.Classes.Data.DB.UserFind(1, false, sUserName, sUserName, sUserName, null, null);

//DataTable results = YAF.Classes.Data.DB.UserFind(1, false, sUserName, sUserName);

if (results.Rows.Count > 0)

{

forumUserID = (int)results.Rows[0]["UserID"];

}

}

FormsAuthentication.SetAuthCookie(sUserName, false);

}


Abhijeet Gupta

www.addya.in

ankit
  • ankit
  • 50.2% (Neutral)
  • YAF Camper
11 years ago
Hi,

I have the same problem, link of my topic is here:

http://forum.yetanotherforum.net/yaf_postst15023_How-to-integrate-YAF-with-existing-website.aspx 

I want to use YAF with scenario explained here:

--> I am using YAF as a forum and I have implemented it in my project in a sub-folder named "Forum" so all files and folder of folder "YetAnotherForum.NET" is included in that sub-folder and changes according to webconfig is also done.

--> So now I have not used membership control in my website and so if a user logged in to my website and he is clicking forum link then he must be able to access YAF without login and he does not have to login again at YAF and should be able to post topics because he has logged in to my existing website.

--> Is it possible to do it with the code you have provided here?

abhijeet
  • abhijeet
  • 51.2% (Neutral)
  • YAF Forumling Topic Starter
11 years ago
yeah it works.

when a user logs in your website set the Auth cookies.

i.e. : FormsAuthentication.SetAuthCookie(sUserName, false);


Abhijeet Gupta

www.addya.in

ankit
  • ankit
  • 50.2% (Neutral)
  • YAF Camper
11 years ago
Hi,

Thanks. And yes I am doing the same. After setting values in my session variables I am using you code i.e. FormsAuthentication.SetAuthCookie(sUserName, false); to set values for YAF and it working perfectly if I am operatin my website with VisualStudio but when I am publishing my website and trying to use it thorough localhost that thing does't work.

Can you help me out for this problem. Have you tried this after publish website to live url? Can you give me URL link for that website.

Thanks for reply.

sinachi
  • sinachi
  • 50.2% (Neutral)
  • YAF Forumling
11 years ago
when a user logs in your website set the Auth cookies.
SamsonAtYAF
11 years ago
Question, I'm trying to do this right now .... But I am confused! Do you put that code in the LOGIN or REGISTER ACCOUNT section. Or in both.

I'm a bit confused now doing a CREATE on LOGIN would work.

Please let me know what I can do at LOGIN!

Second question, You dont seem to actually pass the password value to CREATEUSER. I'm also a bit confused by that?

abhijeet
  • abhijeet
  • 51.2% (Neutral)
  • YAF Forumling Topic Starter
10 years ago
Hi Samson

I called CreateUser(.....) method ,in my User Registration Code.

And set the Authentication cookies for the user ;after registration of user so that he can use the forum straightaway,which is the last line i.e. : FormsAuthentication.SetAuthCookie(sUserName, false);

Put the above code in your login code after processing login credential.

Answer for your second question is: as we're not using the Login/Register module of YAF;I disabled the login and registration page of YAF;it was just the formality to pass password while creating User,hence I passed the sUserName for forum.


Abhijeet Gupta

www.addya.in