本文整理汇总了PHP中get_auth_plugin函数的典型用法代码示例。如果您正苦于以下问题:PHP get_auth_plugin函数的具体用法?PHP get_auth_plugin怎么用?PHP get_auth_plugin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_auth_plugin函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: local_ent_installer_cron
/**
* this function schedules the user synchronisation updates
*
* Implementation specific : Generic
*/
function local_ent_installer_cron()
{
global $CFG;
if (!get_config('local_ent_installer', 'cron_enable')) {
return;
}
$now = time();
$needscron = false;
$chour = 0 + get_config('local_ent_installer', 'cron_hour');
$cmin = 0 + get_config('local_ent_installer', 'cron_min');
$cfreq = get_config('local_ent_installer', 'cron_enable');
$now = time();
$nowdt = getdate($now);
$expectedtime = get_config('local_ent_installer', 'last_sync_date') + $cfreq - HOURSEC;
$crondebug = optional_param('crondebug', false, PARAM_BOOL);
if ($now < $expectedtime && !$crondebug) {
return;
}
if (!empty($CFG->ent_installer_running)) {
return;
}
if ($nowdt['hours'] * 60 + $nowdt['minutes'] >= $chour * 60 + $cmin || $crondebug) {
set_config('ent_installer_running', 1);
set_config('last_sync_date', $now, 'local_ent_installer');
// Get ldap params from real ldap plugin.
$ldapauth = get_auth_plugin('ldap');
$options = array('host' => $CFG->wwwroot);
// Run the customised synchro.
local_ent_installer_sync_users($ldapauth, $options);
set_config('ent_installer_running', null);
} else {
mtrace('waiting for valid time ');
}
}
示例2: get_content
function get_content()
{
global $USER, $CFG, $SESSION;
$wwwroot = '';
$signup = '';
if ($this->content !== NULL) {
return $this->content;
}
if (empty($CFG->loginhttps)) {
$wwwroot = $CFG->wwwroot;
} else {
// This actually is not so secure ;-), 'cause we're
// in unencrypted connection...
$wwwroot = str_replace("http://", "https://", $CFG->wwwroot);
}
if (!empty($CFG->registerauth)) {
$authplugin = get_auth_plugin($CFG->registerauth);
if ($authplugin->can_signup()) {
$signup = $wwwroot . '/login/signup.php';
}
}
// TODO: now that we have multiauth it is hard to find out if there is a way to change password
$forgot = $wwwroot . '/login/forgot_password.php';
if (!empty($CFG->loginpasswordautocomplete)) {
$autocomplete = 'autocomplete="off"';
} else {
$autocomplete = '';
}
$username = get_moodle_cookie();
$this->content = new stdClass();
$this->content->footer = '';
$this->content->text = '';
if (!isloggedin() or isguestuser()) {
// Show the block
if (empty($CFG->authloginviaemail)) {
$strusername = get_string('username');
} else {
$strusername = get_string('usernameemail');
}
$this->content->text .= "\n" . '<form class="loginform" id="login" method="post" action="' . get_login_url() . '" ' . $autocomplete . '>';
$this->content->text .= '<div class="c1 fld username"><label for="login_username">' . $strusername . '</label>';
$this->content->text .= '<input type="text" name="username" id="login_username" value="' . s($username) . '" /></div>';
$this->content->text .= '<div class="c1 fld password"><label for="login_password">' . get_string('password') . '</label>';
$this->content->text .= '<input type="password" name="password" id="login_password" value="" ' . $autocomplete . ' /></div>';
if (isset($CFG->rememberusername) and $CFG->rememberusername == 2) {
$checked = $username ? 'checked="checked"' : '';
$this->content->text .= '<div class="c1 rememberusername"><input type="checkbox" name="rememberusername" id="rememberusername" value="1" ' . $checked . '/>';
$this->content->text .= ' <label for="rememberusername">' . get_string('rememberusername', 'admin') . '</label></div>';
}
$this->content->text .= '<div class="c1 btn"><input type="submit" value="' . get_string('login') . '" /></div>';
$this->content->text .= "</form>\n";
if (!empty($signup)) {
$this->content->footer .= '<div><a href="' . $signup . '">' . get_string('startsignup') . '</a></div>';
}
if (!empty($forgot)) {
$this->content->footer .= '<div><a href="' . $forgot . '">' . get_string('forgotaccount') . '</a></div>';
}
}
return $this->content;
}
示例3: definition_after_data
function definition_after_data()
{
global $CFG, $DB;
$mform =& $this->_form;
$userid = $mform->getElementValue('id');
// if language does not exist, use site default lang
if ($langsel = $mform->getElementValue('lang')) {
$lang = reset($langsel);
// missing _utf8 in language, add it before further processing. MDL-11829 MDL-16845
if (strpos($lang, '_utf8') === false) {
$lang = $lang . '_utf8';
$lang_el =& $mform->getElement('lang');
$lang_el->setValue($lang);
}
// check lang exists
if (!file_exists($CFG->dataroot . '/lang/' . $lang) and !file_exists($CFG->dirroot . '/lang/' . $lang)) {
$lang_el =& $mform->getElement('lang');
$lang_el->setValue($CFG->lang);
}
}
if ($user = $DB->get_record('user', array('id' => $userid))) {
// remove description
if (empty($user->description) && !empty($CFG->profilesforenrolledusersonly) && !$DB->record_exists('role_assignments', array('userid' => $userid))) {
$mform->removeElement('description');
}
// print picture
if (!empty($CFG->gdversion)) {
$image_el =& $mform->getElement('currentpicture');
if ($user and $user->picture) {
$image_el->setValue(print_user_picture($user, SITEID, $user->picture, 64, true, false, '', true));
} else {
$image_el->setValue(get_string('none'));
}
}
/// disable fields that are locked by auth plugins
$fields = get_user_fieldnames();
$authplugin = get_auth_plugin($user->auth);
foreach ($fields as $field) {
if (!$mform->elementExists($field)) {
continue;
}
$configvariable = 'field_lock_' . $field;
if (isset($authplugin->config->{$configvariable})) {
if ($authplugin->config->{$configvariable} === 'locked') {
$mform->hardFreeze($field);
$mform->setConstant($field, $user->{$field});
} else {
if ($authplugin->config->{$configvariable} === 'unlockedifempty' and $user->{$field} != '') {
$mform->hardFreeze($field);
$mform->setConstant($field, $user->{$field});
}
}
}
}
/// Next the customisable profile fields
profile_definition_after_data($mform, $user->id);
} else {
profile_definition_after_data($mform, 0);
}
}
示例4: definition_after_data
function definition_after_data()
{
global $CFG, $DB, $OUTPUT;
$mform =& $this->_form;
$userid = $mform->getElementValue('id');
// if language does not exist, use site default lang
if ($langsel = $mform->getElementValue('lang')) {
$lang = reset($langsel);
// check lang exists
if (!get_string_manager()->translation_exists($lang, false)) {
$lang_el =& $mform->getElement('lang');
$lang_el->setValue($CFG->lang);
}
}
if ($user = $DB->get_record('user', array('id' => $userid))) {
// remove description
if (empty($user->description) && !empty($CFG->profilesforenrolledusersonly) && !$DB->record_exists('role_assignments', array('userid' => $userid))) {
$mform->removeElement('description_editor');
}
// print picture
$context = context_user::instance($user->id, MUST_EXIST);
$fs = get_file_storage();
$hasuploadedpicture = $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.png') || $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.jpg');
if (!empty($user->picture) && $hasuploadedpicture) {
$imagevalue = $OUTPUT->user_picture($user, array('courseid' => SITEID, 'size' => 64));
} else {
$imagevalue = get_string('none');
}
$imageelement = $mform->getElement('currentpicture');
$imageelement->setValue($imagevalue);
if ($mform->elementExists('deletepicture') && !$hasuploadedpicture) {
$mform->removeElement('deletepicture');
}
/// disable fields that are locked by auth plugins
$fields = get_user_fieldnames();
$authplugin = get_auth_plugin($user->auth);
foreach ($fields as $field) {
if (!$mform->elementExists($field)) {
continue;
}
$configvariable = 'field_lock_' . $field;
if (isset($authplugin->config->{$configvariable})) {
if ($authplugin->config->{$configvariable} === 'locked') {
$mform->hardFreeze($field);
$mform->setConstant($field, $user->{$field});
} else {
if ($authplugin->config->{$configvariable} === 'unlockedifempty' and $user->{$field} != '') {
$mform->hardFreeze($field);
$mform->setConstant($field, $user->{$field});
}
}
}
}
/// Next the customisable profile fields
profile_definition_after_data($mform, $user->id);
} else {
profile_definition_after_data($mform, 0);
}
}
示例5: execute
/**
* Run users sync.
*/
public function execute()
{
global $CFG;
if (is_enabled_auth('cas')) {
$auth = get_auth_plugin('cas');
$auth->sync_users(true);
}
}
示例6: validation
function validation($data, $files)
{
global $CFG;
$errors = parent::validation($data, $files);
$authplugin = get_auth_plugin($CFG->registerauth);
if (record_exists('user', 'username', $data['username'], 'mnethostid', $CFG->mnet_localhost_id)) {
$errors['username'] = get_string('usernameexists');
} else {
if (empty($CFG->extendedusernamechars)) {
$string = eregi_replace("[^(-\\.[:alnum:])]", '', $data['username']);
if (strcmp($data['username'], $string)) {
$errors['username'] = get_string('alphanumerical');
}
}
}
//check if user exists in external db
//TODO: maybe we should check all enabled plugins instead
if ($authplugin->user_exists($data['username'])) {
$errors['username'] = get_string('usernameexists');
}
if (!validate_email($data['email'])) {
$errors['email'] = get_string('invalidemail');
} else {
if (record_exists('user', 'email', $data['email'])) {
$errors['email'] = get_string('emailexists') . ' <a href="forgot_password.php">' . get_string('newpassword') . '?</a>';
}
}
if (empty($data['email2'])) {
$errors['email2'] = get_string('missingemail');
} else {
if ($data['email2'] != $data['email']) {
$errors['email2'] = get_string('invalidemail');
}
}
if (!isset($errors['email'])) {
if ($err = email_is_not_allowed($data['email'])) {
$errors['email'] = $err;
}
}
$errmsg = '';
if (!check_password_policy($data['password'], $errmsg)) {
$errors['password'] = $errmsg;
}
if (signup_captcha_enabled()) {
$recaptcha_element = $this->_form->getElement('recaptcha_element');
if (!empty($this->_form->_submitValues['recaptcha_challenge_field'])) {
$challenge_field = $this->_form->_submitValues['recaptcha_challenge_field'];
$response_field = $this->_form->_submitValues['recaptcha_response_field'];
if (true !== ($result = $recaptcha_element->verify($challenge_field, $response_field))) {
$errors['recaptcha'] = $result;
}
} else {
$errors['recaptcha'] = get_string('missingrecaptchachallengefield');
}
}
return $errors;
}
示例7: __logout
function __logout()
{
$authsequence = get_enabled_auth_plugins();
// auths, in sequence
foreach ($authsequence as $authname) {
$authplugin = get_auth_plugin($authname);
$authplugin->logoutpage_hook();
}
require_logout();
}
示例8: test_user_updated
/**
* Tests that the locations in the auth_db API that update a user trigger the user_updated event.
*/
public function test_user_updated()
{
global $CFG, $DB;
$this->preventResetByRollback();
// Initialise the database.
$authdbtestcase = new auth_db_testcase();
$authdbtestcase->init_auth_database();
$auth = get_auth_plugin('db');
$auth->db_init();
// Add a suspended user.
$user = array();
$user['username'] = 'mark';
$user['suspended'] = '1';
$user['mnethostid'] = $CFG->mnet_localhost_id;
$user['auth'] = 'db';
$this->getDataGenerator()->create_user($user);
// Add a user to the auth_db_users table - we will then call sync_users to
// deal with the record here. In this case it will un-suspend the user.
$user = new stdClass();
$user->name = 'mark';
$user->pass = 'password123';
$user->email = 'what@legend.com';
$user->id = $DB->insert_record('auth_db_users', $user);
// Set the config to remove the suspension on the user.
set_config('removeuser', AUTH_REMOVEUSER_SUSPEND, 'auth/db');
$auth->config->removeuser = AUTH_REMOVEUSER_SUSPEND;
// Run sync_users and capture the user_updated event.
$sink = $this->redirectEvents();
$trace = new null_progress_trace();
$auth->sync_users($trace, false);
$events = $sink->get_events();
$sink->close();
// Check that there is only one event.
$this->assertEquals(1, count($events));
// Get the event.
$event = array_pop($events);
// Test that the user updated event was triggered - no need to test the other
// details of the event as that is done extensively in other unit tests.
$this->assertInstanceOf('\\core\\event\\user_updated', $event);
// Run sync_users and capture the user_updated event.
$sink = $this->redirectEvents();
$auth->update_user_record('mark');
$events = $sink->get_events();
$sink->close();
// Check that there is only one event.
$this->assertEquals(1, count($events));
// Get the event.
$event = array_pop($events);
// Test that the user updated event was triggered - no need to test the other
// details of the event as that is done extensively in other unit tests.
$this->assertInstanceOf('\\core\\event\\user_updated', $event);
}
示例9: validation
function validation($data)
{
global $CFG;
$errors = array();
$authplugin = get_auth_plugin($CFG->registerauth);
if (record_exists('user', 'username', $data['username'], 'mnethostid', $CFG->mnet_localhost_id)) {
$errors['username'] = get_string('usernameexists');
} else {
if (empty($CFG->extendedusernamechars)) {
$string = eregi_replace("[^(-\\.[:alnum:])]", '', $data['username']);
if (strcmp($data['username'], $string)) {
$errors['username'] = get_string('alphanumerical');
}
}
}
//check if user exists in external db
//TODO: maybe we should check all enabled plugins instead
if ($authplugin->user_exists($data['username'])) {
$errors['username'] = get_string('usernameexists');
}
if (!validate_email($data['email'])) {
$errors['email'] = get_string('invalidemail');
} else {
if (record_exists('user', 'email', $data['email'])) {
$errors['email'] = get_string('emailexists') . ' <a href="forgot_password.php">' . get_string('newpassword') . '?</a>';
}
}
if (empty($data['email2'])) {
$errors['email2'] = get_string('missingemail');
} else {
if ($data['email2'] != $data['email']) {
$errors['email2'] = get_string('invalidemail');
}
}
if (!isset($errors['email'])) {
if ($err = email_is_not_allowed($data['email'])) {
$errors['email'] = $err;
}
}
if (!check_password_policy($data['password'], $errmsg)) {
$errors['password'] = $errmsg;
}
if (0 == count($errors)) {
return true;
} else {
return $errors;
}
}
示例10: definition_after_data
function definition_after_data()
{
global $CFG;
$mform =& $this->_form;
$userid = $mform->getElementValue('id');
// if language does not exist, use site default lang
if ($langsel = $mform->getElementValue('lang')) {
$lang = reset($langsel);
if (!file_exists($CFG->dataroot . '/lang/' . $lang) and !file_exists($CFG->dirroot . '/lang/' . $lang)) {
$lang_el =& $mform->getElement('lang');
$lang_el->setValue($CFG->lang);
}
}
if ($user = get_record('user', 'id', $userid)) {
// print picture
if (!empty($CFG->gdversion)) {
$image_el =& $mform->getElement('currentpicture');
if ($user and $user->picture) {
$image_el->setValue(print_user_picture($user->id, SITEID, $user->picture, 64, true, false, '', true));
} else {
$image_el->setValue(get_string('none'));
}
}
/// disable fields that are locked by auth plugins
$fields = get_user_fieldnames();
$freezefields = array();
$authplugin = get_auth_plugin($user->auth);
foreach ($fields as $field) {
if (!$mform->elementExists($field)) {
continue;
}
$configvariable = 'field_lock_' . $field;
if (isset($authplugin->config->{$configvariable})) {
if ($authplugin->config->{$configvariable} === 'locked') {
$freezefields[] = $field;
} else {
if ($authplugin->config->{$configvariable} === 'unlockedifempty' and $user->{$field} != '') {
$freezefields[] = $field;
}
}
}
}
$mform->hardFreeze($freezefields);
}
/// Next the customisable profile fields
profile_definition_after_data($mform);
}
示例11: execute
public function execute()
{
global $CFG;
require_once "{$CFG->libdir}/datalib.php";
$user = get_admin();
if (!$user) {
cli_error("Unable to find admin user in DB.");
}
$auth = empty($user->auth) ? 'manual' : $user->auth;
if ($auth == 'nologin' or !is_enabled_auth($auth)) {
cli_error(sprintf("User authentication is either 'nologin' or disabled. Check Moodle authentication method for '%s'", $user->username));
}
$authplugin = get_auth_plugin($auth);
$authplugin->sync_roles($user);
login_attempt_valid($user);
complete_user_login($user);
printf("%s:%s\n", session_name(), session_id());
}
示例12: get_content
function get_content()
{
global $USER, $CFG;
$wwwroot = '';
$signup = '';
if ($this->content !== NULL) {
return $this->content;
}
if (empty($CFG->loginhttps)) {
$wwwroot = $CFG->wwwroot;
} else {
// This actually is not so secure ;-), 'cause we're
// in unencrypted connection...
$wwwroot = str_replace("http://", "https://", $CFG->wwwroot);
}
if (!empty($CFG->registerauth)) {
$authplugin = get_auth_plugin($CFG->registerauth);
if ($authplugin->can_signup()) {
$signup = $wwwroot . '/login/signup.php';
}
}
// TODO: now that we have multiauth it is hard to find out if there is a way to change password
$forgot = $wwwroot . '/login/forgot_password.php';
$username = get_moodle_cookie() === 'nobody' ? '' : get_moodle_cookie();
$this->content->footer = '';
$this->content->text = '';
if (!isloggedin() or isguestuser()) {
// Show the block
$this->content->text .= "\n" . '<form class="loginform" id="login" method="post" action="' . $wwwroot . '/login/index.php">';
$this->content->text .= '<div class="c1 fld username"><label for="login_username">' . get_string('username') . '</label>';
$this->content->text .= '<input type="text" name="username" id="login_username" value="' . s($username) . '" /></div>';
$this->content->text .= '<div class="c1 fld password"><label for="login_password">' . get_string('password') . '</label>';
$this->content->text .= '<input type="password" name="password" id="login_password" value="" /></div>';
$this->content->text .= '<div class="c1 btn"><input type="submit" value="' . get_string('login') . '" /></div>';
$this->content->text .= "</form>\n";
if (!empty($signup)) {
$this->content->footer .= '<div><a href="' . $signup . '">' . get_string('startsignup') . '</a></div>';
}
if (!empty($forgot)) {
$this->content->footer .= '<div><a href="' . $forgot . '">' . get_string('forgotaccount') . '</a></div>';
}
}
return $this->content;
}
示例13: print_login
/**
* Display the file listing - no login required
* @global <type> $SESSION
* @param <type> $ajax
* @return <type>
*/
public function print_login($ajax = true)
{
global $SESSION, $CFG, $DB;
//jump to the peer to create a session
require_once $CFG->dirroot . '/mnet/lib.php';
$this->ensure_environment();
$mnetauth = get_auth_plugin('mnet');
$host = $DB->get_record('mnet_host', array('id' => $this->options['peer']));
//need to retrieve the host url
$url = $mnetauth->start_jump_session($host->id, '/repository/ws.php?callback=yes&repo_id=' . $this->id, true);
//set session
$SESSION->loginmahara = true;
$ret = array();
$popup_btn = new stdclass();
$popup_btn->type = 'popup';
$popup_btn->url = $url;
$ret['login'] = array($popup_btn);
return $ret;
}
示例14: __app_reset_password_and_mail
private function __app_reset_password_and_mail($user)
{
global $CFG;
$site = get_site();
$supportuser = generate_email_supportuser();
$userauth = get_auth_plugin($user->auth);
if (!$userauth->can_reset_password() or !is_enabled_auth($user->auth)) {
trigger_error("Attempt to reset user password for user {$user->username} with Auth {$user->auth}.");
return false;
}
$newpassword = generate_password();
if (!$userauth->user_update_password($user, $newpassword)) {
$error->error = true;
$error->msg = 'fp_passwordgen_failure';
echo json_encode($error);
die;
}
$a = new stdClass();
$a->firstname = $user->firstname;
$a->lastname = $user->lastname;
$a->sitename = format_string($site->fullname);
$a->username = $user->username;
$a->newpassword = $newpassword;
//$a->signoff = generate_email_signoff();
$message = 'Hi ' . $a->firstname . ',
Your account password at \'' . $a->sitename . '\' has been reset
and you have been issued with a new temporary password.
Your current login information is now:
username: ' . $a->username . '
password: ' . $a->newpassword . '
Cheers from the \'' . $a->sitename . '\' administrator.';
//$message = get_string('newpasswordtext', '', $a);
$subject = format_string($site->fullname) . ': ' . get_string('changedpassword');
unset_user_preference('create_password', $user);
// prevent cron from generating the password
//directly email rather than using the messaging system to ensure its not routed to a popup or jabber
return email_to_user($user, $supportuser, $subject, $message);
}
示例15: validation
function validation($data, $files)
{
global $CFG;
$invite = false;
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
if (isloggedin() && has_capability('moodle/local:invitenewuser', $sitecontext)) {
$invite = true;
}
$errors = parent::validation($data, $files);
$authplugin = get_auth_plugin($CFG->registerauth);
if ($data['password1'] != $data['password2']) {
$errors['password1'] = get_string('passwordsdiffer');
$errors['password2'] = get_string('passwordsdiffer');
return $errors;
}
if (record_exists('user', 'username', $data['username'], 'mnethostid', $CFG->mnet_localhost_id)) {
$errors['username'] = get_string('usernameexists');
} else {
if (empty($CFG->extendedusernamechars)) {
$string = eregi_replace("[^(-\\.[:alnum:])]", '', $data['username']);
if (strcmp($data['username'], $string)) {
$errors['username'] = get_string('alphanumerical');
}
}
}
//check if user exists in external db
//TODO: maybe we should check all enabled plugins instead
if ($authplugin->user_exists($data['username'])) {
$errors['username'] = get_string('usernameexists');
}
$errmsg = '';
if (!check_password_policy($data['password1'], $errmsg)) {
$errors['password1'] = $errmsg;
}
if (function_exists('local_user_signup_validation')) {
if ($localvalidation = local_user_signup_validation()) {
$errors = array_merge($errors, $localvalidation);
}
}
return $errors;
}