本文整理汇总了PHP中authenticate_user_login函数的典型用法代码示例。如果您正苦于以下问题:PHP authenticate_user_login函数的具体用法?PHP authenticate_user_login怎么用?PHP authenticate_user_login使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了authenticate_user_login函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: loginpage_hook
/**
* Function to enable SSO (it runs before user_login() is called)
* If a valid CHOCOLATECHIP cookie is not found, the user will be forced to the
* master bakery login page where have to authenticate the user.
*
* @return logged in USER
*/
function loginpage_hook()
{
global $CFG, $USER, $DB;
global $key, $cookieDomain, $slaveURL, $masterURL, $defaultCountry;
$key = $this->config->skey;
$cookieDomain = $this->config->cookiedomain;
$masterURL = $this->config->masterurl;
$slaveURL = $this->config->slaveurl;
$defaultCountry = $this->config->defaultcountry;
$mdBakery['slave'] = validateCookie();
if (!empty($mdBakery['slave'])) {
$username = $mdBakery['slave']['name'];
$user = authenticate_user_login($username, null);
if ($user) {
complete_user_login($user);
$urltogo = $CFG->wwwroot . '/';
$userMail = $USER->email;
// If dummie change init url through edit user form
$userInit = $USER->idnumber;
// Don't check for username because of user freedom for Firstname and Lastname display
if ($userMail != $mdBakery['slave']['mail'] || $userInit != $mdBakery['slave']['init']) {
$emptyString = " ";
// Or just "default" string
$user->idnumber = $mdBakery['slave']['init'];
$fName = ucfirst($mdBakery['slave']['name']);
$user->firstname = $fName;
$user->lastname = $emptyString;
$user->email = $mdBakery['slave']['mail'];
$user->city = $emptyString;
$user->country = $defaultCountry;
$DB->update_record('user', $user);
}
redirect($urltogo);
}
} else {
if (isloggedin() && !isguestuser()) {
require_logout();
} else {
// $master_redirect = $masterURL . 'user/login?return_dest=' . urlencode($slaveURL . 'login/index.php');
// header('Location: ' . $master_redirect);
}
}
}
开发者ID:AKovalevich,项目名称:moodle-auth_bakery,代码行数:50,代码来源:auth.php
示例2: validation
function validation($data, $files)
{
global $USER;
$errors = parent::validation($data, $files);
update_login_count();
// ignore submitted username
if (!($user = authenticate_user_login($USER->username, $data['password']))) {
$errors['password'] = get_string('invalidlogin');
return $errors;
}
reset_login_count();
if ($data['newpassword1'] != $data['newpassword2']) {
$errors['newpassword1'] = get_string('passwordsdiffer');
$errors['newpassword2'] = get_string('passwordsdiffer');
return $errors;
}
if ($data['password'] == $data['newpassword1']) {
$errors['newpassword1'] = get_string('mustchangepassword');
$errors['newpassword2'] = get_string('mustchangepassword');
return $errors;
}
$errmsg = '';
//prevents eclipse warnings
if (!check_password_policy($data['newpassword1'], $errmsg)) {
$errors['newpassword1'] = $errmsg;
$errors['newpassword2'] = $errmsg;
return $errors;
}
return $errors;
}
开发者ID:kai707,项目名称:ITSA-backup,代码行数:30,代码来源:change_password_form.php
示例3: login
public function login($username, $password)
{
$user = authenticate_user_login($username, $password);
if (0 < $user->id && $user->admin) {
$_SESSION['MoodlePlugin'] = true;
return session_id();
//var_export($user, true);
}
return MOODLEWS_ERROR;
}
开发者ID:BackupTheBerlios,项目名称:moodlews-svn,代码行数:10,代码来源:moodleplugin.php
示例4: http_basic_login
/**
* podcaster basic authentication
*
* @author Humboldt Universitaet zu Berlin
* Christoph Soergel <[email protected]>
* @version 1.0
* @package podcaster
*
*/
function http_basic_login()
{
global $USER;
$realm = 'restricted';
$userValid = false;
if (isloggedin()) {
return true;
}
$realm = 'restricted';
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
$user = authenticate_user_login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
do {
if (!$user) {
$realm = 'loginerror';
break;
}
$USER = $user;
// check whether the user should be changing password
if (get_user_preferences('auth_forcepasswordchange', false)) {
if ($passwordchangeurl != '') {
$realm = 'mustchangepassword';
} else {
$realm = 'mustchangepassword_butnourl';
}
break;
}
// check wether user is fully setup
if (user_not_fully_set_up($USER)) {
$realm = 'notfullysetup';
break;
}
return true;
} while (false);
unset($USER);
}
// no credentials
header('WWW-Authenticate: Basic realm="' . get_string($realm, 'podcaster') . '"');
header('HTTP/1.0 401 Unauthorized');
echo get_string($realm, 'podcaster');
exit;
}
开发者ID:NextEinstein,项目名称:riverhills,代码行数:50,代码来源:basic.php
示例5: validation
function validation($data)
{
global $USER;
$errors = array();
update_login_count();
// ignore submitted username
if (!($user = authenticate_user_login($USER->username, $data['password']))) {
$errors['password'] = get_string('invalidlogin');
return $errors;
}
reset_login_count();
if ($data['newpassword1'] != $data['newpassword2']) {
$errors['newpassword1'] = get_string('passwordsdiffer');
$errors['newpassword2'] = get_string('passwordsdiffer');
return $errors;
}
if ($data['password'] == $data['newpassword1']) {
$errors['newpassword1'] = get_string('mustchangepassword');
$errors['newpassword2'] = get_string('mustchangepassword');
return $errors;
}
return true;
}
开发者ID:veritech,项目名称:pare-project,代码行数:23,代码来源:change_password_form.php
示例6: validation
function validation($data, $files)
{
global $USER;
$errors = parent::validation($data, $files);
update_login_count();
// ignore submitted username
if (!($user = authenticate_user_login($USER->username, $data['password']))) {
$errors['password'] = get_string('invalidlogin');
return $errors;
}
reset_login_count();
if ($data['newpassword1'] != $data['newpassword2']) {
$errors['newpassword1'] = get_string('passwordsdiffer');
$errors['newpassword2'] = get_string('passwordsdiffer');
return $errors;
}
if ($data['password'] == $data['newpassword1']) {
$errors['newpassword1'] = get_string('mustchangepassword');
$errors['newpassword2'] = get_string('mustchangepassword');
return $errors;
}
$errmsg = '';
//prevents eclipse warnings
if (!check_password_policy($data['newpassword1'], $errmsg)) {
$errors['newpassword1'] = $errmsg;
$errors['newpassword2'] = $errmsg;
return $errors;
}
// Added by SMS 8/7/2011: To make sure the password does not include special
// characters that may result in issues when synching the password with vms
if (!isValidPassword($data['newpassword1'])) {
$errors['newpassword1'] .= 'Your password cannot contain the following characters: " / \\ [ ] : ; | = , + * ? < > @ & !';
$errors['newpassword2'] .= 'Your password cannot contain the following characters: " / \\ [ ] : ; | = , + * ? < > @ & !';
}
return $errors;
}
开发者ID:arshanam,项目名称:Moodle-ITScholars-LMS,代码行数:36,代码来源:change_password_form.php
示例7: print_error
print_error('shib_not_set_up_error', 'auth_shibboleth');
}
/// If we can find the Shibboleth attribute, save it in session and return to main login page
if (!empty($_SERVER[$pluginconfig->user_attribute])) {
// Shibboleth auto-login
$frm = new stdClass();
$frm->username = strtolower($_SERVER[$pluginconfig->user_attribute]);
// The password is never actually used, but needs to be passed to the functions 'user_login' and
// 'authenticate_user_login'. Shibboleth returns true for the function 'prevent_local_password', which is
// used when setting the password in 'update_internal_user_password'. When 'prevent_local_password'
// returns true, the password is set to 'not cached' (AUTH_PASSWORD_NOT_CACHED) in the Moodle DB. However,
// rather than setting the password to a hard-coded value, we will generate one each time, in case there are
// changes to the Shibboleth plugin and it is actually used.
$frm->password = generate_password(8);
/// Check if the user has actually submitted login data to us
if ($shibbolethauth->user_login($frm->username, $frm->password) && ($user = authenticate_user_login($frm->username, $frm->password))) {
complete_user_login($user);
if (user_not_fully_set_up($USER)) {
$urltogo = $CFG->wwwroot . '/user/edit.php?id=' . $USER->id . '&course=' . SITEID;
// We don't delete $SESSION->wantsurl yet, so we get there later
} else {
if (isset($SESSION->wantsurl) and strpos($SESSION->wantsurl, $CFG->wwwroot) === 0) {
$urltogo = $SESSION->wantsurl;
/// Because it's an address in this site
unset($SESSION->wantsurl);
} else {
$urltogo = $CFG->wwwroot . '/';
/// Go to the standard home page
unset($SESSION->wantsurl);
/// Just in case
}
开发者ID:bobpuffer,项目名称:moodleUCLA-LUTH,代码行数:31,代码来源:index.php
示例8: teosso_authenticate_user
function teosso_authenticate_user()
{
global $CFG, $USER, $SESSION;
$pluginconfig = get_config('auth/teosso');
// retrieve the login data from the HTTP Headers
$attributes = auth_plugin_teosso::get_sso_attributes();
// check to see if we got any authentication data
if (empty($attributes)) {
redirect($pluginconfig->signin_url);
}
// get the http headers for error reporting
$headers = apache_request_headers();
$attr_hdrs = array();
foreach ($headers as $key => $value) {
if (preg_match('/^HTTP_/', $key)) {
$attr_hdrs[] = $key . ': ' . $value;
}
}
$headers = implode(' | ', $attr_hdrs);
// FIND THE VALIDIDTY OF THE HTTP HEADER
$attrmap = auth_plugin_teosso::get_attributes();
if (empty($attrmap['idnumber'])) {
// serious misdemeanour
print_error('missingidnumber', 'auth_teosso');
}
if (empty($attributes[$attrmap['idnumber']])) {
#
// not valid session. Ship user off to Federation Manager
add_to_log(0, 'login', 'error', '/auth/teosso/index.php', get_string('idnumber_error', 'auth_teosso', $headers));
redirect($pluginconfig->signin_error_url);
} else {
// in theory we only need acct_id at this point - we should retrieve the user record to get the username via idnumber
if (!($user = get_record('user', 'idnumber', $attributes[$attrmap['idnumber']]))) {
// must be a new user
if (!empty($attributes[$attrmap['username']])) {
$attributes['username'] = $attributes[$attrmap['username']];
} else {
add_to_log(0, 'login', 'error', '/auth/teosso/index.php', get_string('username_error', 'auth_teosso', $headers));
redirect($pluginconfig->signin_error_url);
}
} else {
// user must use the auth type teosso or authenticate_user_login() will fail
if ($user->auth != 'teosso') {
add_to_log(0, 'login', 'error', '/auth/teosso/index.php', get_string('user_auth_type_error', 'auth_teosso', $headers));
redirect($pluginconfig->signin_error_url);
}
// because we want to retain acct_id as the master ID
// we need to modify idnumber on mdl_user NOW - so it all lines up later
if (isset($attributes[$attrmap['username']]) && $user->username != $attributes[$attrmap['username']]) {
if (!set_field('user', 'username', $attributes[$attrmap['username']], 'id', $user->id)) {
print_error('usernameupdatefailed', 'auth_teosso');
}
$attributes['username'] = $attributes[$attrmap['username']];
} else {
$attributes['username'] = $user->username;
}
}
// Valid session. Register or update user in Moodle, log him on, and redirect to Moodle front
// we require the plugin to know that we are now doing a teosso login in hook puser_login
$GLOBALS['teosso_login'] = TRUE;
// make variables accessible to teosso->get_userinfo. Information will be requested from authenticate_user_login -> create_user_record / update_user_record
$GLOBALS['teosso_login_attributes'] = $attributes;
// just passes time as a password. User will never log in directly to moodle with this password anyway or so we hope?
$USER = authenticate_user_login($attributes['username'], time());
$USER->loggedin = true;
$USER->site = $CFG->wwwroot;
update_user_login_times();
if ($pluginconfig->notshowusername) {
// Don't show username on login page
set_moodle_cookie('nobody');
}
set_login_session_preferences();
add_to_log(SITEID, 'user', 'login', "view.php?id={$USER->id}&course=" . SITEID, $USER->id, 0, $USER->id);
check_enrolment_plugins($USER);
load_all_capabilities();
// just fast copied this from some other module - might not work...
if (isset($SESSION->wantsurl) and strpos($SESSION->wantsurl, $CFG->wwwroot) === 0) {
$urltogo = $SESSION->wantsurl;
} else {
$urltogo = $CFG->wwwroot . '/';
}
unset($SESSION->wantsurl);
redirect($urltogo);
}
}
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:85,代码来源:index.php
示例9: loginpage_hook
//.........这里部分代码省略.........
$user = $DB->get_record('user', array('email' => $useremail, 'deleted' => 0, 'mnethostid' => $CFG->mnet_localhost_id));
//create the user if it doesn't exist
if (empty($user)) {
//get following incremented username
$lastusernumber = get_config('auth/googleoauth2', 'lastusernumber');
$lastusernumber = empty($lastusernumber) ? 1 : $lastusernumber++;
//check the user doesn't exist
$nextuser = $DB->get_record('user', array('username' => get_config('auth/googleoauth2', 'googleuserprefix') . $lastusernumber));
while (!empty($nextuser)) {
$lastusernumber = $lastusernumber + 1;
$nextuser = $DB->get_record('user', array('username' => get_config('auth/googleoauth2', 'googleuserprefix') . $lastusernumber));
}
set_config('lastusernumber', $lastusernumber, 'auth/googleoauth2');
$username = get_config('auth/googleoauth2', 'googleuserprefix') . $lastusernumber;
//retrieve more information from the provider
$newuser = new stdClass();
$newuser->email = $useremail;
switch ($authprovider) {
case 'google':
$params = array();
$params['access_token'] = $accesstoken;
$params['alt'] = 'json';
$userinfo = $curl->get('https://www.googleapis.com/oauth2/v1/userinfo', $params);
$userinfo = json_decode($userinfo);
//email, id, name, verified_email, given_name, family_name, link, gender, locale
$newuser->auth = 'googleoauth2';
if (!empty($userinfo->given_name)) {
$newuser->firstname = $userinfo->given_name;
}
if (!empty($userinfo->family_name)) {
$newuser->lastname = $userinfo->family_name;
}
if (!empty($userinfo->locale)) {
//$newuser->lang = $userinfo->locale;
//TODO: convert the locale into correct Moodle language code
}
break;
case 'facebook':
$newuser->firstname = $facebookuser->first_name;
$newuser->lastname = $facebookuser->last_name;
break;
case 'messenger':
$newuser->firstname = $messengeruser->first_name;
$newuser->lastname = $messengeruser->last_name;
break;
default:
break;
}
//retrieve country and city if the provider failed to give it
if (!isset($newuser->country) or !isset($newuser->city)) {
$googleipinfodbkey = get_config('auth/googleoauth2', 'googleipinfodbkey');
if (!empty($googleipinfodbkey)) {
$locationdata = $curl->get('http://api.ipinfodb.com/v3/ip-city/?key=' . $googleipinfodbkey . '&ip=' . getremoteaddr() . '&format=json');
$locationdata = json_decode($locationdata);
}
if (!empty($locationdata)) {
//TODO: check that countryCode does match the Moodle country code
$newuser->country = isset($newuser->country) ? isset($newuser->country) : $locationdata->countryCode;
$newuser->city = isset($newuser->city) ? isset($newuser->city) : $locationdata->cityName;
}
}
} else {
$username = $user->username;
}
//authenticate the user
//TODO: delete this log later
$userid = empty($user) ? 'new user' : $user->id;
add_to_log(SITEID, 'auth_googleoauth2', '', '', $username . '/' . $useremail . '/' . $userid);
$user = authenticate_user_login($username, null);
if ($user) {
//set a cookie to remember what auth provider was selected
setcookie('MOODLEGOOGLEOAUTH2_' . $CFG->sessioncookie, $authprovider, time() + DAYSECS * 60, $CFG->sessioncookiepath, $CFG->sessioncookiedomain, $CFG->cookiesecure, $CFG->cookiehttponly);
//prefill more user information if new user
if (!empty($newuser)) {
$newuser->id = $user->id;
$DB->update_record('user', $newuser);
}
complete_user_login($user);
// Redirection
if (user_not_fully_set_up($USER)) {
$urltogo = $CFG->wwwroot . '/user/edit.php';
// We don't delete $SESSION->wantsurl yet, so we get there later
} else {
if (isset($SESSION->wantsurl) and strpos($SESSION->wantsurl, $CFG->wwwroot) === 0) {
$urltogo = $SESSION->wantsurl;
// Because it's an address in this site
unset($SESSION->wantsurl);
} else {
// No wantsurl stored or external - go to homepage
$urltogo = $CFG->wwwroot . '/';
unset($SESSION->wantsurl);
}
}
redirect($urltogo);
}
} else {
throw new moodle_exception('couldnotgetgoogleaccesstoken', 'auth_googleoauth2');
}
}
}
开发者ID:rajivnavada,项目名称:auth_googleoauth2,代码行数:101,代码来源:auth.php
示例10: array_for_modules
}
}
$new_section["modules"] = array_for_modules($section_modules);
$sections_array[] = $new_section;
}
}
$json_output["site_sections"] = $sections_array;
if ($CFG->rolesactive) {
$json_output["site_admin"] = has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
} else {
$json_output["site_admin"] = isadmin();
}
$json_output["auto_login_guests"] = $CFG->autologinguests == 1;
}
if (isset($_GET['check_user']) || $update_all && isset($_POST['username']) && isset($_POST['password'])) {
$json_output["login_valid"] = authenticate_user_login($_POST['username'], $_POST['password']) != FALSE;
}
if (isset($_GET['course_categories']) || $update_all) {
include_once $CFG->dirroot . '/course/lib.php';
$categories = array();
$given_categories = get_categories();
foreach ($given_categories as $i => $each_category) {
$is_admin = FALSE;
if ($CFG->rolesactive) {
} else {
$is_admin = isadmin();
}
$show_category = $each_category->visible or $is_admin;
if ($each_category->visible) {
$new_category = array();
$new_category["id"] = $each_category->id;
开发者ID:nagyistoce,项目名称:moodle-Teach-Pilot,代码行数:31,代码来源:main.php
示例11: get_string
$authorize_error = get_string("auth_saml_not_authorize", "auth_saml", $username);
$authorize_user = false;
}
if (function_exists('saml_hook_authorize_user')) {
$result = saml_hook_authorize_user($username, $saml_attributes, $authorize_user);
if ($result !== true) {
$authorize_user = false;
$authorize_error = $result;
}
}
if (!$authorize_user) {
$err['login'] = "<p>" . $authorize_error . "</p>";
saml_error($err, '?logout', $pluginconfig->samllogfile);
}
// Just passes time as a password. User will never log in directly to moodle with this password anyway or so we hope?
$user = authenticate_user_login($username, time());
if ($user === false) {
$err['login'] = get_string("auth_saml_error_authentication_process", "auth_saml", $username);
saml_error($err['login'], '?logout', $pluginconfig->samllogfile);
}
// Complete the user login sequence
$user = get_complete_user_data('id', $user->id);
if ($user === false) {
$err['login'] = get_string("auth_saml_error_complete_user_data", "auth_saml", $username);
saml_error($err['login'], '?logout', $pluginconfig->samllogfile);
}
$USER = complete_user_login($user);
if (function_exists('saml_hook_post_user_created')) {
saml_hook_post_user_created($USER);
}
if (isset($SESSION->wantsurl) && !empty($SESSION->wantsurl)) {
开发者ID:blionut,项目名称:elearning,代码行数:31,代码来源:index.php
示例12: test_authenticate_user_login
public function test_authenticate_user_login()
{
global $CFG;
$this->resetAfterTest();
$oldlog = ini_get('error_log');
ini_set('error_log', "{$CFG->dataroot}/testlog.log");
// Prevent standard logging.
set_config('lockoutthreshold', 0);
set_config('lockoutwindow', 60 * 20);
set_config('lockoutduration', 60 * 30);
$_SERVER['HTTP_USER_AGENT'] = 'no browser';
// Hack around missing user agent in CLI scripts.
$user1 = $this->getDataGenerator()->create_user(array('username' => 'username1', 'password' => 'password1'));
$user2 = $this->getDataGenerator()->create_user(array('username' => 'username2', 'password' => 'password2', 'suspended' => 1));
$user3 = $this->getDataGenerator()->create_user(array('username' => 'username3', 'password' => 'password3', 'auth' => 'nologin'));
$result = authenticate_user_login('username1', 'password1');
$this->assertInstanceOf('stdClass', $result);
$this->assertEquals($user1->id, $result->id);
$reason = null;
$result = authenticate_user_login('username1', 'password1', false, $reason);
$this->assertInstanceOf('stdClass', $result);
$this->assertEquals(AUTH_LOGIN_OK, $reason);
$reason = null;
$result = authenticate_user_login('username1', 'nopass', false, $reason);
$this->assertFalse($result);
$this->assertEquals(AUTH_LOGIN_FAILED, $reason);
$reason = null;
$result = authenticate_user_login('username2', 'password2', false, $reason);
$this->assertFalse($result);
$this->assertEquals(AUTH_LOGIN_SUSPENDED, $reason);
$reason = null;
$result = authenticate_user_login('username3', 'password3', false, $reason);
$this->assertFalse($result);
$this->assertEquals(AUTH_LOGIN_SUSPENDED, $reason);
$reason = null;
$result = authenticate_user_login('username4', 'password3', false, $reason);
$this->assertFalse($result);
$this->assertEquals(AUTH_LOGIN_NOUSER, $reason);
set_config('lockoutthreshold', 3);
$reason = null;
$result = authenticate_user_login('username1', 'nopass', false, $reason);
$this->assertFalse($result);
$this->assertEquals(AUTH_LOGIN_FAILED, $reason);
$result = authenticate_user_login('username1', 'nopass', false, $reason);
$this->assertFalse($result);
$this->assertEquals(AUTH_LOGIN_FAILED, $reason);
ob_start();
// Prevent nomailever notice.
$result = authenticate_user_login('username1', 'nopass', false, $reason);
ob_end_clean();
$this->assertFalse($result);
$this->assertEquals(AUTH_LOGIN_FAILED, $reason);
$result = authenticate_user_login('username1', 'password1', false, $reason);
$this->assertFalse($result);
$this->assertEquals(AUTH_LOGIN_LOCKOUT, $reason);
$result = authenticate_user_login('username1', 'password1', true, $reason);
$this->assertInstanceOf('stdClass', $result);
$this->assertEquals(AUTH_LOGIN_OK, $reason);
ini_set('error_log', $oldlog);
}
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:60,代码来源:authlib_test.php
示例13: user_signup
/**
* Sign up a new user ready for confirmation.
* Password is passed in plaintext.
*
* @param object $user new user object
* @param boolean $notify print notice with link and terminate
*/
function user_signup($user, $notify = true)
{
global $CFG, $DB, $SESSION;
require_once $CFG->dirroot . '/user/profile/lib.php';
require_once $CFG->dirroot . '/user/lib.php';
if (isset($SESSION->wantsurl)) {
$wantsurl = $SESSION->wantsurl;
}
$plainpassword = $user->password;
$user->password = hash_internal_user_password($user->password);
if (empty($user->calendartype)) {
$user->calendartype = $CFG->calendartype;
}
$user->confirmed = 1;
$user->id = user_create_user($user, false, false);
user_add_password_history($user->id, $plainpassword);
// Save any custom profile field information.
profile_save_data($user);
// Trigger event.
\core\event\user_created::create_from_userid($user->id)->trigger();
$thisuser = authenticate_user_login($user->username, $plainpassword, false, $errorcode);
if ($thisuser == false) {
print_error('authfailure');
} else {
complete_user_login($thisuser);
if (isset($wantsurl)) {
$urltogo = $wantsurl;
if (isset($_SESSION["fiaction"]) && isset($_SESSION["ficourseid"]) && is_numeric($_SESSION["ficourseid"]) && $_SESSION["fiaction"] == "enroll") {
$urltogo = $CFG->wwwroot . '/course/enrol.php?id=' . $_SESSION["ficourseid"];
unset($_SESSION['fiaction']);
unset($_SESSION['ficourseid']);
unset($SESSION->wantsurl);
}
} else {
$urltogo = $CFG->wwwroot . '/';
}
redirect($urltogo);
}
// if ($notify) {
// global $CFG, $PAGE, $OUTPUT;
// $emailconfirm = get_string('emailconfirm');
// $PAGE->navbar->add($emailconfirm);
// $PAGE->set_title($emailconfirm);
// $PAGE->set_heading($PAGE->course->fullname);
// echo $OUTPUT->header();
// notice(get_string('emailconfirmsent', '', $user->email), "$CFG->wwwroot/index.php");
// } else {
// return true;
// }
}
开发者ID:TheFridayInstitute,项目名称:moodle-auth_fiemail,代码行数:57,代码来源:auth.php
示例14: __authenticate
public function __authenticate($username, $password, $serviceshortname)
{
global $CFG, $DB;
//echo $OUTPUT->header();
if (!$CFG->enablewebservices) {
throw new moodle_exception('enablewsdescription', 'webservice');
}
$username = trim(textlib::strtolower($username));
if (is_restored_user($username)) {
throw new moodle_exception('restoredaccountresetpassword', 'webservice');
}
$user = authenticate_user_login($username, $password);
if (!empty($user)) {
//Non admin can not authenticate if maintenance mode
$hassiteconfig = has_capability('moodle/site:config', context_system::instance(), $user);
if (!empty($CFG->maintenance_enabled) and !$hassiteconfig) {
throw new moodle_exception('sitemaintenance', 'admin');
}
if (isguestuser($user)) {
throw new moodle_exception('noguest');
}
if (empty($user->confirmed)) {
throw new moodle_exception('usernotconfirmed', 'moodle', '', $user->username);
}
// check credential expiry
$userauth = get_auth_plugin($user->auth);
if (!empty($userauth->config->expiration) and $userauth->config->expiration == 1) {
$days2expire = $userauth->password_expire($user->username);
if (intval($days2expire) < 0) {
throw new moodle_exception('passwordisexpired', 'webservice');
}
}
// let enrol plugins deal with new enrolments if necessary
enrol_check_plugins($user);
// setup user session to check capability
session_set_user($user);
//check if the service exists and is enabled
$service = $DB->get_record('external_services', array('shortname' => $serviceshortname, 'enabled' => 1));
if (empty($service)) {
// will throw exception if no token found
throw new moodle_exception('servicenotavailable', 'webservice');
}
//check if there is any required system capability
if ($service->requiredcapability and !has_capability($service->requiredcapability, context_system::instance(), $user)) {
throw new moodle_exception('missingrequiredcapability', 'webservice', '', $service->requiredcapability);
}
//specific checks related to user restricted service
if ($service->restrictedusers) {
$authoriseduser = $DB->get_record('external_services_users', array('externalserviceid' => $service->id, 'userid' => $user->id));
if (empty($authoriseduser)) {
throw new moodle_exception('usernotallowed', 'webservice', '', $serviceshortname);
}
if (!empty($authoriseduser->validuntil) and $authoriseduser->validuntil < time()) {
throw new moodle_exception('invalidtimedtoken', 'webservice');
}
if (!empty($authoriseduser->iprestriction) and !address_in_subnet(getremoteaddr(), $authoriseduser->iprestriction)) {
throw new moodle_exception('invalidiptoken', 'webservice');
}
}
//Check if a token has already been created for this user and this service
//Note: this could be an admin created or an user created token.
// It does not really matter we take the first one that is valid.
$tokenssql = "SELECT t.id, t.sid, t.token, t.validuntil, t.iprestriction\n FROM {external_tokens} t\n WHERE t.userid = ? AND t.externalserviceid = ? AND t.tokentype = ?\n ORDER BY t.timecreated ASC";
$tokens = $DB->get_records_sql($tokenssql, array($user->id, $service->id, EXTERNAL_TOKEN_PERMANENT));
//A bit of sanity checks
foreach ($tokens as $key => $token) {
/// Checks related to a specific token. (script execution continue)
$unsettoken = false;
//if sid is set then there must be a valid associated session no matter the token type
if (!empty($token->sid)) {
$session = session_get_instance();
if (!$session->session_exists($token->sid)) {
//this token will never be valid anymore, delete it
$DB->delete_records('external_tokens', array('sid' => $token->sid));
$unsettoken = true;
}
}
//remove token if no valid anymore
//Also delete this wrong token (similar logic to the web service servers
// /webservice/lib.php/webservice_server::authenticate_by_token())
if (!empty($token->validuntil) and $token->validuntil < time()) {
$DB->delete_records('external_tokens', array('token' => $token->token, 'tokentype' => EXTERNAL_TOKEN_PERMANENT));
$unsettoken = true;
}
// remove token if its ip not in whitelist
if (isset($token->iprestriction) and !address_in_subnet(getremoteaddr(), $token->iprestriction)) {
$unsettoken = true;
}
if ($unsettoken) {
unset($tokens[$key]);
}
}
// if some valid tokens exist then use the most recent
if (count($tokens) > 0) {
$token = array_pop($tokens);
} else {
if ($serviceshortname == MOODLE_OFFICIAL_MOBILE_SERVICE and has_capability('moodle/webservice:createmobiletoken', get_system_context()) or !is_siteadmin($user) && has_capability('moodle/webservice:createtoken', get_system_context())) {
// if service doesn't exist, dml will throw exception
$service_record = $DB->get_record('external_services', array('shortname' => $serviceshortname, 'enabled' => 1), '*', MUST_EXIST);
// create a new token
//.........这里部分代码省略.........
开发者ID:vinoth4891,项目名称:clinique,代码行数:101,代码来源:clinique_login_authenticate.php
示例15: check_user_secret
function check_user_secret($username, $passwd)
{
$user = get_complete_user_data('username', $username);
if (is_object($user)) {
// try to login this user ...
if (!empty($passwd)) {
return authenticate_user_login($username, $passwd);
// returns $USER object on success
}
}
return false;
}
开发者ID:kai707,项目名称:ITSA-backup,代码行数:12,代码来源:lib_ldapsso.php
示例16: print_error
$USER->id = 0;
require_once '../../config.php';
print_error('auth_onelogin_saml: auth failed due to missing username/email saml attribute: ' . $pluginconfig->saml_username_map . "<br />" . get_string("auth_onelogin_saml_username_email_error", "auth_onelogin_saml") . "\r\n");
}
if ($_POST['SAMLResponse']) {
$saml_account_matcher = $pluginconfig->saml_account_matcher;
if (empty($saml_account_matcher)) {
$saml_account_matcher = 'username';
}
$saml_create = $pluginconfig->saml_auto_create_users == 'on' ? true : false;
$saml_update = $pluginconfig->saml_auto_update_users == 'on' ? true : false;
$USER = auth_onelogin_saml_authenticate_user_login($saml_account_matcher, $saml_user, $saml_create, $saml_update);
} else {
print_error("Info received. Finishing authentication process through regular method hook because no SAML response detected.");
display_object($_POST);
$USER = authenticate_user_login($saml_user[$saml_account_matcher], time());
}
// check that the signin worked
if ($USER == false) {
print_error("You could not be identified or created. <br />Login result: FAILURE<br />I have...<br />" . htmlspecialchars(print_r($USER, true)));
session_write_close();
$USER = new object();
$USER->id = 0;
require_once '../../config.php';
print_error('pluginauthfailed', 'auth_onelogin_saml', '', !empty($saml_user['username']) ? $saml_user['username'] : $saml_user['email']);
}
// complete the user login sequence
$USER->loggedin = true;
$USER->site = $CFG->wwwroot;
$USER = get_complete_user_data('id', $USER->id);
complete_user_login($USER);
开发者ID:mfprimo,项目名称:moodle-onelogin,代码行数:31,代码来源:index.php
示例17: RWSLIMUser
function RWSLIMUser($r_usrn, $r_pw, $r_csf)
{
global $RWSECAS;
/*********** eClass Modification ************
Extra Comments:
LDAP lookup call for the employee id translation for ccid
CCID->empid, this is needed because the authentication fails and tries to create a user.
************/
global $CFG;
require_once $CFG->dirroot . '/local/eclass/lib/IMS.php';
$ims = new IMS($r_usrn, $r_pw, 'uid=', 'ou=people,dc=ualberta,dc=ca');
$user_info = $ims->get_user_info($r_usrn);
$empid = $user_info->employeenumber;
/*********** End eClass Modification ********/
if ($RWSECAS) {
RWSPLICas($r_usrn, $r_pw, $r_csf);
}
//$r_usr = authenticate_user_login($r_usrn, $r_pw);
$r_usr = authenticate_user_login($empid, $r_pw);
//eClass Modification
if ($r_usr) {
complete_user_login($r_usr);
}
if (isloggedin()) {
RWSSStat("1000");
} else {
if ($RWSECAS) {
if (isset($_SESSION['rwscas']['cookiejar'])) {
$r_ckf = $_SESSION['rwscas']['cookiejar'];
if (file_exists($r_ckf)) {
unlink($r_ckf);
}
unset($_SESSION['rwscas']['cookiejar']);
}
unset($_SESSION['rwscas']);
}
RWSSErr("2008");
}
}
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:41,代码来源:servicelib.php
示例18: loginpage_hook
//.........这里部分代码省略.........
while (!empty($user_lenauth_check)) {
$user_lenauth_check = $user_lenauth_check + 1;
$username = $this->_oauth_config->auth_lenauth_user_prefix . $last_user_number;
$user_lenauth_check = $DB->get_record('user', array('username' => $username));
$i_check++;
if ($i_check > 20) {
throw new moodle_exception('Something wrong with usernames of LenAuth users. Limit of 20 queries is out. Check last mdl_user table of Moodle', 'auth_lenauth');
}
}
// create user HERE
$user_lenauth = create_user_record($username, '', 'lenauth');
/**
* User exists...
*/
} else {
$username = $user_lenauth->username;
}
set_config('auth_lenauth_last_user_number', $last_user_number, 'auth/lenauth');
if (!empty($social_uid)) {
$user_social_uid_custom_field = new stdClass();
$user_social_uid_custom_field->u
|
请发表评论