lycanhunter
Posts: 11
|
| Posted: 04/20/2010, 6:16 AM |
|
This should be easy but yet THE BRAIN HURTS.
have simple login page. Two t ype of users residents and Admins
when an Admin logs in want to send them to one page and when a resident logs in want to send them to a different home page.
I want to grab the userType field from the user table that says whether they are admin or resident and then base the return page off that field.
This should not be as difficult as my brain is making it.
Would this be a before show or afterinitialize thing? Can I just do a simply CCGet on the userType field and then an if Else statement?
_________________
That is not dead which can eternal Lie.. |
 |
 |
saseow
Posts: 744
|
| Posted: 04/20/2010, 6:32 AM |
|
Try this:
//Add this to the BeforeShow event of the login calling page
//Redirect based on Security
if(CCGetSession("GroupID") == "1")
{
header("Location: residents_page.php");
}
else
{
header("Location:admins_page.php");
}
Hope that helps,
Trevor
|
 |
 |
lycanhunter
Posts: 11
|
| Posted: 04/20/2010, 6:42 AM |
|
have to convert php to ASP code and will give it a try. Seems almost ridiculously easy enough.
_________________
That is not dead which can eternal Lie.. |
 |
 |
lycanhunter
Posts: 11
|
| Posted: 04/20/2010, 7:34 AM |
|
Thanks saseow,
here is what I changed it to
DIM stWho
stwho = Session("GroupID")
if stWho = "2" Then
response.Redirect("admin.asp")
else
if stWho ="1" Then
response.redirect("member.asp")
End if
End if
_________________
That is not dead which can eternal Lie.. |
 |
 |
wieb
Posts: 15
|
| Posted: 05/04/2010, 6:29 AM |
|
I am new on CodeCharge Studio and try to figure out this problem for hours
Finally found it, see bellow how to solve this problem:
- find //Go to destination page @1-D0978A6F
- find these lines of code :
if($Redirect)
{
$CCSEventResult = CCGetEvent($CCSEvents, "BeforeUnload", $MainPage);
$DBiku_connection->close();
header("Location: " . $Redirect);
unset($Login);
unset($Tpl);
exit;
}
- change the above code to this:
if($Redirect)
{
$CCSEventResult = CCGetEvent($CCSEvents, "BeforeUnload", $MainPage);
$DBiku_connection->close();
if(CCGetSession("GroupID") == "1")
{
header("Location: group_1_page.php");
} else if(CCGetSession("GroupID") == "2") {
header("Location: group_2_page.php");
}
unset($Login);
unset($Tpl);
exit;
}
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 05/07/2010, 6:02 AM |
|
Hi
Not a good idea to modify standard code in the main PHP file. Doing this will make your page un-maintainable by CCS. Also, in the above example the CCS Redirect capability will be completely broken.
A better place to do this is the login on-click event.
To that select the login button on your login component. Look at the events tab you will see the event for the login click event.
Add a new action of custom code type and perform your logic making the varialble $Redirect contain the page you wish to switch to based on any login info.
Remeber to declare $Redirect as global in this code.
Hope that helps.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
wieb
Posts: 15
|
| Posted: 05/13/2010, 9:20 AM |
|
Could you please show me a simple example of custom code for login click even and redirect the users based on login info?
|
 |
 |
lycanhunter
Posts: 11
|
| Posted: 05/13/2010, 12:18 PM |
|
I went with Session variables. When an Admin user logs in There is a USer_Type variable that gets set to Admin. I look for this when I first login and then redirect to the admin page instead of the standard users page. Since this is the only page that is different it is the only page I need to check when it is called.
_________________
That is not dead which can eternal Lie.. |
 |
 |
mamboBROWN
Posts: 1713
|
| Posted: 05/13/2010, 5:44 PM |
|
lycanhunter,
If your issue has been resolved could you please add [RESOLVED] or [SOLVED] to the thread title. Thanks.
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 05/13/2010, 5:55 PM |
|
Sure
Select the login button for your login form
Add an on click event custom code
Add the following code:
if (CCGetUserID() > 0) //Check if logged in
{
global $Redirect;
//What ever logic you want:
//eg:
if(CCGetSession("GroupID","")=ADMIN) $Redirect = "MyAdminPage.php";
}
in the above example ADMIN would be a define you create to match the group IDs you have set up in your security table.
You could use the literal number if you want.
You can set $Redirect to any page you want based on any criteria you want
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
wieb
Posts: 15
|
| Posted: 05/13/2010, 8:42 PM |
|
Thank you jjrjr1, I am clear now.
I don't want to mess up CCS standard code in the main PHP file and have a headache later.
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 05/14/2010, 6:13 AM |
|
Yeah. Changing the CCS standard code will make your projects useless in the CCS Framework.
Always stay out of the "Grey" code and only make mods in white space and custom code events. In all cases it's good to stay out of the main php file.
Correction to the if statement...
if(CCGetSession("GroupID","")==ADMIN) $Redirect = "MyAdminPage.php";
The original one would always re-direct.. 
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |