예제 #1
0
파일: external.php 프로젝트: janeklb/moodle
 /**
  * Confirm a user account.
  *
  * @param  string $username user name
  * @param  string $secret   confirmation secret (random string) used for validating the confirm request
  * @return array warnings and success status (true if the user was confirmed, false if he was already confirmed)
  * @since Moodle 3.2
  * @throws moodle_exception
  */
 public static function confirm_user($username, $secret)
 {
     global $PAGE;
     $warnings = array();
     $params = self::validate_parameters(self::confirm_user_parameters(), array('username' => $username, 'secret' => $secret));
     $context = context_system::instance();
     $PAGE->set_context($context);
     if (!($authplugin = signup_get_user_confirmation_authplugin())) {
         throw new moodle_exception('confirmationnotenabled');
     }
     $confirmed = $authplugin->user_confirm($username, $secret);
     if ($confirmed == AUTH_CONFIRM_ALREADY) {
         $success = false;
         $warnings[] = array('item' => 'user', 'itemid' => 0, 'warningcode' => 'alreadyconfirmed', 'message' => s(get_string('alreadyconfirmed')));
     } else {
         if ($confirmed == AUTH_CONFIRM_OK) {
             $success = true;
         } else {
             throw new moodle_exception('invalidconfirmdata');
         }
     }
     $result = array('success' => $success, 'warnings' => $warnings);
     return $result;
 }
예제 #2
0
 * @package    core
 * @subpackage auth
 * @copyright  1999 Martin Dougiamas  http://dougiamas.com
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require '../config.php';
require_once $CFG->libdir . '/authlib.php';
$data = optional_param('data', '', PARAM_RAW);
// Formatted as:  secret/username
$p = optional_param('p', '', PARAM_ALPHANUM);
// Old parameter:  secret
$s = optional_param('s', '', PARAM_RAW);
// Old parameter:  username
$PAGE->set_url('/login/confirm.php');
$PAGE->set_context(context_system::instance());
if (!($authplugin = signup_get_user_confirmation_authplugin())) {
    throw new moodle_exception('confirmationnotenabled');
}
if (!empty($data) || !empty($p) && !empty($s)) {
    if (!empty($data)) {
        $dataelements = explode('/', $data, 2);
        // Stop after 1st slash. Rest is username. MDL-7647
        $usersecret = $dataelements[0];
        $username = $dataelements[1];
    } else {
        $usersecret = $p;
        $username = $s;
    }
    $confirmed = $authplugin->user_confirm($username, $usersecret);
    if ($confirmed == AUTH_CONFIRM_ALREADY) {
        $user = get_complete_user_data('username', $username);