コード例 #1
0
ファイル: events_test.php プロジェクト: pzhu2004/moodle
 /**
  * Test the mnet access control updated event.
  */
 public function test_mnet_access_control_updated()
 {
     global $DB;
     // Create a mnet access control.
     $mnetaccesscontrol = new stdClass();
     $mnetaccesscontrol->username = '******';
     $mnetaccesscontrol->mnet_host_id = $this->mnethost->id;
     $mnetaccesscontrol->accessctrl = 'enabled';
     $mnetaccesscontrol->id = $DB->insert_record('mnet_sso_access_control', $mnetaccesscontrol);
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     mnet_update_sso_access_control('username', $this->mnethost->id, 'enabled');
     $events = $sink->get_events();
     $event = reset($events);
     // Check that the event data is valid.
     $this->assertInstanceOf('\\core\\event\\mnet_access_control_updated', $event);
     $this->assertEquals(context_system::instance(), $event->get_context());
     $expected = array(SITEID, 'admin/mnet', 'update', 'admin/mnet/access_control.php', 'SSO ACL: enabled user \'username\' from ' . $this->mnethost->name);
     $this->assertEventLegacyLogData($expected, $event);
     $this->assertEventContextNotUsed($event);
     $url = new \moodle_url('/admin/mnet/access_control.php');
     $this->assertEquals($url, $event->get_url());
 }
コード例 #2
0
        $formerror['username'] = get_string('enterausername', 'mnet');
    }
    if (empty($form->mnet_host_id)) {
        $formerror['mnet_host_id'] = get_string('selectahost', 'mnet');
    }
    if (empty($form->accessctrl)) {
        $formerror['accessctrl'] = get_string('selectaccesslevel', 'mnet');
    }
    // process if there are no errors
    if (count($formerror) == 0) {
        // username can be a comma separated list
        $usernames = explode(',', $form->username);
        foreach ($usernames as $username) {
            $username = trim(moodle_strtolower($username));
            if (!empty($username)) {
                if (mnet_update_sso_access_control($username, $form->mnet_host_id, $form->accessctrl)) {
                    if ($form->accessctrl == 'allow') {
                        redirect('access_control.php', get_string('ssl_acl_allow', 'mnet', array($username, $mnethosts[$form->mnet_host_id])));
                    } elseif ($form->accessctrl == 'deny') {
                        redirect('access_control.php', get_string('ssl_acl_deny', 'mnet', array($username, $mnethosts[$form->mnet_host_id])));
                    }
                }
            }
        }
    }
    exit;
}
// Explain
print_box(get_string('ssoacldescr', 'mnet'));
// Are the needed bits enabled?
$warn = '';