|
|
Rank: Member
Joined: 4/22/2008 Posts: 23 Location: Southern US
|
I'm really impressed with the yaf forums! I had planned to make login functionality for the rest of my website similar to whats done in yaf. So I was wondering:
Q1) How can I make a custom login control that uses the yaf login/register functionality & tables to login/out of the rest of my website? (What are the general steps that would be involved?)
Q2) How can I check if the user is currently logged in to the forums from my other web pages (asp.net/C# pages). (Whats an example of the C# that could determine that?)
(Note: yaf is in a sub directory on my site)
|
|
|
 Rank: YAF MVP

Joined: 2/12/2005 Posts: 714 Location: Italy
|
On your first question, strip out the HTML from the login page (and the code) and create a user control. You can then place the control anywhere. The second one is more complex, it's been awhile since I looked at the code for login, but you need to trawl through the security classes, see which one handles the process your interested in. Hopefully, on of the other "big dog's" will pop in, point you to extactly where it is. HTH  .....the man in black fled across the desert..........and the gunslinger followed.....
|
|
|
Rank: Member
Joined: 4/22/2008 Posts: 23 Location: Southern US
|
Thanks test! I'll give it a try (and google it if/when I get stuck). If one of you "Big Dogs" wanna put in 2 cents that'll be cool with me too!  \
|
|
|
Rank: Member
Joined: 4/22/2008 Posts: 23 Location: Southern US
|
I found this example for the VS logincontrols. I'll see if i can modify that and post back if it works. Login Control coding example
|
|
|
Rank: Member
Joined: 4/22/2008 Posts: 23 Location: Southern US
|
Okay, that seems to work except... the yaf passwords seem to be encrypted (which is a bonus if I can get this to work). So how do I handle the encryption in my logincontrol?
Update: I found a post regarding this. Here was my solution: string encryptedPass = FormsAuthentication.HashPasswordForStoringInConfigFile(Password, "md5" );
Now I just need to figure out how to check if the user is logged in or not and I'm finished.
|
|
|
Rank: Member
Joined: 4/22/2008 Posts: 23 Location: Southern US
|
Okay, I've got my pages using a standard .net login control which uses the dbo.yaf_User table (and encryption) to allow users to login/out of my website successfully.
The following code determines if the user has logged in using MY login control or not: bool Authenticated = ?; e.Authenticated = Authenticated;
but theirs still a disconnect between my pages and the forum. How can I resolve that. I need my page(s) to recognize if the user had logged in on the forum and vice-versa.
Anybody know how to handle that (I'll continue to look thru the security classes as you suggested Test)?
|
|
|
 Rank: YAF MVP

Joined: 2/12/2005 Posts: 714 Location: Italy
|
Had another guy ask this question. My solution was not exactly "hi-tech", but... I created a IF...THEN...ELSE statement in the global.asx file. This checks if the user has logged in (either place), then sets a couple sesion variables. It works, but is prone to "random logouts" which I can't figure is session related or what. .....the man in black fled across the desert..........and the gunslinger followed.....
|
|
|
 Rank: YAF Forumling
Joined: 5/1/2008 Posts: 4 Location: Inside You
|
Can we customize any of the forums script like PHPBB or VBuletin by C$.NET ? I m a new to C# so a bit puzzled.
|
|
|
Rank: Member
Joined: 4/22/2008 Posts: 23 Location: Southern US
|
Thanks Test. I'll try that.
|
|
|
 Rank: YAF Forumling

Joined: 5/2/2008 Posts: 4
|
Hey chance... I'm keenly interested in this topic as well as I'd hate to have people have to login twice and keep track of two ids/passwords.
|
|
|
Rank: Member
Joined: 4/22/2008 Posts: 23 Location: Southern US
|
Well yafconvert, Theirs probably a better way to do this but I'm still learning as well. What I did was modified the FormsUser class from yaf and added a few custom properties (like IsWebAuthenticated and IsForumAuthenticated) and stored this object in session when the users log in. Like so: Code: //Set user session object FormsUser user = (FormsUser)Session["user"]; if (user == null) { user = new FormsUser(); } user.IsAuthenticated = true; user.Name = UserName.Text; user.Password = Password.Text; Session["user"] = user;
When the user logs into the web app I set "IsWebAuthenticated to true, and when they login to to forums i do the same for IsForumAuthenticated. I have a masterpage with a loginstatus control (in my web app) which checks these variables and uses a method to automatically log them into the web app if they're logged into the forums but not the web app. Code: public static bool SiteAuthentication(string UserName, string Password) { bool boolReturnValue = false; //Encrypt the password string encryptedPass = FormsAuthentication.HashPasswordForStoringInConfigFile(Password, "md5"); //Get connection string from web.config string strConnection = ConfigurationManager.ConnectionStrings["YOUR Connection String Goes here"].ConnectionString;
SqlConnection Connection = new SqlConnection(strConnection); String strSQL = "Select * From yaf_User"; SqlCommand command = new SqlCommand(strSQL, Connection); SqlDataReader Dr;
Connection.Open(); Dr = command.ExecuteReader(); while (Dr.Read()) { if ((UserName == Dr["Name"].ToString()) & (encryptedPass == Dr["Password"].ToString())) { boolReturnValue = true; break; } } Dr.Close();
return boolReturnValue; }
I still need to find where to check these variables in the forum code. I posted a question about that but never got a reply (here: Where does yaf check if your logged in?)
|
|
|
 Rank: YAF MVP

Joined: 2/12/2005 Posts: 714 Location: Italy
|
I'm not sure about your version, but mine (v1.9.2) is simple. Check the httpcontext object for the application to see if they are authenticated. Code:HttpContext.Current.User.Identity.IsAuthenticated You can force authentication by doing this.. Code:FormsAuthentication.SetAuthCookie("username", true); HTH  .....the man in black fled across the desert..........and the gunslinger followed.....
|
|
|
Rank: Member
Joined: 4/22/2008 Posts: 23 Location: Southern US
|
Oh yeah, that looks so much cleaner.
|
|
|
| Users browsing this topic |
|
Guest
|
YAFPro Theme Created by Jaben Cargman (Tiny Gecko)Powered by YAF 1.9.3 RC1 |
YAF © 2003-2008, Yet Another Forum.NETThis page was generated in 0.105 seconds.