/**
  * 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
 /**
  * Quick output of data to avoid several accessor calls if the response is very basic.
  * Can be called statically to allow simple output of basic data.
  * The status code is required, but the other parameters are optional
  * If an error occurs, the LSL-friendly error message is output to the HTTP response, and the script terminated
  *
  * @param int $status_code The status code for the response (required)
  * @param string $status_descriptor The status descriptor for the response (optional - ignored if null)
  * @param mixed $data The data for the response, which can be a scalar, or a mixed array of scalars/scalar-arrays (see {@link SloodleResponse::$data}) (optional - ignored if null)
  * @param bool $static If true (default), then this function will assume it is being call statically, and construct its own response object. Otherwise, it will all the existing member data to render the output.
  * @return void
  * @access public
  */
 function quick_output($status_code, $status_descriptor = null, $data = null, $static = true)
 {
     // Is this s static call?
     if ($static) {
         // Construct and render the output of a response object
         $response = new SloodleResponse($status_code, $status_descriptor, $data);
         $response->render_to_output();
     } else {
         // Set all our data
         $this->status_code = $status_code;
         if ($status_descriptor != null) {
             $this->status_descriptor = $status_descriptor;
         }
         if ($data != null) {
             $this->add_data_line($data);
         }
         // Output it
         $this->render_to_output();
     }
 }