/** * Called from fetchData after successful login. * * @param string username */ public function loginObserver($a_username, $a_auth) { $usr_id = ilObjUser::_lookupId($a_username); $auth_mode = ilObjUser::_lookupAuthMode($usr_id); $auth_id = ilAuthUtils::_getAuthMode($auth_mode); $GLOBALS['ilLog']->write(__METHOD__ . ': auth id = ' . $auth_id); switch ($auth_id) { case AUTH_LOCAL: return true; default: if (ilAuthUtils::isPasswordModificationEnabled($auth_id)) { return true; } } $a_auth->status = AUTH_WRONG_LOGIN; $a_auth->logout(); return false; }
/** * Handle an event in a listener. * * @param string $a_component component, e.g. "Modules/Forum" or "Services/User" * @param string $a_event event e.g. "createUser", "updateUser", "deleteUser", ... * @param array $a_parameter parameter array (assoc), array("name" => ..., "phone_office" => ...) */ static function handleEvent($a_component, $a_event, $a_parameter) { global $ilLog; $ilLog->write(__METHOD__ . ': Listening to event from: ' . $a_component); switch ($a_component) { case 'Services/User': switch ($a_event) { case 'afterCreation': $user = $a_parameter['user_obj']; $this->handleMembership($user); break; } break; case 'Modules/Course': switch ($a_event) { case 'addSubscriber': case 'addParticipant': if (ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs') { if (!($user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id']))) { $GLOBALS['ilLog']->write(__METHOD__ . ': No valid user found for usr_id ' . $a_parameter['usr_id']); return true; } include_once './Services/WebServices/ECS/classes/class.ilECSImport.php'; $server_id = ilECSImport::lookupServerId($a_parameter['usr_id']); $GLOBALS['ilLog']->write(__METHOD__ . ': Found server id: ' . $server_id); include_once 'Services/WebServices/ECS/classes/class.ilECSSetting.php'; $settings = ilECSSetting::getInstanceByServerId($server_id); $end = new ilDateTime(time(), IL_CAL_UNIX); $end->increment(IL_CAL_MONTH, $settings->getDuration()); if ($user->getTimeLimitUntil() < $end->get(IL_CAL_UNIX)) { $user->setTimeLimitUntil($end->get(IL_CAL_UNIX)); $user->update(); } self::_sendNotification($settings, $user); unset($user); } break; } break; } }
/** * Auth and email related methods * @group IL_Init */ public function testAuthAndEmailMethods() { include_once "./Services/User/classes/class.ilObjUser.php"; $value = ""; // creation $user = new ilObjUser(); $d = array("login" => "aatestuser2", "passwd_type" => IL_PASSWD_PLAIN, "passwd" => "password", "gender" => "f", "firstname" => "Heidi", "lastname" => "Kabel", "email" => "*****@*****.**", "ext_account" => "ext_"); $user->assignData($d); $user->setActive(true); $user->create(); $user->saveAsNew(); $user->setLanguage("de"); $user->writePrefs(); $id = $user->getId(); ilObjUser::_writeExternalAccount($id, "ext_kabel"); ilObjUser::_writeAuthMode($id, "cas"); $ids = ilObjUser::_getUserIdsByEmail("*****@*****.**"); //var_dump($ids); if (is_array($ids) && count($ids) == 1 && $ids[0] == "aatestuser2") { $value .= "email1-"; } $uid = ilObjUser::getUserIdByEmail("*****@*****.**"); if ($uid == $id) { $value .= "email2-"; } $acc = ilObjUser::_getExternalAccountsByAuthMode("cas"); foreach ($acc as $k => $v) { if ($k == $id && $v == "ext_kabel") { $value .= "auth1-"; } } if (ilObjUser::_lookupAuthMode($id) == "cas") { $value .= "auth2-"; } if (ilObjUser::_checkExternalAuthAccount("cas", "ext_kabel") == "aatestuser2") { $value .= "auth3-"; } if (ilObjUser::_externalAccountExists("ext_kabel", "cas")) { $value .= "auth4-"; } ilObjUser::_getNumberOfUsersPerAuthMode(); $la = ilObjUser::_getLocalAccountsForEmail("*****@*****.**"); ilObjUser::_incrementLoginAttempts($id); ilObjUser::_getLoginAttempts($id); ilObjUser::_resetLoginAttempts($id); ilObjUser::_setUserInactive($id); // deletion $user->delete(); $this->assertEquals("email1-email2-auth1-auth2-auth3-auth4-", $value); }
/** * Handle an event in a listener. * * @param string $a_component component, e.g. "Modules/Forum" or "Services/User" * @param string $a_event event e.g. "createUser", "updateUser", "deleteUser", ... * @param array $a_parameter parameter array (assoc), array("name" => ..., "phone_office" => ...) */ static function handleEvent($a_component, $a_event, $a_parameter) { global $ilLog; $ilLog->write(__METHOD__ . ': Listening to event from: ' . $a_component . ' ' . $a_event); switch ($a_component) { case 'Services/User': switch ($a_event) { case 'afterCreate': $user = $a_parameter['user_obj']; self::handleMembership($user); break; } break; case 'Modules/Group': $GLOBALS['ilLog']->write(__METHOD__ . ': New event from group: ' . $a_event); switch ($a_event) { case 'addSubscriber': case 'addToWaitingList': if (ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs') { if (!($user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id']))) { $GLOBALS['ilLog']->write(__METHOD__ . ': No valid user found for usr_id ' . $a_parameter['usr_id']); return true; } $settings = self::initServer($a_parameter['usr_id']); self::extendAccount($settings, $user); include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php'; self::updateEnrolmentStatus($a_parameter['obj_id'], $user, ilECSEnrolmentStatus::STATUS_PENDING); } break; case 'deleteParticipant': if (ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs') { if (!($user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id']))) { $GLOBALS['ilLog']->write(__METHOD__ . ': No valid user found for usr_id ' . $a_parameter['usr_id']); return true; } include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php'; self::updateEnrolmentStatus($a_parameter['obj_id'], $user, ilECSEnrolmentStatus::STATUS_UNSUBSCRIBED); } break; case 'addParticipant': if (ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs') { if (!($user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id']))) { $GLOBALS['ilLog']->write(__METHOD__ . ': No valid user found for usr_id ' . $a_parameter['usr_id']); return true; } $settings = self::initServer($user->getId()); self::extendAccount($settings, $user); #self::_sendNotification($settings,$user); include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php'; self::updateEnrolmentStatus($a_parameter['obj_id'], $user, ilECSEnrolmentStatus::STATUS_ACTIVE); unset($user); } break; } break; case 'Modules/Course': $GLOBALS['ilLog']->write(__METHOD__ . ': New event from course: ' . $a_event); switch ($a_event) { case 'addSubscriber': case 'addToWaitingList': if (ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs') { if (!($user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id']))) { $GLOBALS['ilLog']->write(__METHOD__ . ': No valid user found for usr_id ' . $a_parameter['usr_id']); return true; } $settings = self::initServer($a_parameter['usr_id']); self::extendAccount($settings, $user); include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php'; self::updateEnrolmentStatus($a_parameter['obj_id'], $user, ilECSEnrolmentStatus::STATUS_PENDING); } break; case 'deleteParticipant': if (ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs') { if (!($user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id']))) { $GLOBALS['ilLog']->write(__METHOD__ . ': No valid user found for usr_id ' . $a_parameter['usr_id']); return true; } include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php'; self::updateEnrolmentStatus($a_parameter['obj_id'], $user, ilECSEnrolmentStatus::STATUS_UNSUBSCRIBED); } break; case 'addParticipant': if (ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs') { if (!($user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id']))) { $GLOBALS['ilLog']->write(__METHOD__ . ': No valid user found for usr_id ' . $a_parameter['usr_id']); return true; } $settings = self::initServer($user->getId()); self::extendAccount($settings, $user); self::_sendNotification($settings, $user); include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php'; self::updateEnrolmentStatus($a_parameter['obj_id'], $user, ilECSEnrolmentStatus::STATUS_ACTIVE); unset($user); } break; } break; } }