OnUserLoginExternal
mixed handler function( array &arParams );
The OnUserLoginExternal event is used to check user login and password in an external authorization source. Handlers of this event are called fr om within the method CUser::Login, if none of OnBeforeUserLogin event handlers returned false, before a user authorization attempt and before the login arParams['LOGIN'], and password arParams['PASSWORD'] are both verified.
Parameters
Parameter | Description |
---|---|
arParams | Array of fields to verify login and password:
|
Note This handler array of parameters and elements arParams are references to original variables. Therefore, all changes to parameters made within the handler affect values of the original variables.
Returned value
If a user must be authorized, the event handler must return ID of this user.See Also
- "OnBeforeUserLogin" event
- "OnAfterUserLogin" event
- CUser::Login
- Events
- External Authorization
Example of handler function:
<? // example of user authorization from the Innovision Power Board forum tables // 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 { public static 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 = "SEL ECT * FR OM ".$table_user." WH ERE 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; } } } public static function OnExternalAuthList() { return Array( Array("ID"=>"IPB", "NAME"=>"Invision Power Board") ); } }?>
© «Bitrix24», 2001-2023