jjrjr1
Posts: 942
|
| Posted: 02/06/2008, 5:57 AM |
|
Hi
I have been working on a large project with many challenges. As a result I have learned many new things. I would like to share those if anyone needs this functionality. CCS is a great tool and we certainly have a great community here.
I had a need to be able to create 2 logins. One would use a table and security settings to login with and the other would use a different table to log in with also using security settings.
Also I needed to go to a differnt landing screen based on a users logoin privledges.
Let me know if anyone needs this.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
Gena
Posts: 591
|
| Posted: 02/06/2008, 6:18 AM |
|
Yes, it's very interesting!
_________________
Gena |
 |
 |
waqasaltaf
Posts: 37
|
| Posted: 02/06/2008, 7:36 AM |
|
Hook us up !
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 02/07/2008, 6:22 AM |
|
Ok... Here goes.
Just to note. These code changes will allow you to have as many "psudo user" tables as you might need. The processing will use the same security groups as set for your project. so be sure ("unless you modify them on the fly") the privledge field used matches those project defined security groups.
I you really want to do some different stuff these code samples will show you how to process a login based on different data in a table. ie: go to a different result page based on login values or even go to a page that might be stored in the database for that user.
You can be creative with this based on your particular project needs.
Fisrt code modification in to the Commom.php script.
The standard login code is here (Not exactly I did make some changes to this one. But close enough for this discussion)
function CCLoginUser($login, $password)
{
global $logperm;
global $tlogin;
global $fname;
global $lname;
global $auth;
session_unset();
$logtype="0";
$db = new clsDBMobiGolf();
$SQL = "SELECT usr_id, usr_priv, usr_pw, usr_fname, usr_lname FROM mg_users WHERE usr_id=" . $db->ToSQL($login, ccsText) . " AND usr_pw=" . $db->ToSQL($password, ccsText);
$db->query($SQL);
$Result = $db->next_record();
if ($Result) {
CCSetSession("UserID", $db->f("usr_id"));
CCSetSession("UserLogin", $login);
CCSetSession("GroupID", $db->f("usr_priv"));
}
$logperm = $db->f("usr_priv");
$tlogin= $db->f("usr_id");
$fname= $db->f("usr_fname");
$lname= $db->f("usr_lname");
$auth = "Member";
if ($logperm==9){$auth="Super Administrator";}
if ($logperm==8){$auth="Administrator";}
if ($logperm==5){$auth="Professional Trainer";}
return $Result;
}
Be sure you understand what is going on here as knowing this you will see you can get any value you might need later for processing from the user table. Be sure any variable you need in your script is declared global both here and in your login page script.
Copy that block of code from Common.php and paste it directly below that function and rename it to something different. (Example below) Note: this needs to be directly below the original or for some reason during page generation CCS will delete your new function.
function CCLoginUser1($login, $password)
{
global $logperm;
global $tlogin;
global $ttype;
global $transkey;
session_unset();
$logtype="0";
$db2 = new clsDBMobiGolf();
$SQL = "SELECT vou_idkey, vou_valid, vou_transkey, vou_type FROM mg_voucher WHERE vou_idkey=" . $db2->ToSQL(trim($login), ccsText);
$db2->query($SQL);
$Result = $db2->next_record();
if ($Result) {
CCSetSession("UserID", $db2->f("vou_idkey"));
CCSetSession("UserLogin", trim($login));
CCSetSession("GroupID", $db2->f("vou_valid"));
}
$logperm = $db2->f("vou_valid");
$tlogin=$db2->f("vou_idkey");
$ttype=$db2->f("vou_type");
$transkey=$db2->f("vou_transkey");
return $Result;
}
In your new login function set the databas table you want to use, the fields you will use for the standard security processing, and get any other values you might want from your new login table. (Ensuring they are declared global.)
If all you want to do is have a different table used for login, you are basically done. Just go to the login event in your script page and replace the call to the original login function to your new name. All will work as if you had used the original user table. (You can create as many of theres as you may need.)
Now, if you want to control some processing or retrun page based on the login results, you can add this code to your login event in you login page script.
//Login @8-3C2E79F6
global $CCSLocales;
global $Redirect;
global $tlogin; // be sure any values you return from your custom login are declared global here as well
global $ttype;
global $transkey;
if ($Container->autoLogin->Value != $Container->autoLogin->CheckedValue) {
CCSetCookie("MobiGolfLogin", "");
}
// Below call your custom login fuction
if ( !CCLoginUser1( $Container->login->Value, $Container->password->Value)) {
$Container->Errors->addError($CCSLocales->GetText("CCS_LoginError1"));
$Container->password->SetValue("");
$Login_Button_DoLogin_OnClick = 0;
CCSetCookie("MobiGolfLogin", "");
} else {
global $Redirect;
// Below any custom functions based on login results
if($ttype=="1"){$Redirect= "redeemdl.php?login=".$tlogin."&tx=".$transkey;}
// end custom processing... From here on it worls like normal
if ($Container->autoLogin->Value == $Container->autoLogin->CheckedValue) {
$ALLogin = $Container->login->Value;
$ALPassword = $Container->password->Value;
CCSetALCookie($ALLogin, $ALPassword);
}
$Redirect = CCGetParam("ret_link", $Redirect);
$Login_Button_DoLogin_OnClick = 1;
}
//End Login
Let me know if that helps or you have any questions. Have fun....
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 02/07/2008, 6:32 AM |
|
A note...
The sample login event I sent is actually the original with a few changes. Do not add that entire block of gode as I incorrectly suggested. Just make the changes to the original that is commented in the code block I sent.
Sorry if that caused any confusion.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 02/07/2008, 6:50 AM |
|
Another note that might not be clear in the code is the line
$db2 = new clsDBMobiGolf();
In the Common.php file.
In this declaration $db2 needs to be a new instance of your database object in your particular project.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
|