Agree the site policy for the current user.

@return array of warnings and status result
@since Moodle 3.2
@throws moodle_exception
354011
public static function agree_site_policy() {
        global $CFG, $DB, $USER;

        $warnings = array();

        $context = context_system::instance();
        try {
            // We expect an exception here since the user didn't agree the site policy yet.
            self::validate_context($context);
        } catch (Exception $e) {
            // We are expecting only a sitepolicynotagreed exception.
            if (!($e instanceof moodle_exception) or $e->errorcode != 'sitepolicynotagreed') {
                // In case we receive a different exception, throw it.
                throw $e;
            }
        }

        $manager = new \core_privacy\local\sitepolicy\manager();
        if (!empty($USER->policyagreed)) {
            $status = false;
            $warnings[] = array(
                'item' => 'user',
                'itemid' => $USER->id,
                'warningcode' => 'alreadyagreed',
                'message' => 'The user already agreed the site policy.'
            );
        } else if (!$manager->is_defined()) {
            $status = false;
            $warnings[] = array(
                'item' => 'user',
                'itemid' => $USER->id,
                'warningcode' => 'nositepolicy',
                'message' => 'The site does not have a site policy configured.'
            );
        } else {
            $status = $manager->accept();
        }

        $result = array();
        $result['status'] = $status;
        $result['warnings'] = $warnings;
        return $result;
    }
1255975
public function rules()
    {
        $attributes = [
            'title' => 'required',
            'text'  => 'required',
        ];

        $rules = $this->buildLocalizedRules($attributes);

        return array_merge($rules, [
            'id'           => 'exists:site_pages,id',
            'slug'         => 'required|alpha_dash|unique:site_pages,slug,'.$this->route('sites'),
            'published_at' => 'date',
            'concealed_at' => 'date',
        ]);
    }
1341143
public function behaviors() {

		$behaviours	= parent::behaviors();

		$behaviours[ 'verbs' ][ 'actions' ][ 'index' ] = [ 'get' ];
		$behaviours[ 'verbs' ][ 'actions' ][ 'maintenance' ] = [ 'get' ];
		$behaviours[ 'verbs' ][ 'actions' ][ 'register' ] = [ 'get', 'post' ];
		$behaviours[ 'verbs' ][ 'actions' ][ 'confirm-account' ] = [ 'get', 'post' ];
		$behaviours[ 'verbs' ][ 'actions' ][ 'join-site' ] = [ 'get', 'post' ];
		$behaviours[ 'verbs' ][ 'actions' ][ 'feedback' ] = [ 'get' ];
		$behaviours[ 'verbs' ][ 'actions' ][ 'testimonial' ] = [ 'get' ];

		return $behaviours;
	}
1013291
static public function getStatuses()
    {
        return [
            self::STATUS_NEW => \Yii::t('skeeks/reviews2', "New"),
            self::STATUS_PROCESSED => \Yii::t('skeeks/reviews2', "In Progress"),
            self::STATUS_ALLOWED => \Yii::t('skeeks/reviews2', "Approved"),
            self::STATUS_CANCELED => \Yii::t('skeeks/reviews2', "Rejected"),
        ];
    }
867105
public function rules()
    {

        return [
            'user_id'  => 'required|exists:users,id',
            'group_id' => [
                'required',
                'exists:groups,id',
                function ($attribute, $value, $fail) {

                    // retrieve admin group, if any
                    $admin_group = Group::whereHas('users', function ($query) {

                        $query->where('name', 'admin');
                    })->first();

                    // if the requested group_id is matching the admin one; skip
                    if (! is_null($admin_group) && $admin_group->id == $value) {
                        return $fail('You cannot attach any user to the admin group relationship.');
                    }
                },
            ],
        ];
    }
751756
public function getUserLoginAttempt()
    {
        if (!$this->_attempt) {
            $this->_attempt = new AdminLoginAttempt;
            $this->_attempt->key = $this->getKey();
        }
        return $this->_attempt;
    }
880540
protected function prepare_global_page_access() {
        global $CFG, $PAGE, $SITE, $USER;

        $myurl = new moodle_url('/admin/tool/policy/view.php', [
            'policyid' => $this->policy->policyid,
            'versionid' => $this->policy->id,
            'returnurl' => $this->returnurl,
            'behalfid' => $this->behalfid,
            'manage' => $this->manage,
            'numpolicy' => $this->numpolicy,
            'totalpolicies' => $this->totalpolicies,
        ]);

        if ($this->manage) {
            require_once($CFG->libdir.'/adminlib.php');
            admin_externalpage_setup('tool_policy_managedocs', '', null, $myurl);
            require_capability('tool/policy:managedocs', context_system::instance());
            $PAGE->navbar->add(format_string($this->policy->name),
                new moodle_url('/admin/tool/policy/managedocs.php', ['id' => $this->policy->policyid]));
        } else {
            if ($this->policy->status != policy_version::STATUS_ACTIVE) {
                require_login();
            } else if (isguestuser() || empty($USER->id) || !$USER->policyagreed) {
                // Disable notifications for new users, guests or users who haven't agreed to the policies.
                $PAGE->set_popup_notification_allowed(false);
            }
            $PAGE->set_url($myurl);
            $PAGE->set_heading($SITE->fullname);
            $PAGE->set_title(get_string('policiesagreements', 'tool_policy'));
            $PAGE->navbar->add(get_string('policiesagreements', 'tool_policy'), new moodle_url('/admin/tool/policy/index.php'));
            $PAGE->navbar->add(format_string($this->policy->name));
        }

        if (!api::can_user_view_policy_version($this->policy, $this->behalfid)) {
            throw new moodle_exception('accessdenied', 'tool_policy');
        }
    }
522909
protected function defaultChecker(){
            $allowed = $this->getAlloweds();
            $useragent = $this->getValue();
            if('*' === $allowed){
                return true;
            }

            $allowed = (array) $allowed;
            if (is_array($allowed)) {
                foreach($allowed as $allow)
                {
                    if (strstr($useragent, $allow)) {
                        return true;
                    }
                }
            }

            return false;
        }
1313697
public function vote()
    {
        $request = $this->requestStack->getMasterRequest();
        if (($this->forceAccountRecovery['enabled'] || $this->blockPages['enabled']) && $request) {
            $route = $request->get('_route');
            $ipAddress = $request->getClientIp();

            $this->blockPages['routes'][] = $this->routeLogin['name'];
            if ($this->blockPages['enabled'] && in_array($route, $this->blockPages['routes'])) {
                // Get number of failed login attempts.
                $attempts = $this->loginFailureTracker->getAttempts($ipAddress, $this->blockPages['duration_in_minutes']);

                if (count($attempts) >= $this->blockPages['after_attempts']) {
                    // You have too many failed login attempts, login access is temporarily blocked.
                    return self::ACCESS_DENIED_BLOCK;
                }
            }

            $this->forceAccountRecovery['routes'][] = $this->routeLogin['name'];
            if ($this->forceAccountRecovery['enabled'] && in_array($route, $this->forceAccountRecovery['routes'])) {
                // Get number of failed login attempts.
                $attempts = $this->loginFailureTracker->getAttempts($ipAddress, $this->forceAccountRecovery['duration_in_minutes']);

                if (count($attempts) >= $this->forceAccountRecovery['after_attempts']) {
                    // You have too many failed login attempts, login access is temporarily blocked, go recover your account.
                    return self::ACCESS_DENIED_DEFER;
                }
            }
        }

        return self::ACCESS_ALLOWED;
    }
113878
public function rules(): array
    {
        $user = $this->user($this->route('guard'));
        $user->updateRulesUniques();

        return $user->getRules();
    }
79235
public function pass()
    {
        $action      = $this->getParameter('action');

        return $this->Permissions->checkPermission($action, $this->getLocal('SiteSlug'));
    }
598211
protected function isAllowed()
    {
        /** @var  \Arcanesoft\Contracts\Auth\Models\User  $user */
        if (is_null($user = auth()->user()))
            return false;

        return $user->isAdmin() || $user->isModerator();
    }
584413
public function getRecommLists()
    {
        if ($this->_aUserRecommLists === null) {
            $this->_aUserRecommLists = false;
            if (($oUser = $this->getUser())) {
                // recommendation list
                $this->_aUserRecommLists = $oUser->getUserRecommLists();
            }
        }

        return $this->_aUserRecommLists;
    }
1362126
public function actionThumb()
    {
        if (!Yii::$app->request->isAjax) {
            return $this->redirect(['forum/index']);
        }

        $data = [
            'error' => 1,
            'msg' => Html::tag('span',
                Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign'])
                . ' ' . Yii::t('podium/view', 'Error while voting on this post!'),
                ['class' => 'text-danger']
            ),
        ];

        if ($this->module->user->isGuest) {
            $data['msg'] = Html::tag('span',
                Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign'])
                . ' ' . Yii::t('podium/view', 'Please sign in to vote on this post'),
                ['class' => 'text-info']
            );
            return Json::encode($data);
        }

        $postId = Yii::$app->request->post('post');
        $thumb = Yii::$app->request->post('thumb');

        if (is_numeric($postId) && $postId > 0 && in_array($thumb, ['up', 'down'])) {
            $post = Post::find()->where(['id' => $postId])->limit(1)->one();
            if ($post) {
                if ($post->thread->locked) {
                    $data['msg'] = Html::tag('span',
                        Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign'])
                        . ' ' . Yii::t('podium/view', 'This thread is locked.'),
                        ['class' => 'text-info']
                    );
                    return Json::encode($data);
                }

                if ($post->author_id == User::loggedId()) {
                    $data['msg'] = Html::tag('span',
                        Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign'])
                        . ' ' . Yii::t('podium/view', 'You can not vote on your own post!'),
                        ['class' => 'text-info']
                    );
                    return Json::encode($data);
                }

                $count = 0;
                $votes = $this->module->podiumCache->get('user.votes.' . User::loggedId());
                if ($votes !== false) {
                    if ($votes['expire'] < time()) {
                        $votes = false;
                    } elseif ($votes['count'] >= 10) {
                        $data['msg'] = Html::tag('span',
                            Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign'])
                            . ' ' . Yii::t('podium/view', '{max} votes per hour limit reached!', ['max' => 10]),
                            ['class' => 'text-danger']
                        );
                        return Json::encode($data);
                    } else {
                        $count = $votes['count'];
                    }
                }

                if ($post->podiumThumb($thumb == 'up', $count)) {
                    $data = [
                        'error' => 0,
                        'likes' => '+' . $post->likes,
                        'dislikes' => '-' . $post->dislikes,
                        'summ' => $post->likes - $post->dislikes,
                        'msg' => Html::tag('span',
                            Html::tag('span', '', ['class' => 'glyphicon glyphicon-ok-circle'])
                            . ' ' . Yii::t('podium/view', 'Your vote has been saved!'),
                            ['class' => 'text-success']
                        ),
                    ];
                }
            }
        }
        return Json::encode($data);
    }
1056086
protected function rules() {
        return [
            new Rule('Order ID Exists', function(array $subject) {
                $response   = SubjectReader::readResponse($subject);
                $orderId    = $response['message']['trackId'];
                $order      = $this->orderFactory->create()->loadByIncrementId($orderId);

                return ! $order->isEmpty();
            }, __('Checkout.com track ID is not matching to any orders.') ),
        ];
    }
485585
public static function getAccept(): array
    {
        if (!self::$accept) {
            // get header from request
            self::$accept = self::parseAcceptHeader(self::getHeader('Accept'));
        }
        return self::$accept;
    }
154765
public function admin()
    {
        $currentuser = $this->getUser();
        $users = $this->users()->getUsers();
        $sessions = $this->accessControl()->getActiveSessions();

        foreach ($users as $name => $user) {
            if (($key = array_search(Permissions::ROLE_EVERYONE, $user['roles'], true)) !== false) {
                unset($users[$name]['roles'][$key]);
            }
        }

        $context = [
            'currentuser' => $currentuser,
            'users'       => $users,
            'sessions'    => $sessions,
        ];

        return $this->render('@bolt/users/users.twig', $context);
    }