Demigod
  •  Demigod
  • 95.60001% (Exalted)
  • YAF Commander Topic Starter
2008-02-09T07:21:14Z
My forum currently uses v1.9.1 and I've integrated the security into my own website. I'm working on a huge redesign of the website and want to roll it out with v1.9.3+ but I'm having troubles following the logic when users login.

Exactly which page or method is called when the user clicks "Forum Login"?

Where is the cookie layed down?

I want to recreate the login page so it looks like part of the site, not just part of the forum. In 1.9.1 I just used the user_login method, populated a bunch of session variables, and set the cookie with ForumsAuthentication.

I've searched through the entire source of the current alpha and just can't find what I am looking for.
Sponsor
Jaben
  •  Jaben
  • 100% (Exalted)
  • YAF Developer
2008-02-10T15:04:04Z
v1.9.3 uses ASP.NET membership, roles, and profiles.

Login is handled BY ASP.NET using a provider defined by you. For instance, you can tell YAF to use the Active Directory provider and "logging in" will be handled by this provider in it's unique way. YAF has it's own custom providers as well which are used for backwards compatiblity with v1.9.1.x and below. Without these providers you will not be able to upgrade an existing YAF configuration.

Giving you want Active Directory -- v1.9.3 is probably the way to go.

You can also do a search for "ASP.NET Membership Providers" for more details.
Demigod
  •  Demigod
  • 95.60001% (Exalted)
  • YAF Commander Topic Starter
2008-02-10T17:45:47Z
I wasn't looking for AD.. I was just looking for a method where all of the actual logging in was done so I could add a few other session variables from the user object to the session so my other pages can use them.

Gave up looking and went with a different approach. My site uses 3 different Master pages and in the Page_Init on each of them I test to see if "someone" is logged in.. and if so, grab what I need and populate the session vars. Is there a better way to accomplish the following code?

        protected void Page_Init(object sender, EventArgs e)
        {
            if (HttpContext.Current.User != null && Session["UserName"].ToString() == "")
            {
                if (HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    if (HttpContext.Current.User.Identity is FormsIdentity)
                    {
                        string Username = HttpContext.Current.User.Identity.Name;
                        string SQLConnection = ConfigurationManager.AppSettings["MySQL-String"];
                        string SQL = "SELECT u.Name, u.UserID, u.Level, u.ProviderUserKey FROM yaf_User u " +
                              "WHERE u.Name = '" + Username + "'";
                        System.Data.DataTable UserInfo = Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset(SQLConnection, System.Data.CommandType.Text, SQL).Tables[0];
                        Session["UserID"] = UserInfo.Rows[0]["UserID"].ToString();
                        Session["Level"] = UserInfo.Rows[0]["Level"].ToString();
                        Session["UserName"] = UserInfo.Rows[0]["Name"].ToString();
                        Session["Chatter"] = new Chatter(new Guid(UserInfo.Rows[0]["ProviderUserKey"].ToString()), Session["UserName"].ToString());
                    }
                }
            }
        }
Jaben
  •  Jaben
  • 100% (Exalted)
  • YAF Developer
2008-02-11T13:02:21Z
Just use Membership, Demigod:

MembershipUser u = Membership.GetUser(HttpContext.Current.User.Identity.Name);
if (u != null)
{
  // do some work
}

Demigod
  •  Demigod
  • 95.60001% (Exalted)
  • YAF Commander Topic Starter
2011-02-21T04:31:11Z
Originally Posted by: Jaben 

Just use Membership, Demigod:


MembershipUser u = Membership.GetUser(HttpContext.Current.User.Identity.Name);
if (u != null)
{
  // do some work
}



3 years later.. I still have questions on this.

Now that I have actually upgraded to 1.9.5 I need to make this work. The User object you create there just doesn't contain any of the users info that I need.... like UserID. That's really the only useful item I need and every time I renovate my website I come back to this problem again.

UserID is not part of that object. So... is there another way to access UserID, or is there a way for me to ADD UserID to that object? Just throw me a bone... I can handle the work.
Demigod
  •  Demigod
  • 95.60001% (Exalted)
  • YAF Commander Topic Starter
2011-02-21T07:56:31Z
Figured out a much easier way of dealing with this.

I added this to my code:


using YAF.Classes.Core;


And then this when I need to know the UserID of the user in question:


int UserID = YafContext.Current.PageUserID;


If they're not logged in, it is 1. Else, they're logged in... then I can deal with whatever it was I needed to do.

Jaben
  •  Jaben
  • 100% (Exalted)
  • YAF Developer
2011-02-22T01:38:32Z
If you needed the ID for any userName, you can use this:


var UserId = UserMembershipHelper.GetUserIDFromProviderUserKey(Membership.GetUser(userNameToLookup).ProviderUserKey);

Demigod
  •  Demigod
  • 95.60001% (Exalted)
  • YAF Commander Topic Starter
2011-02-22T03:46:56Z
Excellent stuff Jaben. Thanks.

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