Welcome Guest Search | Active Topics | Log In | Register

Register user automatically Options · View
sidrp
#1 Posted : Friday, February 16, 2007 10:19:10 PM

Rank: YAF Forumling


Joined: 2/16/2007
Posts: 2
I just moved over from a paid Forum to this because of lack of support/documentation. After reading a few posts I was able to integrate YAF with my site in less than 2-3 hours. Thanks..I still have one small issue I need resolved.
Heres what I am doing...
1. I have a up and running ASP.Net 2.0 web application.
2. I create the YAF as a subfolder and copied all the config and database settings correctly.
3. I want to be able to log a user in automatically from the ASP.net site to YAF.
4. I was able to do this with a user who I registered manually.
5. How do I register a user using Code who is not in the YAF database?
I am pretty sure there is a method out there which I am missing.
heres my code for others to review:

Dim user As BusinessLogicLayer.UserBO = GetLoggedInUser()

Dim sPassword As String = user.Password
Dim userName As String = user.Username

Dim userID As Object = yaf.DB.user_login(1, userName, sPassword)

Dim idName As String = String.Format("{0};{1};{2}", userID, 1, userName)

If Not userID Is DBNull.Value Then


If (Request.QueryString("ReturnUrl"Wink <> Nothing) Then
FormsAuthentication.RedirectFromLoginPage(idName, True)
Else
FormsAuthentication.SetAuthCookie(idName, True)
'yaf.Forum.
Response.Write("authen"Wink
Response.Redirect("../DiscussionForum/Default.aspx"Wink
End If
Else

End If

What method do I call to register a user who doesnt have an account in YAF?
thanks a million for a wonderful app..
Sid
nanott
#2 Posted : Sunday, February 18, 2007 5:51:25 AM

Rank: YAF Forumling


Joined: 2/18/2007
Posts: 1
Location: USA
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.
sidrp
#3 Posted : Monday, February 19, 2007 5:04:26 PM

Rank: YAF Forumling


Joined: 2/16/2007
Posts: 2
Thanks for your reply..I will try it today...To integrate the forum into my website, just created another folder and pulle din all the source code and recompiled...I too, will need to redesign the master page, but since we get the code, it should just be a matter to changing the Masterpage to look like your site.
HTH
Sid
Users browsing this topic
Guest
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.

YAFPro Theme Created by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.3 RC2 | YAF © 2003-2008, Yet Another Forum.NET
This page was generated in 0.104 seconds.

SourceForge.net Logo Powered by ASP.NET v2.0 411ASP.NET