A number of people have asked if there is a way to redirect users to a different page after they login ... essentially using Expression Engine as the front end to a Secure Extranet.
The answer is yes ... if you are willing to insert some PHP code at the top of each page and follow some naming conventions.
It’s not too hard to do at all - but can get rather involved if you want to continue to use the global variables from page to page.
Here’s how to do it. Links take you off the Wiki and to my site ... use the back button on your browser to return here. A complete version of this entry is available here:
http://www.firewhite.com/weblog/secure_extranet_redux
This example
Assumes we are going to set up 3 different membership groups for Client Alpha, Client Beta, and Client Gamma.
The code assumes that weblogs, membership groups, and templates groups are all named approximately the same thing. (alpha, beta, and gamma)
Step by Step Process
Step 1. Set up Extranet Templates
Create a set of templates you want to use to standardize presentation of content across membership groups. House those templates in a template group we’ll call “Extranet”. Each template in this group should be available ONLY to members who are logged in. You’ll want to use the {if logged_in} tag to make this so. To customize the template for each membership group, use the variables {mystart_blog} on the index and start pages and {segment_1} elsewhere.
You can populate this template group with as many or as few templates (pages) as you like. At a minimum you should create these templates:
http://www.firewhite.com/collateral/extranet_index.txt - extranet/index
Required. Container for all entries on the Secure Extranet.
http://www.firewhite.com/collateral/extranet_start.txt - extranet/start
Required. Creates customized start page based on membership group.
http://www.firewhite.com/collateral/extranet_header.txt - extranet/header
Recommended. Provides a mechanism for inserting code fragment (Fragment One - see below) that is required on the top of each page of extranet.
Step 2. Set up Login Templates
Create a group called Login. Only two templates are required and one is strongly recommended:
http://www.firewhite.com/collateral/login_index.txt - login/index
Required. Handles external logins from end users who do not need to go through control panel.
http://www.firewhite.com/collateral/login_start.txt - login/start
Required. Handles redirects based on membership group.
http://www.firewhite.com/collateral/login_form.txt - login form
Recommended. Login form used on login/index page and elsewhere.
Step 3
Create the above membership groups and template groups for Alpha, Beta, Gamma as you would normally.
Make sure each template in the group starts with the first code block as discussed below. A fast way to ensure this happens is to establish a template called extranet/header, and simply embed this template at the top of each template.
Step 4
Go to the templates groups you just created and select preferences. You’ll want to do this for the template groups Alpha, Beta, Gamma and for Extranet and Login. For each template in the group, select allow PHP = “yes” and PHP Parsing Stage = “input”. See this http://www.firewhite.com/weblog/hint for how to do this more quickly.
Step 5
Go to the template group “Alpha” and select the first template listed and click on the link marked Access. Say “yes” to give members of the group “Beta” access to templates in this group and “no” to all other groups listed. Repeat this process for all templates in the group.
Repeat this process for templates in the groups “Beta” and Gamma”, and their respective groups.
Step 6
Test your code. Create a dummy member of the group Alpha and login as that member. You should be directed to a login page that has been customized just for members of Alpha group. Check to see if you can access pages intended for group Beta or Gamma. You should not be able to access any pages intended for group Beta or Gamma. Logout. Check that when logged out you cannot see any of the start pages for Alpha, Beta, Gamma.
Step 7
Test and debug. You are done!
List of Templates
http://www.firewhite.com/collateral/extranet_index.txt - extranet/index
http://www.firewhite.com/collateral/extranet_start.txt - extranet/start
http://www.firewhite.com/collateral/extranet_header.txt - extranet/header
http://www.firewhite.com/collateral/login_index.txt - login/index
http://www.firewhite.com/collateral/login_start.txt - login/start
http://www.firewhite.com/collateral/login_form.txt - login/form
Code Fragments
http://www.firewhite.com/collateral/fragment_one.txt
Used at the very top of extranet/header, where extranet/header is the first thing called at the top of every page on the Secure Extranet
http://www.firewhite.com/collateral/fragment_two.txt
Makes up the entirety of login/start
