当前位置: 首页>>代码示例>>PHP>>正文


PHP email_is_not_allowed函数代码示例

本文整理汇总了PHP中email_is_not_allowed函数的典型用法代码示例。如果您正苦于以下问题:PHP email_is_not_allowed函数的具体用法?PHP email_is_not_allowed怎么用?PHP email_is_not_allowed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了email_is_not_allowed函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validation

 function validation($usernew, $files)
 {
     global $CFG, $DB;
     $errors = parent::validation($usernew, $files);
     $usernew = (object) $usernew;
     $user = $DB->get_record('user', array('id' => $usernew->id));
     // validate email
     if (!isset($usernew->email)) {
         // mail not confirmed yet
     } else {
         if (!validate_email($usernew->email)) {
             $errors['email'] = get_string('invalidemail');
         } else {
             if ($usernew->email !== $user->email and $DB->record_exists('user', array('email' => $usernew->email, 'mnethostid' => $CFG->mnet_localhost_id))) {
                 $errors['email'] = get_string('emailexists');
             }
         }
     }
     if (isset($usernew->email) and $usernew->email === $user->email and over_bounce_threshold($user)) {
         $errors['email'] = get_string('toomanybounces');
     }
     if (isset($usernew->email) and !empty($CFG->verifychangedemail) and !isset($errors['email']) and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) {
         $errorstr = email_is_not_allowed($usernew->email);
         if ($errorstr !== false) {
             $errors['email'] = $errorstr;
         }
     }
     /// Next the customisable profile fields
     $errors += profile_validation($usernew, $files);
     return $errors;
 }
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:31,代码来源:edit_form.php

示例2: get_complete_user_data

     $user = get_complete_user_data('idnumber', $idnumber);
 } else {
     // create new user
     //code based on moodlelib.create_user_record($username, $password, 'manual')
     $auth = 'wp2moodle';
     // so they log in - and out - with this plugin
     $authplugin = get_auth_plugin($auth);
     $newuser = new stdClass();
     if ($newinfo = $authplugin->get_userinfo($username)) {
         $newinfo = truncate_user($newinfo);
         foreach ($newinfo as $key => $value) {
             $newuser->{$key} = $value;
         }
     }
     if (!empty($newuser->email)) {
         if (email_is_not_allowed($newuser->email)) {
             unset($newuser->email);
         }
     }
     if (!isset($newuser->city)) {
         $newuser->city = '';
     }
     $newuser->auth = $auth;
     $newuser->policyagreed = 1;
     $newuser->idnumber = $idnumber;
     $newuser->username = $username;
     $newuser->password = md5($hashedpassword);
     // manual auth checks password validity, so we need to set a valid password
     // $DB->set_field('user', 'password',  $hashedpassword, array('id'=>$user->id));
     $newuser->firstname = $firstname;
     $newuser->lastname = $lastname;
开发者ID:nagyistoce,项目名称:wp2moodle-moodle,代码行数:31,代码来源:login.php

示例3: create_user_record

/**
 * Creates a bare-bones user record
 *
 * @uses $CFG
 * @param string $username New user's username to add to record
 * @param string $password New user's password to add to record
 * @param string $auth Form of authentication required
 * @return object A {@link $USER} object
 * @todo Outline auth types and provide code example
 */
function create_user_record($username, $password, $auth = 'manual')
{
    global $CFG;
    //just in case check text case
    $username = trim(moodle_strtolower($username));
    $authplugin = get_auth_plugin($auth);
    if ($newinfo = $authplugin->get_userinfo($username)) {
        $newinfo = truncate_userinfo($newinfo);
        foreach ($newinfo as $key => $value) {
            $newuser->{$key} = addslashes($value);
        }
    }
    if (!empty($newuser->email)) {
        if (email_is_not_allowed($newuser->email)) {
            unset($newuser->email);
        }
    }
    if (!isset($newuser->city)) {
        $newuser->city = '';
    }
    $newuser->auth = $auth;
    $newuser->username = $username;
    // fix for MDL-8480
    // user CFG lang for user if $newuser->lang is empty
    // or $user->lang is not an installed language
    $sitelangs = array_keys(get_list_of_languages());
    if (empty($newuser->lang) || !in_array($newuser->lang, $sitelangs)) {
        $newuser->lang = $CFG->lang;
    }
    $newuser->confirmed = 1;
    $newuser->lastip = getremoteaddr();
    $newuser->timemodified = time();
    $newuser->mnethostid = $CFG->mnet_localhost_id;
    if (insert_record('user', $newuser)) {
        $user = get_complete_user_data('username', $newuser->username);
        if (!empty($CFG->{'auth_' . $newuser->auth . '_forcechangepassword'})) {
            set_user_preference('auth_forcepasswordchange', 1, $user->id);
        }
        update_internal_user_password($user, $password);
        return $user;
    }
    return false;
}
开发者ID:nadavkav,项目名称:rtlMoodle,代码行数:53,代码来源:moodlelib.php

示例4: create_user_from_aaddata

 /**
  * Create a Moodle user from Azure AD user data.
  *
  * @param array $aaddata Array of Azure AD user data.
  * @return \stdClass An object representing the created Moodle user.
  */
 public function create_user_from_aaddata($aaddata)
 {
     global $CFG;
     require_once $CFG->dirroot . '/user/profile/lib.php';
     require_once $CFG->dirroot . '/user/lib.php';
     $newuser = (object) ['auth' => 'oidc', 'username' => trim(\core_text::strtolower($aaddata['userPrincipalName'])), 'email' => isset($aaddata['mail']) ? $aaddata['mail'] : '', 'firstname' => isset($aaddata['givenName']) ? $aaddata['givenName'] : '', 'lastname' => isset($aaddata['surname']) ? $aaddata['surname'] : '', 'city' => isset($aaddata['city']) ? $aaddata['city'] : '', 'country' => isset($aaddata['country']) ? $aaddata['country'] : '', 'department' => isset($aaddata['department']) ? $aaddata['department'] : '', 'lang' => isset($aaddata['preferredLanguage']) ? substr($aaddata['preferredLanguage'], 0, 2) : 'en', 'confirmed' => 1, 'timecreated' => time(), 'mnethostid' => $CFG->mnet_localhost_id];
     $password = null;
     $newuser->idnumber = $newuser->username;
     if (!empty($newuser->email)) {
         if (email_is_not_allowed($newuser->email)) {
             unset($newuser->email);
         }
     }
     if (empty($newuser->lang) || !get_string_manager()->translation_exists($newuser->lang)) {
         $newuser->lang = $CFG->lang;
     }
     $newuser->timemodified = $newuser->timecreated;
     $newuser->id = user_create_user($newuser, false, false);
     // Save user profile data.
     profile_save_data($newuser);
     $user = get_complete_user_data('id', $newuser->id);
     if (!empty($CFG->{'auth_' . $newuser->auth . '_forcechangepassword'})) {
         set_user_preference('auth_forcepasswordchange', 1, $user);
     }
     // Set the password.
     update_internal_user_password($user, $password);
     // Trigger event.
     \core\event\user_created::create_from_userid($newuser->id)->trigger();
     return $user;
 }
开发者ID:jamesmcq,项目名称:o365-moodle,代码行数:36,代码来源:main.php

示例5: loginpage_hook

 /**
  * Authentication hook - is called every time user hit the login page
  * The code is run only if the param code is mentionned.
  */
 public function loginpage_hook()
 {
     global $USER, $SESSION, $CFG, $DB;
     // Check the Google authorization code.
     $authorizationcode = optional_param('code', '', PARAM_TEXT);
     if (!empty($authorizationcode)) {
         $authprovider = required_param('authprovider', PARAM_ALPHANUMEXT);
         require_once $CFG->dirroot . '/auth/googleoauth2/classes/provider/' . $authprovider . '.php';
         $providerclassname = 'provideroauth2' . $authprovider;
         $provider = new $providerclassname();
         // Try to get an access token (using the authorization code grant).
         $token = $provider->getAccessToken('authorization_code', ['code' => $authorizationcode]);
         $accesstoken = $token->accessToken;
         $refreshtoken = $token->refreshToken;
         $tokenexpires = $token->expires;
         // With access token request by curl the email address.
         if (!empty($accesstoken)) {
             try {
                 // We got an access token, let's now get the user's details.
                 $userdetails = $provider->getUserDetails($token);
                 // Use these details to create a new profile.
                 switch ($authprovider) {
                     case 'battlenet':
                         // Battlenet as no email notion.
                         // TODO: need to check the idp table for matching user and request user to add his email.
                         // TODO: It will be similar logic for twitter.
                         $useremail = $userdetails->id . '@fakebattle.net';
                         break;
                     case 'github':
                         $useremails = $provider->getUserEmails($token);
                         // Going to try to find someone with a similar email using googleoauth2 auth.
                         $fallbackuseremail = '';
                         foreach ($useremails as $githubuseremail) {
                             if ($githubuseremail->verified) {
                                 if ($DB->record_exists('user', array('auth' => 'googleoauth2', 'email' => $githubuseremail->email))) {
                                     $useremail = $githubuseremail->email;
                                 }
                                 $fallbackuseremail = $githubuseremail->email;
                             }
                         }
                         // If we didn't find anyone then we take a verified email address.
                         if (empty($useremail)) {
                             $useremail = $fallbackuseremail;
                         }
                         break;
                     case 'vk':
                         // VK doesn't return the email address?
                         if ($userdetails->uid) {
                             $useremail = 'id' . $userdetails->uid . '@vkmessenger.com';
                         }
                         break;
                     default:
                         $useremail = $userdetails->email;
                         break;
                 }
                 $verified = 1;
             } catch (Exception $e) {
                 // Failed to get user details.
                 throw new moodle_exception('faileduserdetails', 'auth_googleoauth2');
             }
             // Throw an error if the email address is not verified.
             if (!$verified) {
                 throw new moodle_exception('emailaddressmustbeverified', 'auth_googleoauth2');
             }
             // Prohibit login if email belongs to the prohibited domain.
             if ($err = email_is_not_allowed($useremail)) {
                 throw new moodle_exception($err, 'auth_googleoauth2');
             }
             // If email not existing in user database then create a new username (userX).
             if (empty($useremail) or $useremail != clean_param($useremail, PARAM_EMAIL)) {
                 throw new moodle_exception('couldnotgetuseremail', 'auth_googleoauth2');
                 // TODO: display a link for people to retry.
             }
             // Get the user.
             // Don't bother with auth = googleoauth2 because authenticate_user_login() will fail it if it's not 'googleoauth2'.
             $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)) {
                 // Deny login if setting "Prevent account creation when authenticating" is on.
                 if ($CFG->authpreventaccountcreation) {
                     throw new moodle_exception("noaccountyet", "auth_googleoauth2");
                 }
                 // Get following incremented username.
                 $googleuserprefix = core_text::strtolower(get_config('auth/googleoauth2', 'googleuserprefix'));
                 $lastusernumber = get_config('auth/googleoauth2', 'lastusernumber');
                 $lastusernumber = empty($lastusernumber) ? 1 : $lastusernumber + 1;
                 // Check the user doesn't exist.
                 $nextuser = $DB->record_exists('user', array('username' => $googleuserprefix . $lastusernumber));
                 while ($nextuser) {
                     $lastusernumber++;
                     $nextuser = $DB->record_exists('user', array('username' => $googleuserprefix . $lastusernumber));
                 }
                 set_config('lastusernumber', $lastusernumber, 'auth/googleoauth2');
                 $username = $googleuserprefix . $lastusernumber;
                 // Retrieve more information from the provider.
                 $newuser = new stdClass();
//.........这里部分代码省略.........
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:101,代码来源:auth.php

示例6: create_user_record

/**
 * Creates a bare-bones user record
 *
 * @todo Outline auth types and provide code example
 *
 * @param string $username New user's username to add to record
 * @param string $password New user's password to add to record
 * @param string $auth Form of authentication required
 * @return stdClass A complete user object
 */
function create_user_record($username, $password, $auth = 'manual')
{
    global $CFG, $DB;
    //just in case check text case
    $username = trim(moodle_strtolower($username));
    $authplugin = get_auth_plugin($auth);
    $newuser = new stdClass();
    if ($newinfo = $authplugin->get_userinfo($username)) {
        $newinfo = truncate_userinfo($newinfo);
        foreach ($newinfo as $key => $value) {
            $newuser->{$key} = $value;
        }
    }
    if (!empty($newuser->email)) {
        if (email_is_not_allowed($newuser->email)) {
            unset($newuser->email);
        }
    }
    if (!isset($newuser->city)) {
        $newuser->city = '';
    }
    $newuser->auth = $auth;
    $newuser->username = $username;
    // fix for MDL-8480
    // user CFG lang for user if $newuser->lang is empty
    // or $user->lang is not an installed language
    if (empty($newuser->lang) || !get_string_manager()->translation_exists($newuser->lang)) {
        $newuser->lang = $CFG->lang;
    }
    $newuser->confirmed = 1;
    $newuser->lastip = getremoteaddr();
    $newuser->timemodified = time();
    $newuser->mnethostid = $CFG->mnet_localhost_id;
    $newuser->id = $DB->insert_record('user', $newuser);
    $user = get_complete_user_data('id', $newuser->id);
    if (!empty($CFG->{'auth_' . $newuser->auth . '_forcechangepassword'})) {
        set_user_preference('auth_forcepasswordchange', 1, $user);
    }
    update_internal_user_password($user, $password);
    // fetch full user record for the event, the complete user data contains too much info
    // and we want to be consistent with other places that trigger this event
    events_trigger('user_created', $DB->get_record('user', array('id' => $user->id)));
    return $user;
}
开发者ID:hitphp,项目名称:moodle,代码行数:54,代码来源:moodlelib.php

示例7: create_user_from_aaddata

 /**
  * Create a Moodle user from Azure AD user data.
  *
  * @param array $aaddata Array of Azure AD user data.
  * @return \stdClass An object representing the created Moodle user.
  */
 public function create_user_from_aaddata($aaddata)
 {
     global $CFG;
     require_once $CFG->dirroot . '/user/profile/lib.php';
     require_once $CFG->dirroot . '/user/lib.php';
     $creationallowed = $this->check_usercreationrestriction($aaddata);
     if ($creationallowed !== true) {
         mtrace('Cannot create user because they do not meet the configured user creation restrictions.');
         return false;
     }
     // Locate country code.
     if (isset($aaddata['country'])) {
         $countries = get_string_manager()->get_list_of_countries();
         foreach ($countries as $code => $name) {
             if ($aaddata['country'] == $name) {
                 $aaddata['country'] = $code;
             }
         }
         if (strlen($aaddata['country']) > 2) {
             // Limit string to 2 chars to prevent sql error.
             $aaddata['country'] = substr($aaddata['country'], 0, 2);
         }
     }
     $newuser = (object) ['auth' => 'oidc', 'username' => trim(\core_text::strtolower($aaddata['userPrincipalName'])), 'lang' => 'en', 'confirmed' => 1, 'timecreated' => time(), 'mnethostid' => $CFG->mnet_localhost_id];
     $newuser = static::apply_configured_fieldmap($aaddata, $newuser, 'create');
     $password = null;
     $newuser->idnumber = $newuser->username;
     if (!empty($newuser->email)) {
         if (email_is_not_allowed($newuser->email)) {
             unset($newuser->email);
         }
     }
     if (empty($newuser->lang) || !get_string_manager()->translation_exists($newuser->lang)) {
         $newuser->lang = $CFG->lang;
     }
     $newuser->timemodified = $newuser->timecreated;
     $newuser->id = user_create_user($newuser, false, false);
     // Save user profile data.
     profile_save_data($newuser);
     $user = get_complete_user_data('id', $newuser->id);
     if (!empty($CFG->{'auth_' . $newuser->auth . '_forcechangepassword'})) {
         set_user_preference('auth_forcepasswordchange', 1, $user);
     }
     // Set the password.
     update_internal_user_password($user, $password);
     // Trigger event.
     \core\event\user_created::create_from_userid($newuser->id)->trigger();
     return $user;
 }
开发者ID:eugeneventer,项目名称:o365-moodle,代码行数:55,代码来源:main.php

示例8: loginpage_hook


//.........这里部分代码省略.........
                     $messengeruser = json_decode($postreturnvalues);
                     $useremail = $messengeruser->emails->preferred;
                     $verified = 1;
                     //not super good but there are no way to check it yet:
                     //http://social.msdn.microsoft.com/Forums/en-US/messengerconnect/thread/515d546d-1155-4775-95d8-89dadc5ee929
                     break;
                 case 'github':
                     $params = array();
                     $params['access_token'] = $accesstoken;
                     $postreturnvalues = $curl->get('https://api.github.com/user', $params);
                     $githubuser = json_decode($postreturnvalues);
                     $useremails = json_decode($curl->get('https://api.github.com/user/emails', $params));
                     $useremail = $useremails[0];
                     $verified = 1;
                     // The field will be available in the final version of the API v3.
                     break;
                 case 'linkedin':
                     $params = array();
                     $params['format'] = 'json';
                     $params['oauth2_access_token'] = $accesstoken;
                     $postreturnvalues = $curl->get('https://api.linkedin.com/v1/people/~:(first-name,last-name,email-address,location:(name,country:(code)))', $params);
                     $linkedinuser = json_decode($postreturnvalues);
                     $useremail = $linkedinuser->emailAddress;
                     $verified = 1;
                     break;
                 default:
                     break;
             }
             //throw an error if the email address is not verified
             if (!$verified) {
                 throw new moodle_exception('emailaddressmustbeverified', 'auth_googleoauth2');
             }
             // Prohibit login if email belongs to the prohibited domain
             if ($err = email_is_not_allowed($useremail)) {
                 throw new moodle_exception($err, 'auth_googleoauth2');
             }
             //if email not existing in user database then create a new username (userX).
             if (empty($useremail) or $useremail != clean_param($useremail, PARAM_EMAIL)) {
                 throw new moodle_exception('couldnotgetuseremail');
                 //TODO: display a link for people to retry
             }
             //get the user - don't bother with auth = googleoauth2 because
             //authenticate_user_login() will fail it if it's not 'googleoauth2'
             $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)) {
                 // deny login if setting "Prevent account creation when authenticating" is on
                 if ($CFG->authpreventaccountcreation) {
                     throw new moodle_exception("noaccountyet", "auth_googleoauth2");
                 }
                 //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':
开发者ID:stefanotirati,项目名称:moodle-google-apps,代码行数:67,代码来源:auth.php

示例9: loginpage_hook


//.........这里部分代码省略.........
                                             $queryparams['access_token'] = $access_token;
                                             $queryparams['method']       = 'users.getCurrentUser';
                                             $queryparams['sig']          = md5( 'application_key=' . $this->_oauth_config->ok_public_key . 'method=' . $queryparams['method'] . md5( $queryparams['access_token'] . $this->_oauth_config->ok_secret_key ) );
                                             $queryparams['application_key'] = $this->_oauth_config->ok_public_key;
                                             $curl_response               = $curl->get( $request_api_url . '?' . $this->_generate_query_data( $queryparams ) );
                                             $curl_final_data             = json_decode( $curl_response, true );
                     
                                             $first_name                  = $curl_final_data['first_name'];
                                             $last_name                   = $curl_final_data['last_name'];
                                             $social_uid                  = $curl_final_data['uid'];
                                             break;*/
                 /*case 'ok':
                                         $queryparams['access_token'] = $access_token;
                                         $queryparams['method']       = 'users.getCurrentUser';
                                         $queryparams['sig']          = md5( 'application_key=' . $this->_oauth_config->ok_public_key . 'method=' . $queryparams['method'] . md5( $queryparams['access_token'] . $this->_oauth_config->ok_secret_key ) );
                                         $queryparams['application_key'] = $this->_oauth_config->ok_public_key;
                                         $curl_response               = $curl->get( $request_api_url . '?' . $this->_generate_query_data( $queryparams ) );
                                         $curl_final_data             = json_decode( $curl_response, true );
                 
                                         $first_name                  = $curl_final_data['first_name'];
                                         $last_name                   = $curl_final_data['last_name'];
                                         $social_uid                  = $curl_final_data['uid'];
                                         break;*/
                 default:
                     throw new moodle_exception('Unknown OAuth Provider', 'auth_lenauth');
             }
             /**
              * Check for email returned by webservice. If exist - check for user with this email in Moodle Database
              */
             if (!empty($curl_final_data)) {
                 if (!empty($social_uid)) {
                     if ($is_verified) {
                         if (!empty($user_email)) {
                             if ($err = email_is_not_allowed($user_email)) {
                                 throw new moodle_exception($err, 'auth_lenauth');
                             }
                             $user_lenauth = $DB->get_record('user', array('email' => $user_email, 'deleted' => 0, 'mnethostid' => $CFG->mnet_localhost_id));
                         } else {
                             if (empty($user_lenauth)) {
                                 $user_lenauth = $this->_lenauth_get_userdata_by_social_id($social_uid);
                             }
                             /*if ( empty( $user_lenauth ) ) {
                                   $user_lenauth = $DB->get_record('user', array('username' => $username, 'deleted' => 0, 'mnethostid' => $CFG->mnet_localhost_id));
                               }*/
                         }
                     } else {
                         throw new moodle_exception('Your social account is not verified', 'auth_lenauth');
                     }
                 } else {
                     throw new moodle_exception('Empty Social UID', 'auth_lenauth');
                 }
             } else {
                 /**
                  * addon @since 24.12.2014
                  * I forgot about clear $_COOKIE, thanks again for Yandex Tech Team guys!!!
                  */
                 @setcookie($authprovider, null, time() - 3600);
                 throw new moodle_exception('Final request returns nothing', 'auth_lenauth');
             }
             $last_user_number = intval($this->_oauth_config->auth_lenauth_last_user_number);
             $last_user_number = empty($last_user_number) ? 1 : $last_user_number + 1;
             //$username = $this->_oauth_config->auth_lenauth_user_prefix . $last_user_number; //@todo
             /**
              * If user with email from webservice not exists, we will create an account
              */
             if (empty($user_lenauth)) {
开发者ID:HarcourtsAcademy,项目名称:moodle-auth_lenauth,代码行数:67,代码来源:auth.php

示例10: validation

 function validation($data, $files)
 {
     global $CFG, $DB;
     $errors = parent::validation($data, $files);
     $authplugin = get_auth_plugin($CFG->registerauth);
     if (empty(trim($data['username']))) {
         $errors['username'] = get_string('missingemail');
     }
     if (!isset($errors['username'])) {
         if ($DB->record_exists('user', array('username' => $data['username'], 'mnethostid' => $CFG->mnet_localhost_id))) {
             $errors['username'] = get_string('usernameexists');
         }
         if ($authplugin->user_exists($data['username'])) {
             $errors['username'] = get_string('usernameexists');
         }
         if (!validate_email($data['username'])) {
             $errors['username'] = get_string('invalidemail');
         } else {
             if ($DB->record_exists('user', array('email' => $data['username']))) {
                 $errors['username'] = get_string('emailexists');
                 //  . ' <a href="forgot_password.php">' . get_string('newpassword') . '?</a>';
             }
         }
     }
     if (!isset($errors['username'])) {
         if ($err = email_is_not_allowed($data['username'])) {
             $errors['username'] = $err;
         }
     }
     require_once $CFG->dirroot . '/enrol/token/lib.php';
     $tokenValue = $data['token'];
     $tve = enrol_token_plugin::getTokenValidationErrors($tokenValue);
     if (isset($tve) && $tve !== '') {
         $errors['token'] = $tve;
     }
     return $errors;
 }
开发者ID:frumbert,项目名称:moodle-token-enrolment,代码行数:37,代码来源:signup_form.php

示例11: 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');
             }
             // Validates the username for Windows requirements - 22.05.2011 - jam
             $oldusername = stripslashes($data['username']);
             if (!isValidUsername($data['username']) || strcmp($data['username'], $oldusername)) {
                 $errors['username'] = 'Your username cannot contain the following characters: " / \\ [ ] : ; | = , + * ? < > @ & ! and must be less than or equal to 14 characters.';
             }
         }
     }
     //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;
     }
     // 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 // <= 14 char
     if (!isValidPassword($data['password'])) {
         $errors['password'] .= 'Your password cannot contain the following characters: " / \\ [ ] : ; | = , + * ? < > @ & !';
         //$errors['password'] .= ' and it must be less than or equal to 10 characters.';
     }
     if (strlen($data['password']) <= 0 || strlen($data['password']) > 10) {
         $errors['password'] .= ' Your password must be less than or equal to 10 characters.';
     }
     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;
 }
开发者ID:arshanam,项目名称:Moodle-ITScholars-LMS,代码行数:71,代码来源:signup_form.php

示例12: signup_validate_data

/**
 * Validates the standard sign-up data (except recaptcha that is validated by the form element).
 *
 * @param  array $data  the sign-up data
 * @param  array $files files among the data
 * @return array list of errors, being the key the data element name and the value the error itself
 * @since Moodle 3.2
 */
function signup_validate_data($data, $files)
{
    global $CFG, $DB;
    $errors = array();
    $authplugin = get_auth_plugin($CFG->registerauth);
    if ($DB->record_exists('user', array('username' => $data['username'], 'mnethostid' => $CFG->mnet_localhost_id))) {
        $errors['username'] = get_string('usernameexists');
    } else {
        // Check allowed characters.
        if ($data['username'] !== core_text::strtolower($data['username'])) {
            $errors['username'] = get_string('usernamelowercase');
        } else {
            if ($data['username'] !== core_user::clean_field($data['username'], 'username')) {
                $errors['username'] = get_string('invalidusername');
            }
        }
    }
    // 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 ($DB->record_exists('user', array('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;
    }
    // Validate customisable profile fields. (profile_validation expects an object as the parameter with userid set).
    $dataobject = (object) $data;
    $dataobject->id = 0;
    $errors += profile_validation($dataobject, $files);
    return $errors;
}
开发者ID:janeklb,项目名称:moodle,代码行数:59,代码来源:authlib.php

示例13: validation

 function validation($data, $files)
 {
     global $CFG, $DB;
     $errors = parent::validation($data, $files);
     $authplugin = get_auth_plugin($CFG->registerauth);
     if ($DB->record_exists('user', array('username' => $data['username'], 'mnethostid' => $CFG->mnet_localhost_id))) {
         $errors['username'] = get_string('usernameexists');
     } else {
         //check allowed characters
         if ($data['username'] !== moodle_strtolower($data['username'])) {
             $errors['username'] = get_string('usernamelowercase');
         } else {
             if ($data['username'] !== clean_param($data['username'], PARAM_USERNAME)) {
                 $errors['username'] = get_string('invalidusername');
             }
         }
     }
     //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 ($DB->record_exists('user', array('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 ($this->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;
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:59,代码来源:signup_form.php

示例14: 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;
 }
开发者ID:NextEinstein,项目名称:riverhills,代码行数:57,代码来源:signup_form.php

示例15: create_user_record

/**
 * Creates a bare-bones user record
 *
 * @todo Outline auth types and provide code example
 *
 * @param string $username New user's username to add to record
 * @param string $password New user's password to add to record
 * @param string $auth Form of authentication required
 * @return stdClass A complete user object
 */
function create_user_record($username, $password, $auth = 'manual')
{
    global $CFG, $DB;
    require_once $CFG->dirroot . '/user/profile/lib.php';
    require_once $CFG->dirroot . '/user/lib.php';
    // Just in case check text case.
    $username = trim(core_text::strtolower($username));
    $authplugin = get_auth_plugin($auth);
    $customfields = $authplugin->get_custom_user_profile_fields();
    $newuser = new stdClass();
    if ($newinfo = $authplugin->get_userinfo($username)) {
        $newinfo = truncate_userinfo($newinfo);
        foreach ($newinfo as $key => $value) {
            if (in_array($key, $authplugin->userfields) || in_array($key, $customfields)) {
                $newuser->{$key} = $value;
            }
        }
    }
    if (!empty($newuser->email)) {
        if (email_is_not_allowed($newuser->email)) {
            unset($newuser->email);
        }
    }
    if (!isset($newuser->city)) {
        $newuser->city = '';
    }
    $newuser->auth = $auth;
    $newuser->username = $username;
    // Fix for MDL-8480
    // user CFG lang for user if $newuser->lang is empty
    // or $user->lang is not an installed language.
    if (empty($newuser->lang) || !get_string_manager()->translation_exists($newuser->lang)) {
        $newuser->lang = $CFG->lang;
    }
    $newuser->confirmed = 1;
    $newuser->lastip = getremoteaddr();
    $newuser->timecreated = time();
    $newuser->timemodified = $newuser->timecreated;
    $newuser->mnethostid = $CFG->mnet_localhost_id;
    $newuser->id = user_create_user($newuser, false, false);
    // Save user profile data.
    profile_save_data($newuser);
    $user = get_complete_user_data('id', $newuser->id);
    if (!empty($CFG->{'auth_' . $newuser->auth . '_forcechangepassword'})) {
        set_user_preference('auth_forcepasswordchange', 1, $user);
    }
    // Set the password.
    update_internal_user_password($user, $password);
    // Trigger event.
    \core\event\user_created::create_from_userid($newuser->id)->trigger();
    return $user;
}
开发者ID:lucaboesch,项目名称:moodle,代码行数:62,代码来源:moodlelib.php


注:本文中的email_is_not_allowed函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。