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


PHP core_user::require_active_user方法代码示例

本文整理汇总了PHP中core_user::require_active_user方法的典型用法代码示例。如果您正苦于以下问题:PHP core_user::require_active_user方法的具体用法?PHP core_user::require_active_user怎么用?PHP core_user::require_active_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在core_user的用法示例。


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

示例1: get_user_badges

 /**
  * Returns the list of badges awarded to a user.
  *
  * @param int $userid       user id
  * @param int $courseid     course id
  * @param int $page         page of records to return
  * @param int $perpage      number of records to return per page
  * @param string  $search   a simple string to search for
  * @param bool $onlypublic  whether to return only public badges
  * @return array array containing warnings and the awarded badges
  * @since  Moodle 3.1
  * @throws moodle_exception
  */
 public static function get_user_badges($userid = 0, $courseid = 0, $page = 0, $perpage = 0, $search = '', $onlypublic = false)
 {
     global $CFG, $USER;
     $warnings = array();
     $params = array('userid' => $userid, 'courseid' => $courseid, 'page' => $page, 'perpage' => $perpage, 'search' => $search, 'onlypublic' => $onlypublic);
     $params = self::validate_parameters(self::get_user_badges_parameters(), $params);
     if (empty($CFG->enablebadges)) {
         throw new moodle_exception('badgesdisabled', 'badges');
     }
     if (empty($CFG->badges_allowcoursebadges) && $params['courseid'] != 0) {
         throw new moodle_exception('coursebadgesdisabled', 'badges');
     }
     // Default value for userid.
     if (empty($params['userid'])) {
         $params['userid'] = $USER->id;
     }
     // Validate the user.
     $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
     core_user::require_active_user($user);
     $usercontext = context_user::instance($user->id);
     self::validate_context($usercontext);
     if ($USER->id != $user->id) {
         require_capability('moodle/badges:viewotherbadges', $usercontext);
         // We are looking other user's badges, we must retrieve only public badges.
         $params['onlypublic'] = true;
     }
     $userbadges = badges_get_user_badges($user->id, $params['courseid'], $params['page'], $params['perpage'], $params['search'], $params['onlypublic']);
     $result = array();
     $result['badges'] = array();
     $result['warnings'] = $warnings;
     foreach ($userbadges as $badge) {
         $context = $badge->type == BADGE_TYPE_SITE ? context_system::instance() : context_course::instance($badge->courseid);
         $badge->badgeurl = moodle_url::make_webservice_pluginfile_url($context->id, 'badges', 'badgeimage', $badge->id, '/', 'f1')->out(false);
         // Return all the information if we are requesting our own badges.
         // Or, if we have permissions for configuring badges in the badge context.
         if ($USER->id == $user->id or has_capability('moodle/badges:configuredetails', $context)) {
             $result['badges'][] = (array) $badge;
         } else {
             $result['badges'][] = array('name' => $badge->name, 'description' => $badge->description, 'badgeurl' => $badge->badgeurl, 'issuername' => $badge->issuername, 'issuerurl' => $badge->issuerurl, 'issuercontact' => $badge->issuercontact, 'uniquehash' => $badge->uniquehash, 'dateissued' => $badge->dateissued, 'dateexpire' => $badge->dateexpire);
         }
     }
     return $result;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:56,代码来源:external.php

示例2: view_user_profile

 /**
  * Trigger the user profile viewed event.
  *
  * @param int $userid id of user
  * @param int $courseid id of course
  * @return array of warnings and status result
  * @since Moodle 2.9
  * @throws moodle_exception
  */
 public static function view_user_profile($userid, $courseid = 0)
 {
     global $CFG, $USER;
     require_once $CFG->dirroot . "/user/profile/lib.php";
     $params = self::validate_parameters(self::view_user_profile_parameters(), array('userid' => $userid, 'courseid' => $courseid));
     $warnings = array();
     if (empty($params['userid'])) {
         $params['userid'] = $USER->id;
     }
     if (empty($params['courseid'])) {
         $params['courseid'] = SITEID;
     }
     $course = get_course($params['courseid']);
     $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
     core_user::require_active_user($user);
     if ($course->id == SITEID) {
         $coursecontext = context_system::instance();
     } else {
         $coursecontext = context_course::instance($course->id);
     }
     self::validate_context($coursecontext);
     $currentuser = $USER->id == $user->id;
     $usercontext = context_user::instance($user->id);
     if (!$currentuser and !has_capability('moodle/user:viewdetails', $coursecontext) and !has_capability('moodle/user:viewdetails', $usercontext)) {
         throw new moodle_exception('cannotviewprofile');
     }
     // Case like user/profile.php.
     if ($course->id == SITEID) {
         profile_view($user, $usercontext);
     } else {
         // Case like user/view.php.
         if (!$currentuser and !can_access_course($course, $user, '', true)) {
             throw new moodle_exception('notenrolledprofile');
         }
         profile_view($user, $coursecontext, $course);
     }
     $result = array();
     $result['status'] = true;
     $result['warnings'] = $warnings;
     return $result;
 }
开发者ID:sirromas,项目名称:lms,代码行数:50,代码来源:externallib.php

示例3: get_user_devices

 /**
  * Return the list of mobile devices that are registered in Moodle for the given user.
  *
  * @param  string  $appid  app unique id (usually a reversed domain)
  * @param  integer $userid the user id, 0 for current user
  * @return array warnings and devices
  * @throws moodle_exception
  * @since Moodle 3.2
  */
 public static function get_user_devices($appid, $userid = 0)
 {
     global $USER;
     $params = self::validate_parameters(self::get_user_devices_parameters(), array('appid' => $appid, 'userid' => $userid));
     $context = context_system::instance();
     self::validate_context($context);
     if (empty($params['userid'])) {
         $user = $USER;
     } else {
         $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
         core_user::require_active_user($user);
         // Allow only admins to retrieve other users devices.
         if ($user->id != $USER->id) {
             require_capability('moodle/site:config', $context);
         }
     }
     $warnings = array();
     $devices = array();
     // Check if mobile notifications are enabled.
     if (!self::is_system_configured()) {
         $warnings[] = array('item' => 'user', 'itemid' => $user->id, 'warningcode' => 'systemnotconfigured', 'message' => 'Mobile notifications are not configured');
     } else {
         // We catch exceptions here because get_user_devices may try to connect to Airnotifier.
         try {
             $manager = new message_airnotifier_manager();
             $devices = $manager->get_user_devices($appid, $user->id);
         } catch (Exception $e) {
             $warnings[] = array('item' => 'user', 'itemid' => $user->id, 'warningcode' => 'errorgettingdevices', 'message' => $e->getMessage());
         }
     }
     return array('devices' => $devices, 'warnings' => $warnings);
 }
开发者ID:gabrielrosset,项目名称:moodle,代码行数:41,代码来源:externallib.php

示例4: moodle_exception

if (!$CFG->enablewebservices) {
    throw new moodle_exception('enablewsdescription', 'webservice');
}
// Check if the plugin is properly configured.
$typeoflogin = get_config('tool_mobile', 'typeoflogin');
if ($typeoflogin != tool_mobile\api::LOGIN_VIA_BROWSER and $typeoflogin != tool_mobile\api::LOGIN_VIA_EMBEDDED_BROWSER) {
    throw new moodle_exception('pluginnotenabledorconfigured', 'tool_mobile');
}
// Check if the service exists and is enabled.
$service = $DB->get_record('external_services', array('shortname' => $serviceshortname, 'enabled' => 1));
if (empty($service)) {
    throw new moodle_exception('servicenotavailable', 'webservice');
}
require_login(0, false);
// Require an active user: not guest, not suspended.
core_user::require_active_user($USER);
// Get an existing token or create a new one.
$token = external_generate_token_for_current_user($service);
// Log token access.
$DB->set_field('external_tokens', 'lastaccess', time(), array('id' => $token->id));
$params = array('objectid' => $token->id);
$event = \core\event\webservice_token_sent::create($params);
$event->add_record_snapshot('external_tokens', $token);
$event->trigger();
// Passport is generated in the mobile app, so the app opening can be validated using that variable.
// Passports are valid only one time, it's deleted in the app once used.
$siteid = md5($CFG->wwwroot . $passport);
$apptoken = base64_encode($siteid . ':::' . $token->token);
// Redirect using the custom URL scheme checking first if a URL scheme is forced in the site settings.
$forcedurlscheme = get_config('tool_mobile', 'forcedurlscheme');
if (!empty($forcedurlscheme)) {
开发者ID:janeklb,项目名称:moodle,代码行数:31,代码来源:launch.php

示例5: get_user_preferences

 /**
  * Return user preferences.
  *
  * @param string $name preference name, empty for all
  * @param int $userid id of the user, 0 for current user
  * @return array of warnings and preferences
  * @since Moodle 3.2
  * @throws moodle_exception
  */
 public static function get_user_preferences($name = '', $userid = 0)
 {
     global $USER;
     $params = self::validate_parameters(self::get_user_preferences_parameters(), array('name' => $name, 'userid' => $userid));
     $preferences = array();
     $warnings = array();
     $context = context_system::instance();
     self::validate_context($context);
     if (empty($params['name'])) {
         $name = null;
     }
     if (empty($params['userid'])) {
         $user = null;
     } else {
         $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
         core_user::require_active_user($user);
         if ($user->id != $USER->id) {
             // Only admins can retrieve other users preferences.
             require_capability('moodle/site:config', $context);
         }
     }
     $userpreferences = get_user_preferences($name, null, $user);
     // Check if we received just one preference.
     if (!is_array($userpreferences)) {
         $userpreferences = array($name => $userpreferences);
     }
     foreach ($userpreferences as $name => $value) {
         $preferences[] = array('name' => $name, 'value' => $value);
     }
     $result = array();
     $result['preferences'] = $preferences;
     $result['warnings'] = $warnings;
     return $result;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:43,代码来源:externallib.php

示例6: delete_message

 /**
  * Deletes a message
  *
  * @param  int $messageid the message id
  * @param  int $userid the user id of who we want to delete the message for
  * @param  bool $read if is a message read (default to true)
  * @return external_description
  * @throws moodle_exception
  * @since 3.1
  */
 public static function delete_message($messageid, $userid, $read = true)
 {
     global $CFG, $DB;
     // Check if private messaging between users is allowed.
     if (empty($CFG->messaging)) {
         throw new moodle_exception('disabled', 'message');
     }
     // Warnings array, it can be empty at the end but is mandatory.
     $warnings = array();
     // Validate params.
     $params = array('messageid' => $messageid, 'userid' => $userid, 'read' => $read);
     $params = self::validate_parameters(self::delete_message_parameters(), $params);
     // Validate context.
     $context = context_system::instance();
     self::validate_context($context);
     $messagestable = $params['read'] ? 'message_read' : 'message';
     $message = $DB->get_record($messagestable, array('id' => $params['messageid']), '*', MUST_EXIST);
     $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
     core_user::require_active_user($user);
     $status = false;
     if (message_can_delete_message($message, $user->id)) {
         $status = message_delete_message($message, $user->id);
     } else {
         throw new moodle_exception('You do not have permission to delete this message');
     }
     $results = array('status' => $status, 'warnings' => $warnings);
     return $results;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:38,代码来源:externallib.php

示例7: test_require_active_user

 /**
  * Test require_active_user
  */
 public function test_require_active_user()
 {
     global $DB;
     // Create a default user for the test.
     $userexpected = $this->getDataGenerator()->create_user();
     // Simple case, all good.
     core_user::require_active_user($userexpected, true, true);
     // Set user not confirmed.
     $DB->set_field('user', 'confirmed', 0, array('id' => $userexpected->id));
     try {
         core_user::require_active_user($userexpected);
     } catch (moodle_exception $e) {
         $this->assertEquals('usernotconfirmed', $e->errorcode);
     }
     $DB->set_field('user', 'confirmed', 1, array('id' => $userexpected->id));
     // Set nologin auth method.
     $DB->set_field('user', 'auth', 'nologin', array('id' => $userexpected->id));
     try {
         core_user::require_active_user($userexpected, false, true);
     } catch (moodle_exception $e) {
         $this->assertEquals('suspended', $e->errorcode);
     }
     // Check no exceptions are thrown if we don't specify to check suspended.
     core_user::require_active_user($userexpected);
     $DB->set_field('user', 'auth', 'manual', array('id' => $userexpected->id));
     // Set user suspended.
     $DB->set_field('user', 'suspended', 1, array('id' => $userexpected->id));
     try {
         core_user::require_active_user($userexpected, true);
     } catch (moodle_exception $e) {
         $this->assertEquals('suspended', $e->errorcode);
     }
     // Check no exceptions are thrown if we don't specify to check suspended.
     core_user::require_active_user($userexpected);
     // Delete user.
     delete_user($userexpected);
     try {
         core_user::require_active_user($userexpected);
     } catch (moodle_exception $e) {
         $this->assertEquals('userdeleted', $e->errorcode);
     }
     // Use a not real user.
     $noreplyuser = core_user::get_noreply_user();
     try {
         core_user::require_active_user($noreplyuser, true);
     } catch (moodle_exception $e) {
         $this->assertEquals('invaliduser', $e->errorcode);
     }
     // Get the guest user.
     $guestuser = $DB->get_record('user', array('username' => 'guest'));
     try {
         core_user::require_active_user($guestuser, true);
     } catch (moodle_exception $e) {
         $this->assertEquals('guestsarenotallowed', $e->errorcode);
     }
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:59,代码来源:user_test.php

示例8: get_scorm_sco_tracks

 /**
  * Retrieves SCO tracking data for the given user id and attempt number
  *
  * @param int $scoid the sco id
  * @param int $userid the user id
  * @param int $attempt the attempt number
  * @return array warnings and the scoes data
  * @since Moodle 3.0
  */
 public static function get_scorm_sco_tracks($scoid, $userid, $attempt = 0)
 {
     global $USER, $DB;
     $params = self::validate_parameters(self::get_scorm_sco_tracks_parameters(), array('scoid' => $scoid, 'userid' => $userid, 'attempt' => $attempt));
     $tracks = array();
     $warnings = array();
     $sco = scorm_get_sco($params['scoid'], SCO_ONLY);
     if (!$sco) {
         throw new moodle_exception('cannotfindsco', 'scorm');
     }
     $scorm = $DB->get_record('scorm', array('id' => $sco->scorm), '*', MUST_EXIST);
     $cm = get_coursemodule_from_instance('scorm', $scorm->id);
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
     core_user::require_active_user($user);
     // Extra checks so only users with permissions can view other users attempts.
     if ($USER->id != $user->id) {
         require_capability('mod/scorm:viewreport', $context);
     }
     scorm_require_available($scorm, true, $context);
     if (empty($params['attempt'])) {
         $params['attempt'] = scorm_get_last_attempt($scorm->id, $user->id);
     }
     $attempted = false;
     if ($scormtracks = scorm_get_tracks($sco->id, $params['userid'], $params['attempt'])) {
         // Check if attempted.
         if ($scormtracks->status != '') {
             $attempted = true;
             foreach ($scormtracks as $element => $value) {
                 $tracks[] = array('element' => $element, 'value' => $value);
             }
         }
     }
     if (!$attempted) {
         $warnings[] = array('item' => 'attempt', 'itemid' => $params['attempt'], 'warningcode' => 'notattempted', 'message' => get_string('notattempted', 'scorm'));
     }
     $result = array();
     $result['data']['attempt'] = $params['attempt'];
     $result['data']['tracks'] = $tracks;
     $result['warnings'] = $warnings;
     return $result;
 }
开发者ID:matiasma,项目名称:moodle,代码行数:52,代码来源:external.php

示例9: validate_preferences_permissions

 /**
  * Check that the user has enough permission to retrieve message or notifications preferences.
  *
  * @param  int $userid the user id requesting the preferences
  * @return stdClass full user object
  * @throws moodle_exception
  * @since  Moodle 3.2
  */
 protected static function validate_preferences_permissions($userid)
 {
     global $USER;
     if (empty($userid)) {
         $user = $USER;
     } else {
         $user = core_user::get_user($userid, '*', MUST_EXIST);
         core_user::require_active_user($user);
     }
     $systemcontext = context_system::instance();
     self::validate_context($systemcontext);
     // Check access control.
     if ($user->id == $USER->id) {
         // Editing own message profile.
         require_capability('moodle/user:editownmessageprofile', $systemcontext);
     } else {
         // Teachers, parents, etc.
         $personalcontext = context_user::instance($user->id);
         require_capability('moodle/user:editmessageprofile', $personalcontext);
     }
     return $user;
 }
开发者ID:lucaboesch,项目名称:moodle,代码行数:30,代码来源:externallib.php

示例10: external_generate_token_for_current_user

/**
 * Generate or return an existing token for the current authenticated user.
 * This function is used for creating a valid token for users authenticathing via login/token.php or admin/tool/mobile/launch.php.
 *
 * @param stdClass $service external service object
 * @return stdClass token object
 * @since Moodle 3.2
 * @throws moodle_exception
 */
function external_generate_token_for_current_user($service)
{
    global $DB, $USER;
    core_user::require_active_user($USER, true, true);
    // Check if there is any required system capability.
    if ($service->requiredcapability and !has_capability($service->requiredcapability, context_system::instance())) {
        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', '', $service->shortname);
        }
        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.
    $conditions = array('userid' => $USER->id, 'externalserviceid' => $service->id, 'tokentype' => EXTERNAL_TOKEN_PERMANENT);
    $tokens = $DB->get_records('external_tokens', $conditions, 'timecreated ASC');
    // 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)) {
            if (!\core\session\manager::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 is not valid anymore.
        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 {
        $context = context_system::instance();
        $isofficialservice = $service->shortname == MOODLE_OFFICIAL_MOBILE_SERVICE;
        if ($isofficialservice and has_capability('moodle/webservice:createmobiletoken', $context) or !is_siteadmin($USER) && has_capability('moodle/webservice:createtoken', $context)) {
            // Create a new token.
            $token = new stdClass();
            $token->token = md5(uniqid(rand(), 1));
            $token->userid = $USER->id;
            $token->tokentype = EXTERNAL_TOKEN_PERMANENT;
            $token->contextid = context_system::instance()->id;
            $token->creatorid = $USER->id;
            $token->timecreated = time();
            $token->externalserviceid = $service->id;
            // MDL-43119 Token valid for 3 months (12 weeks).
            $token->validuntil = $token->timecreated + 12 * WEEKSECS;
            $token->iprestriction = null;
            $token->sid = null;
            $token->lastaccess = null;
            // Generate the private token, it must be transmitted only via https.
            $token->privatetoken = random_string(64);
            $token->id = $DB->insert_record('external_tokens', $token);
            $eventtoken = clone $token;
            $eventtoken->privatetoken = null;
            $params = array('objectid' => $eventtoken->id, 'relateduserid' => $USER->id, 'other' => array('auto' => true));
            $event = \core\event\webservice_token_created::create($params);
            $event->add_record_snapshot('external_tokens', $eventtoken);
            $event->trigger();
        } else {
            throw new moodle_exception('cannotcreatetoken', 'webservice', '', $service->shortname);
        }
    }
    return $token;
}
开发者ID:lucaboesch,项目名称:moodle,代码行数:94,代码来源:externallib.php

示例11: view_grade_report

 /**
  * Trigger the user report events, do the same that the web interface view of the report
  *
  * @param int $courseid id of course
  * @param int $userid id of the user the report belongs to
  * @return array of warnings and status result
  * @since Moodle 3.2
  * @throws moodle_exception
  */
 public static function view_grade_report($courseid, $userid = 0)
 {
     global $USER;
     $params = self::validate_parameters(self::view_grade_report_parameters(), array('courseid' => $courseid, 'userid' => $userid));
     $warnings = array();
     $course = get_course($params['courseid']);
     $context = context_course::instance($course->id);
     self::validate_context($context);
     $userid = $params['userid'];
     if (empty($userid)) {
         $userid = $USER->id;
     } else {
         $user = core_user::get_user($userid, '*', MUST_EXIST);
         core_user::require_active_user($user);
     }
     $systemcontext = context_system::instance();
     $personalcontext = context_user::instance($userid);
     $access = grade_report_overview::check_access($systemcontext, $context, $personalcontext, $course, $userid);
     if (!$access) {
         throw new moodle_exception('nopermissiontoviewgrades', 'error');
     }
     grade_report_overview::viewed($context, $course->id, $userid);
     $result = array();
     $result['status'] = true;
     $result['warnings'] = $warnings;
     return $result;
 }
开发者ID:dg711,项目名称:moodle,代码行数:36,代码来源:external.php

示例12: view_notes

    /**
     * Simulates the web interface view of notes/index.php: trigger events
     *
     * @param int $courseid id of the course
     * @param int $userid id of the user
     * @return array of warnings and status result
     * @since Moodle 2.9
     * @throws moodle_exception
     */
    public static function view_notes($courseid, $userid = 0) {
        global $CFG;
        require_once($CFG->dirroot . "/notes/lib.php");

        if (empty($CFG->enablenotes)) {
            throw new moodle_exception('notesdisabled', 'notes');
        }

        $warnings = array();
        $arrayparams = array(
            'courseid' => $courseid,
            'userid' => $userid
        );
        $params = self::validate_parameters(self::view_notes_parameters(), $arrayparams);

        if (empty($params['courseid'])) {
            $params['courseid'] = SITEID;
        }

        $course = get_course($params['courseid']);

        if ($course->id == SITEID) {
            $context = context_system::instance();
        } else {
            $context = context_course::instance($course->id);
        }

        // First of all, validate the context before do further permission checks.
        self::validate_context($context);
        require_capability('moodle/notes:view', $context);

        if (!empty($params['userid'])) {
            $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
            core_user::require_active_user($user);

            if ($course->id != SITEID and !can_access_course($course, $user, '', true)) {
                throw new moodle_exception('notenrolledprofile');
            }
        }

        note_view($context, $params['userid']);

        $result = array();
        $result['status'] = true;
        $result['warnings'] = $warnings;
        return $result;

    }
开发者ID:uniedpa,项目名称:moodle,代码行数:57,代码来源:externallib.php

示例13: update_picture

 /**
  * Update or delete the user picture in the site
  *
  * @param  int  $draftitemid id of the user draft file to use as image
  * @param  bool $delete      if we should delete the user picture
  * @param  int $userid       id of the user, 0 for current user
  * @return array warnings and success status
  * @since Moodle 3.2
  * @throws moodle_exception
  */
 public static function update_picture($draftitemid, $delete = false, $userid = 0)
 {
     global $CFG, $USER, $PAGE;
     $params = self::validate_parameters(self::update_picture_parameters(), array('draftitemid' => $draftitemid, 'delete' => $delete, 'userid' => $userid));
     $context = context_system::instance();
     self::validate_context($context);
     if (!empty($CFG->disableuserimages)) {
         throw new moodle_exception('userimagesdisabled', 'admin');
     }
     if (empty($params['userid']) or $params['userid'] == $USER->id) {
         $user = $USER;
         require_capability('moodle/user:editownprofile', $context);
     } else {
         $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
         core_user::require_active_user($user);
         $personalcontext = context_user::instance($user->id);
         require_capability('moodle/user:editprofile', $personalcontext);
         if (is_siteadmin($user) and !is_siteadmin($USER)) {
             // Only admins may edit other admins.
             throw new moodle_exception('useradmineditadmin');
         }
     }
     // Load the appropriate auth plugin.
     $userauth = get_auth_plugin($user->auth);
     if (is_mnet_remote_user($user) or !$userauth->can_edit_profile() or $userauth->edit_profile_url()) {
         throw new moodle_exception('noprofileedit', 'auth');
     }
     $filemanageroptions = array('maxbytes' => $CFG->maxbytes, 'subdirs' => 0, 'maxfiles' => 1, 'accepted_types' => 'web_image');
     $user->deletepicture = $params['delete'];
     $user->imagefile = $params['draftitemid'];
     $success = core_user::update_picture($user, $filemanageroptions);
     $result = array('success' => $success, 'warnings' => array());
     if ($success) {
         $userpicture = new user_picture(core_user::get_user($user->id));
         $userpicture->size = 1;
         // Size f1.
         $result['profileimageurl'] = $userpicture->get_url($PAGE)->out(false);
     }
     return $result;
 }
开发者ID:gabrielrosset,项目名称:moodle,代码行数:50,代码来源:externallib.php

示例14: wiki_get_subwiki_by_group_and_user_with_validation

/**
 * Utility function for getting a subwiki by group and user, validating that the user can view it.
 * If the subwiki doesn't exists in DB yet it'll have id -1.
 *
 * @param stdClass $wiki The wiki.
 * @param int $groupid Group ID. 0 means the subwiki doesn't use groups.
 * @param int $userid User ID. 0 means the subwiki doesn't use users.
 * @return stdClass Subwiki. If it doesn't exists in DB yet it'll have id -1. If the user can't view the
 *                  subwiki this function will return false.
 * @since  Moodle 3.1
 * @throws moodle_exception
 */
function wiki_get_subwiki_by_group_and_user_with_validation($wiki, $groupid, $userid)
{
    global $USER, $DB;
    // Get subwiki based on group and user.
    if (!($subwiki = wiki_get_subwiki_by_group($wiki->id, $groupid, $userid))) {
        // The subwiki doesn't exist.
        // Validate if user is valid.
        if ($userid != 0) {
            $user = core_user::get_user($userid, '*', MUST_EXIST);
            core_user::require_active_user($user);
        }
        // Validate that groupid is valid.
        if ($groupid != 0 && !groups_group_exists($groupid)) {
            throw new moodle_exception('cannotfindgroup', 'error');
        }
        // Valid data but subwiki not found. We'll simulate a subwiki object to check if the user would be able to see it
        // if it existed. If he's able to see it then we'll return an empty array because the subwiki has no pages.
        $subwiki = new stdClass();
        $subwiki->id = -1;
        $subwiki->wikiid = $wiki->id;
        $subwiki->userid = $userid;
        $subwiki->groupid = $groupid;
    }
    // Check that the user can view the subwiki. This function checks capabilities.
    if (!wiki_user_can_view($subwiki, $wiki)) {
        return false;
    }
    return $subwiki;
}
开发者ID:IFPBMoodle,项目名称:moodle,代码行数:41,代码来源:locallib.php

示例15: delete_user_key

$context = context_system::instance();
$PAGE->set_context($context);
// Force https.
$PAGE->https_required();
// Check if the user is already logged-in.
if (isloggedin() and !isguestuser()) {
    delete_user_key('tool_mobile', $userid);
    if ($USER->id == $userid) {
        redirect($urltogo);
    } else {
        throw new moodle_exception('alreadyloggedin', 'error', '', format_string(fullname($USER)));
    }
}
tool_mobile\api::check_autologin_prerequisites($userid);
// Validate and delete the key.
$key = validate_user_key($key, 'tool_mobile', null);
delete_user_key('tool_mobile', $userid);
// Double check key belong to user.
if ($key->userid != $userid) {
    throw new moodle_exception('invalidkey');
}
// Key validated, now require an active user: not guest, not suspended.
$user = core_user::get_user($key->userid, '*', MUST_EXIST);
core_user::require_active_user($user, true, true);
// Do the user log-in.
if (!($user = get_complete_user_data('id', $user->id))) {
    throw new moodle_exception('cannotfinduser', '', '', $user->id);
}
complete_user_login($user);
\core\session\manager::apply_concurrent_login_limit($user->id, session_id());
redirect($urltogo);
开发者ID:dg711,项目名称:moodle,代码行数:31,代码来源:autologin.php


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