Here's code I pulled together from various threads on this forum. I just got this working today. The function returns true if the login to YAF was successful. If the user doesn't exist (DBNull returned from user_login) then it automatically registers the user in the yaf database.
Code:public static bool LoginToYAF(string username, string password, string email, out string cookieUserID)
{
cookieUserID = null;
// login to the Yet Another Forum system...
string sPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "md5");
object userID = yaf.DB.user_login(1, username, sPassword);
if (userID == DBNull.Value)
{
// user doesn't exist in forum yet... let's add this user to the forum...
yaf.AdminPage yadmPage = new yaf.AdminPage();
if (yaf.DB.user_register(yadmPage, 1, username, password, email, "", "", "-300", false))
{
// must login user to get proper id for cookie...
userID = yaf.DB.user_login(1, username, sPassword);
}
else
{
// could not register...
}
}
if (userID != DBNull.Value)
{
// successful login!
// YAF cookie user ID is <userID>;<boardNum>;<username>
cookieUserID = String.Format("{0};{1};{2}", userID, 1, username); // note the hard-coded board num...
return true;
}
else
{
// problem logging into forum
return false;
}
}
One thing I'm needing help on is how can I get this forum to use my site's master page? It seems like I need to treat the forum as a virtual directory within my web site. Any ideas?
Thanks.