mixed event_handler( array &arParams );
The OnUserLoginExternal event is used to check user login and password in an external authorization source. Handlers of this event are called from within the method CUser::Login if none of the OnBegoreUserLogin handlers return false, before a user authorization attempt and before the login arParams['LOGIN'] and password arParams['PASSWORD'] are both verified.
Parameter | Description |
---|---|
arParams | Array of fields used for user login and password verification, the following keys available:
|
Note
All parameters passed to this handler function and the arParams array are references to original variables. Therefore, all changes to parameters made within the handler affect values of the
original variables.
<? // example of user authorization // based on tables of Innovision Power Board // file /bitrix/php_interface/init.php AddEventHandler("main", "OnUserLoginExternal", Array("__IPBAuth", "OnUserLoginExternal")); AddEventHandler("main", "OnExternalAuthList", Array("__IPBAuth", "OnExternalAuthList")); define("IPB_TABLE_PREFIX", "ibf_"); define("IPB_VERSION", "2"); class __IPBAuth { function OnUserLoginExternal(&$arArgs) { $groups_map = Array( /*'IPB Group ID' => 'Local Group ID',*/ '4' => '1' ); $table_user = IPB_TABLE_PREFIX."members"; $table_converge = IPB_TABLE_PREFIX."members_converge"; global $DB, $USER, $APPLICATION; extract($arArgs); if(IPB_VERSION == '1') { $strSql = "SELECT * FROM ".$table_user. " WHERE name='".$DB->ForSql($LOGIN). "' AND password='".md5($PASSWORD)."'"; } else { $strSql = "SELECT t1.* ". "FROM ".$table_user." t1, ".$table_converge." t2 ". "WHERE t1.name='".$DB->ForSql($LOGIN)."' ". " AND t1.email = t2.converge_email ". " AND t2.converge_pass_hash = MD5(CONCAT(MD5(t2.converge_pass_salt), '".md5($PASSWORD)."'))"; } $dbAuthRes = $DB->Query($strSql); if($arAuthRes = $dbAuthRes->Fetch()) { $arFields = Array( "LOGIN" => $LOGIN, "NAME" => $arAuthRes['title'], "PASSWORD" => $PASSWORD, "EMAIL" => $arAuthRes['email'], "ACTIVE" => "Y", "EXTERNAL_AUTH_ID"=>"IPB", "LID" => SITE_ID ); $oUser = new CUser; $res = CUser::GetList($O, $B, Array("LOGIN_EQUAL_EXACT"=>$LOGIN, "EXTERNAL_AUTH_ID"=>"IPB")); if(!($ar_res = $res->Fetch())) $ID = $oUser->Add($arFields); else { $ID = $ar_res["ID"]; $oUser->Update($ID, $arFields); } if($ID>0) { $USER->SetParam("IPB_USER_ID", $arAuthRes['id']); $user_group = $arAuthRes['mgroup']; $arUserGroups = CUser::GetUserGroup($ID); foreach($groups_map as $ext_group_id => $group_id) { if($ext_group_id==$user_group) $arUserGroups[] = $group_id; else { $arUserGroupsTmp = Array(); foreach($arUserGroups as $grid) if($grid != $group_id) $arUserGroupsTmp[] = $grid; $arUserGroups = $arUserGroupsTmp; } } CUser::SetUserGroup($ID, $arUserGroups); $arParams["STORE_PASSWORD"] = "N"; return $ID; } } } function OnExternalAuthList() { return Array( Array("ID"=>"IPB", "NAME"=>"Invision Power Board") ); } } ?>
© 2001-2005 Bitrix | Bitrix Site Manager - Content Management & Portal Solutions |