I have an existing site with many users. I wanted to integrate YAF with my main site but the issue is creating accounts with the correct passwords for each user (the passwords are encrypted so I do not know what they are). Plus I did not want to have YAF as a sub folder of my main site as the integration document recommended.
It took about 3 hours to make the code changes. The core of this is sharing cookies across domains... www.mysite.com and forums.mysite.com. This requires that the YAF login page is disabled so that users always log into the main site.
Here is the flow...
-----------------
I. Main Site
-----------------
1. User logs into the main site and they are directed to the YAF forum.
2. I check a table in my database to check if the user has a YAF account. I could have checked YAF DB but I know my database so it was easier.
3. No YAF account?
- Insert the user into my table in #2.
- Create a password (the user does not need to know the YAF password)
- Call the yaf.DB create user method.
- Create a cookie that is shared across domains. Place the user id and password in the cookie (encrypted).
4. YAF Account Exists?
- Create the cookie as discussed above. I do this in a base class inherited by the master page in the site.
----------------
II. YAF
----------------
1. User clicks on the forum link on the main web site.
2. User now on the YAF forum
3. In the YAF BaseControl.cs get the cookie value.
4. Decrypt the user id and password (I have a DLL I wrote for this).
5. Log the user into YAF using the yaf.DB.user_login method.
6. That is it... integration completed.
Couple of side notes....
1. You could use the same password for all users in YAF. This is the case since they log into the main site and they never know the YAF password. If you take down the YAF login page there should be no security risk.
2. In the main site I check if(IsAuthenticated) and if the cookie is null, I go ahead and create the cookie again. This should not happen, but...
3. In YAF as a measure of comfort I check if the user (is NOT IsAuthenticated) and the cookie exists, I then log them back into YAF.
I have tested this with 4 accounts and it works like a charm.
Regards,
Patrick
SURFThru
Edited by user
16 years ago |
Reason: Not specified