/**
  * Validate the avatar specified in the request, to ensure it is registered to a Moodle account.
  * (Also ensures that avatar details were in fact provided in the request).
  * This is effectively a less strict version of {@link validated_user()}, which also checks enrolment and such like.
  * This function will NOT perform auto-registration or auto-enrolment.
  * @param bool $require If true, the script will be terminated with an error message if validation fails
  * @return bool Returns true if validation was successful. Returns false on failure (unless $require was true).
  * @see SloodleSession::validate_user()
  */
 function validate_avatar($require = true)
 {
     // Attempt to fetch avatar details
     $sloodleuuid = $this->request->get_avatar_uuid(false);
     $sloodleavname = $this->request->get_avatar_name(false);
     // We need at least one of the values
     if (empty($sloodleuuid) && empty($sloodleavname)) {
         if ($require) {
             $this->response->quick_output(-311, 'USER_AUTH', 'Require avatar UUID and/or name.', false);
             exit;
         }
         return false;
     }
     // Attempt to find an avatar matching the given details
     $rec = false;
     if (!empty($sloodleuuid)) {
         $rec = get_record('sloodle_users', 'uuid', $sloodleuuid);
     }
     if (!$rec) {
         $rec = get_record('sloodle_users', 'avname', $sloodleavname);
     }
     // Did we find a matching entry?
     if (!$rec) {
         // No - avatar is not validated
         if ($require) {
             $this->response->quick_output(-321, 'USER_AUTH', 'Require avatar UUID and/or name.', false);
             exit;
         }
         return false;
     }
     return true;
 }
예제 #2
0
/**
 * Obtains a named HTTP request parameter, and terminates script with an error message if it was not provided.
 * This is a 'Sloodle-friendly' version of the Moodle "required_param" function.
 * Instead of terminate the script with an HTML-formatted error message, it will terminate with a message
 *  which conforms for the {@link http://slisweb.sjsu.edu/sl/index.php/Sloodle_communications_specification Sloodle communications specification},
 *  making it suitable for use in {@link http://slisweb.sjsu.edu/sl/index.php/Linker_Script linker scripts}.
 *
 * @param string $parname Name of the HTTP request parameter to fetch.
 * @param int $type Type of parameter expected, such as "PARAM_RAW". See Moodle documentation for a complete list.
 * @return mixed The appropriately parsed and/or cleaned parameter value, if it was found.
 * @deprecated
 */
function sloodle_required_param($parname, $type)
{
    exit('ERROR: deprecated function \'sloodle_required_param()\' called.');
    // Attempt to get the parameter
    $par = optional_param($parname, null, $type);
    // Was it provided?
    if (is_null($par)) {
        // No - report the error
        SloodleResponse::quick_output(-811, "SYSTEM", "Expected request parameter '{$parname}'.");
        exit;
    }
    return $par;
}