_id stringlengths 2 7 | title stringlengths 3 151 | partition stringclasses 3
values | text stringlengths 83 13k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q249400 | User.getIsStatus | validation | public function getIsStatus()
{
switch ($this->status) {
case User::STATUS_PENDING:
return '<div class="text-center"><span class="text-primary">Pending</span></div>';
case User::STATUS_ACTIVE:
return '<div class="text-center"><span class="text-success">Active</span></div>';
case User::STATUS_BLOCKED... | php | {
"resource": ""
} |
q249401 | User.confirm | validation | public function confirm()
{
$this->status = User::STATUS_ACTIVE;
if ($this->save(FALSE))
return TRUE;
return FALSE;
} | php | {
"resource": ""
} |
q249402 | User.block | validation | public function block()
{
$this->status = User::STATUS_BLOCKED;
if ($this->save(FALSE))
return TRUE;
return FALSE;
} | php | {
"resource": ""
} |
q249403 | User.unblock | validation | public function unblock()
{
$this->status = User::STATUS_ACTIVE;
if ($this->save(FALSE))
return TRUE;
return FALSE;
} | php | {
"resource": ""
} |
q249404 | Plugin.register | validation | static public function register()
{
// only register once
if (static::$registered === true) {
return true;
}
$kirby = kirby();
if (!class_exists('Kirby\Component\Template')) {
throw new Exception('The Kirby Twig plugin requires Kirby 2.3 or higher. Cur... | php | {
"resource": ""
} |
q249405 | Plugin.render | validation | static public function render($template, $userData)
{
if (!is_string($template)) return '';
$path = strlen($template) <= 256 ? trim($template) : '';
$data = array_merge(Tpl::$data, is_array($userData) ? $userData : []);
$twig = TwigEnv::instance();
// treat template as a pat... | php | {
"resource": ""
} |
q249406 | Twig_Compiler.compile | validation | public function compile(Twig_NodeInterface $node, $indentation = 0)
{
$this->lastLine = null;
$this->source = '';
$this->debugInfo = array();
$this->sourceOffset = 0;
// source code starts at 1 (as we then increment it when we encounter new lines)
$this->sourceLine = ... | php | {
"resource": ""
} |
q249407 | Twig_Compiler.write | validation | public function write()
{
$strings = func_get_args();
foreach ($strings as $string) {
$this->source .= str_repeat(' ', $this->indentation * 4).$string;
}
return $this;
} | php | {
"resource": ""
} |
q249408 | Twig_Compiler.addIndentation | validation | public function addIndentation()
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use write(\'\') instead.', E_USER_DEPRECATED);
$this->source .= str_repeat(' ', $this->indentation * 4);
return $this;
} | php | {
"resource": ""
} |
q249409 | Twig_Compiler.outdent | validation | public function outdent($step = 1)
{
// can't outdent by more steps than the current indentation level
if ($this->indentation < $step) {
throw new LogicException('Unable to call outdent() as the indentation would become negative.');
}
$this->indentation -= $step;
... | php | {
"resource": ""
} |
q249410 | Twig_Autoloader.register | validation | public static function register($prepend = false)
{
@trigger_error('Using Twig_Autoloader is deprecated since version 1.21. Use Composer instead.', E_USER_DEPRECATED);
if (PHP_VERSION_ID < 50300) {
spl_autoload_register(array(__CLASS__, 'autoload'));
} else {
spl_aut... | php | {
"resource": ""
} |
q249411 | AccountRecoverPasswordForm.recoverPassword | validation | public function recoverPassword()
{
$user = User::findOne(['email' => $this->email]);
if ($user != NULL) {
$user->password_reset_token = Yii::$app->getSecurity()->generateRandomString() . '_' . time();
$user->save(FALSE);
}
// Sends recovery mail
Mailer::sendRecoveryMessage($user);
Yii::$... | php | {
"resource": ""
} |
q249412 | TwigEnv.renderString | validation | public function renderString($tplString='', $tplData=[])
{
try {
return $this->twig->createTemplate($tplString)->render($tplData);
}
catch (Twig_Error $err) {
return $this->error($err, false, $tplString);
}
} | php | {
"resource": ""
} |
q249413 | TwigEnv.getSourceExcerpt | validation | private function getSourceExcerpt($source='', $line=1, $plus=1, $format=false)
{
$excerpt = [];
$twig = Escape::html($source);
$lines = preg_split("/(\r\n|\n|\r)/", $twig);
$start = max(1, $line - $plus);
$limit = min(count($lines), $line + $plus);
for ($i = $start -... | php | {
"resource": ""
} |
q249414 | TwigEnv.addCallable | validation | private function addCallable($type='function', $name, $func)
{
if (!is_string($name) || !is_callable($func)) {
return;
}
$twname = trim($name, '*');
$params = [];
if (strpos($name, '*') === 0) {
$params['is_safe'] = ['html'];
}
if ($typ... | php | {
"resource": ""
} |
q249415 | Twig_TokenParser_For.checkLoopUsageCondition | validation | protected function checkLoopUsageCondition(Twig_TokenStream $stream, Twig_NodeInterface $node)
{
if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) {
throw new Twig_Error_Synt... | php | {
"resource": ""
} |
q249416 | Twig_NodeVisitor_Optimizer.optimizePrintNode | validation | protected function optimizePrintNode(Twig_NodeInterface $node, Twig_Environment $env)
{
if (!$node instanceof Twig_Node_Print) {
return $node;
}
$exprNode = $node->getNode('expr');
if (
$exprNode instanceof Twig_Node_Expression_BlockReference ||
$... | php | {
"resource": ""
} |
q249417 | RecoveryController.actionRecoverPassword | validation | public function actionRecoverPassword()
{
$model = new AccountRecoverPasswordForm();
if ($model->load(Yii::$app->request->post())) {
if ($model->validate()) {
$model->recoverPassword();
}
}
return $this->render('recoverPassword', ['model' => $model]);
} | php | {
"resource": ""
} |
q249418 | Mailer.sendWelcomeMessage | validation | public static function sendWelcomeMessage(User $user)
{
return Mailer::sendMail($user->email, 'Welcome to ' . Yii::$app->name, 'welcome', ['user' => $user]);
} | php | {
"resource": ""
} |
q249419 | Mailer.sendMail | validation | protected function sendMail($to, $subject, $view, $params = [])
{
$mailer = Yii::$app->mailer;
$mailer->viewPath = '@abhimanyu/user/views/mail';
return $mailer->compose(['html' => $view, 'text' => 'text/' . $view], $params)
->setTo($to)
->setFrom(Yii::$app->config->get('mail.username'), 'n... | php | {
"resource": ""
} |
q249420 | AccountLoginForm.login | validation | public function login()
{
return $this->validate() ? Yii::$app->user->login($this->getUser(), $this->rememberMe ? UserModule::$rememberMeDuration : 0) : FALSE;
} | php | {
"resource": ""
} |
q249421 | Twig_Extension_Escaper.setDefaultStrategy | validation | public function setDefaultStrategy($defaultStrategy)
{
// for BC
if (true === $defaultStrategy) {
@trigger_error('Using "true" as the default strategy is deprecated since version 1.21. Use "html" instead.', E_USER_DEPRECATED);
$defaultStrategy = 'html';
}
if... | php | {
"resource": ""
} |
q249422 | Twig_Extension_Escaper.getDefaultStrategy | validation | public function getDefaultStrategy($name)
{
// disable string callables to avoid calling a function named html or js,
// or any other upcoming escaping strategy
if (!is_string($this->defaultStrategy) && false !== $this->defaultStrategy) {
return call_user_func($this->defaultStrat... | php | {
"resource": ""
} |
q249423 | Twig_Profiler_Profile.getDuration | validation | public function getDuration()
{
if ($this->isRoot() && $this->profiles) {
// for the root node with children, duration is the sum of all child durations
$duration = 0;
foreach ($this->profiles as $profile) {
$duration += $profile->getDuration();
... | php | {
"resource": ""
} |
q249424 | Twig_Profiler_Profile.getMemoryUsage | validation | public function getMemoryUsage()
{
return isset($this->ends['mu']) && isset($this->starts['mu']) ? $this->ends['mu'] - $this->starts['mu'] : 0;
} | php | {
"resource": ""
} |
q249425 | Twig_Profiler_Profile.getPeakMemoryUsage | validation | public function getPeakMemoryUsage()
{
return isset($this->ends['pmu']) && isset($this->starts['pmu']) ? $this->ends['pmu'] - $this->starts['pmu'] : 0;
} | php | {
"resource": ""
} |
q249426 | Twig_Template.getParent | validation | public function getParent(array $context)
{
if (null !== $this->parent) {
return $this->parent;
}
try {
$parent = $this->doGetParent($context);
if (false === $parent) {
return false;
}
if ($parent instanceof self)... | php | {
"resource": ""
} |
q249427 | Twig_Template.displayBlock | validation | public function displayBlock($name, array $context, array $blocks = array(), $useBlocks = true)
{
$name = (string) $name;
if ($useBlocks && isset($blocks[$name])) {
$template = $blocks[$name][0];
$block = $blocks[$name][1];
} elseif (isset($this->blocks[$name])) {
... | php | {
"resource": ""
} |
q249428 | Twig_Template.hasBlock | validation | public function hasBlock($name, array $context = null, array $blocks = array())
{
if (null === $context) {
@trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.', E_USER_DEPREC... | php | {
"resource": ""
} |
q249429 | Twig_Template.getBlockNames | validation | public function getBlockNames(array $context = null, array $blocks = array())
{
if (null === $context) {
@trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.', E_USER_DEPRECAT... | php | {
"resource": ""
} |
q249430 | Twig_Template.getContext | validation | final protected function getContext($context, $item, $ignoreStrictCheck = false)
{
if (!array_key_exists($item, $context)) {
if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
return;
}
throw new Twig_Error_Runtime(sprintf('Variable "%s" does n... | php | {
"resource": ""
} |
q249431 | RegistrationController.actionRegister | validation | public function actionRegister()
{
$model = new User();
$model->scenario = 'register';
if ($model->load(Yii::$app->request->post()) && $model->register(FALSE, User::STATUS_PENDING)) {
// Send Welcome Message to activate the account
Mailer::sendWelcomeMessage($model);
Yii::$app->session->setFlash(
... | php | {
"resource": ""
} |
q249432 | RegistrationController.actionConfirm | validation | public function actionConfirm($id, $code)
{
$user = UserIdentity::findByActivationToken($id, $code);
if ($user == NULL)
throw new NotFoundHttpException;
if (!empty($user)) {
$user->activation_token = NULL;
$user->status = User::STATUS_ACTIVE;
$user->save(FALSE);
Yii::$app->session->setFlash('su... | php | {
"resource": ""
} |
q249433 | Twig_FileExtensionEscapingStrategy.guess | validation | public static function guess($name)
{
if (in_array(substr($name, -1), array('/', '\\'))) {
return 'html'; // return html for directories
}
if ('.twig' === substr($name, -5)) {
$name = substr($name, 0, -5);
}
$extension = pathinfo($name, PATHINFO_EXTE... | php | {
"resource": ""
} |
q249434 | TwigComponent.file | validation | public function file($name)
{
$usephp = c::get('twig.usephp', true);
$base = str_replace('\\', '/', $this->kirby->roots()->templates().'/'.$name);
$twig = $base . '.twig';
$php = $base . '.php';
// only check existing files if PHP template support is active
if ($use... | php | {
"resource": ""
} |
q249435 | TwigComponent.render | validation | public function render($template, $data = [], $return = true)
{
if ($template instanceof Page) {
$page = $template;
$file = $page->templateFile();
$data = $this->data($page, $data);
} else {
$file = $template;
$data = $this->data(null, $dat... | php | {
"resource": ""
} |
q249436 | Twig_ExpressionParser.checkConstantExpression | validation | protected function checkConstantExpression(Twig_NodeInterface $node)
{
if (!($node instanceof Twig_Node_Expression_Constant || $node instanceof Twig_Node_Expression_Array
|| $node instanceof Twig_Node_Expression_Unary_Neg || $node instanceof Twig_Node_Expression_Unary_Pos
)) {
... | php | {
"resource": ""
} |
q249437 | Twig_Util_DeprecationCollector.collectDir | validation | public function collectDir($dir, $ext = '.twig')
{
$iterator = new RegexIterator(
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::LEAVES_ONLY
), '{'.preg_quote($ext).'$}'
);
return $this->collect(new Twi... | php | {
"resource": ""
} |
q249438 | Twig_Util_DeprecationCollector.collect | validation | public function collect(Traversable $iterator)
{
$this->deprecations = array();
set_error_handler(array($this, 'errorHandler'));
foreach ($iterator as $name => $contents) {
try {
$this->twig->parse($this->twig->tokenize(new Twig_Source($contents, $name)));
... | php | {
"resource": ""
} |
q249439 | Twig_TokenStream.next | validation | public function next()
{
if (!isset($this->tokens[++$this->current])) {
throw new Twig_Error_Syntax('Unexpected end of template.', $this->tokens[$this->current - 1]->getLine(), $this->source);
}
return $this->tokens[$this->current - 1];
} | php | {
"resource": ""
} |
q249440 | Twig_TokenStream.expect | validation | public function expect($type, $value = null, $message = null)
{
$token = $this->tokens[$this->current];
if (!$token->test($type, $value)) {
$line = $token->getLine();
throw new Twig_Error_Syntax(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s).',
... | php | {
"resource": ""
} |
q249441 | Twig_TokenStream.look | validation | public function look($number = 1)
{
if (!isset($this->tokens[$this->current + $number])) {
throw new Twig_Error_Syntax('Unexpected end of template.', $this->tokens[$this->current + $number - 1]->getLine(), $this->source);
}
return $this->tokens[$this->current + $number];
} | php | {
"resource": ""
} |
q249442 | ExportCommand.exportJob | validation | protected function exportJob($job)
{
$stats = $this->getJobStats($job);
$contents = $this->renderForExport($job, $stats);
$filename = trim($this->path, '/').'/'.$this->buildJobFileName($job, $stats);
if (file_exists($filename)) {
throw new \RuntimeException('File alrea... | php | {
"resource": ""
} |
q249443 | ArtisanBeansServiceProvider.registerCommand | validation | protected function registerCommand($command)
{
$abstract = "command.artisan.beans.$command";
$commandClass = "\\Pvm\\ArtisanBeans\\Console\\{$command}Command";
$this->app->singleton($abstract, function ($app) use ($commandClass) {
return new $commandClass();
});
... | php | {
"resource": ""
} |
q249444 | BaseCommand.peekJob | validation | protected function peekJob($tube, $state)
{
$peekMethod = 'peek'.ucfirst($state);
try {
return $this->getPheanstalk()->$peekMethod($tube);
} catch (ServerException $e) {
if ($this->isNotFoundException($e)) {
return;
}
throw $e... | php | {
"resource": ""
} |
q249445 | BaseCommand.reserveJob | validation | protected function reserveJob($tube)
{
try {
return $this->getPheanstalk()->reserveFromTube($tube, 0);
} catch (ServerException $e) {
if ($this->isNotFoundException($e)) {
return;
}
throw $e;
}
} | php | {
"resource": ""
} |
q249446 | BaseCommand.getJobStats | validation | protected function getJobStats($job)
{
try {
return (array) $this->getPheanstalk()->statsJob($job);
} catch (ServerException $e) {
if ($this->isNotFoundException($e)) {
return;
}
throw $e;
}
} | php | {
"resource": ""
} |
q249447 | BaseCommand.buryJob | validation | protected function buryJob($job, $priority = null)
{
if (is_null($priority)) {
$priority = Pheanstalk::DEFAULT_PRIORITY;
}
$this->getPheanstalk()->bury($job, $priority);
} | php | {
"resource": ""
} |
q249448 | BaseCommand.putJob | validation | protected function putJob($tube, $body, $priority, $delay, $ttr)
{
$id = $this->getPheanstalk()
->putInTube($tube, $body, $priority, $delay, $ttr);
return $id;
} | php | {
"resource": ""
} |
q249449 | BaseCommand.getPheanstalk | validation | public function getPheanstalk()
{
if (! $this->pheanstalk) {
$this->pheanstalk = new Pheanstalk($this->host, $this->port);
}
return $this->pheanstalk;
} | php | {
"resource": ""
} |
q249450 | BaseCommand.parseArguments | validation | protected function parseArguments()
{
$this->parseConnection($this->option('connection'));
if ($this->option('host')) {
$this->host = $this->option('host');
}
if ($this->option('port')) {
$this->port = (int) $this->option('port');
}
$this->p... | php | {
"resource": ""
} |
q249451 | BaseCommand.parseConnection | validation | protected function parseConnection($connectionName)
{
$connection = null;
// If user provided the connection name read it directly
if ($connectionName) {
if (! $connection = config("queue.connections.$connectionName")) {
throw new \InvalidArgumentException("Conne... | php | {
"resource": ""
} |
q249452 | BaseCommand.buildCommandSignature | validation | protected function buildCommandSignature()
{
$this->signature = $this->namespace.':'.$this->commandName.' '.
$this->commandArguments.
$this->commandOptions.
$this->commonOptions;
} | php | {
"resource": ""
} |
q249453 | BaseCommand.validateFile | validation | protected function validateFile($filePath, $message = 'File', $allowEmpty = true)
{
if (! file_exists($filePath) || ! is_readable($filePath)) {
throw new \RuntimeException("$message '{$filePath}' doesn't exist or is not readable.");
}
if (! $allowEmpty && 0 === filesize($filePat... | php | {
"resource": ""
} |
q249454 | BaseCommand.renderJob | validation | protected function renderJob($job)
{
$stats = $this->getJobStats($job);
$format = '<info>id</info>: %u, <info>length</info>: %u, <info>priority</info>: %u, <info>delay</info>: %u, <info>age</info>: %u, <info>ttr</info>: %u';
$line = sprintf($format, $job->getId(), strlen($job->getData()), $... | php | {
"resource": ""
} |
q249455 | BaseCommand.getTubeStats | validation | protected function getTubeStats($tube)
{
try {
$stats = $this->getPheanstalk()->statsTube($tube);
} catch (ServerException $e) {
if ($this->isNotFoundException($e)) {
throw new \RuntimeException("Tube '$tube' doesn't exist.");
}
throw ... | php | {
"resource": ""
} |
q249456 | BaseCommand.getServerStats | validation | protected function getServerStats($pattern = '')
{
$stats = (array) $this->getPheanstalk()->stats();
if (! empty($pattern)) {
$stats = array_filter($stats, function ($key) use ($pattern) {
return 1 === preg_match("/$pattern/i", $key);
}, ARRAY_FILTER_USE_KEY)... | php | {
"resource": ""
} |
q249457 | MoveCommand.getNextJob | validation | private function getNextJob($tube, $state)
{
if ('ready' == $this->state) {
return $this->reserveJob($tube);
}
return $this->peekJob($tube, $state);
} | php | {
"resource": ""
} |
q249458 | Utils.getRefererQueryParam | validation | public static function getRefererQueryParam($url, $key)
{
if (!$url) {
return null;
}
$query = [];
parse_str(parse_url($url, PHP_URL_QUERY), $query);
if (isset($query[$key])) {
return $query[$key];
}
return null;
} | php | {
"resource": ""
} |
q249459 | RateLimit.isAllowed | validation | protected function isAllowed($limit, $config)
{
if ($limit["cnt"] >= $config["count"]) {
if (time() > $limit["ts"] + $config["blockDuration"]) {
return true;
} else {
return false;
}
} else {
return true;
}
} | php | {
"resource": ""
} |
q249460 | RateLimit.getIp | validation | protected function getIp($config)
{
$remoteAddr = $_SERVER['REMOTE_ADDR'];
if (filter_var($remoteAddr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$netmask = (isset($config["netmask_IPv4"]))
? $config["netmask_IPv4"] : self::DEFAULT_NETMASK_IPV4;
} else {
... | php | {
"resource": ""
} |
q249461 | RateLimit.getSubnet | validation | protected function getSubnet($ip, $netmask)
{
$binString = @inet_pton($ip);
if ($binString === false) {
throw new \InvalidArgumentException("Not a valid IP address.");
}
// Length of the IP in bytes (4 or 16)
$byteLen = mb_strlen($binString, "8bit");
if (... | php | {
"resource": ""
} |
q249462 | RateLimit.getEntityId | validation | protected function getEntityId($blockType, $config, $params = array())
{
$entityId = null;
if ($blockType === "account" && isset($params["name"])) {
$entityId = md5($params["name"]);
} elseif ($blockType === "email" && isset($params["email"])) {
$entityId = md5($param... | php | {
"resource": ""
} |
q249463 | RateLimit.getLimitFor | validation | protected function getLimitFor($actionName, $blockType, $entityId)
{
$limit = $this->storage->getLimitFor($actionName, $blockType, $entityId);
if ($limit === null) {
$limit = array("ts" => 0, "cnt" => 0);
}
return $limit;
} | php | {
"resource": ""
} |
q249464 | RateLimit.incrementCounter | validation | protected function incrementCounter($actionName, $blockType, $entityId, $config)
{
// Begin an exclusive transaction
$this->storage->transaction($actionName, $blockType, RateLimitStorageInterface::TRANSACTION_BEGIN);
$limit = $this->getLimitFor($actionName, $blockType, $entityId);
... | php | {
"resource": ""
} |
q249465 | RateLimit.logRateLimitReached | validation | protected function logRateLimitReached($actionName, $blockType, $entityId, $config)
{
$this->getLogger()->notice(
"Rate limit of {cnt} reached: {action} for {entity} ({type}).",
array('cnt' => $config["count"], 'action' => $actionName, 'entity' => $entityId, 'type' => $blockType)
... | php | {
"resource": ""
} |
q249466 | Registration.handleRegistration | validation | public function handleRegistration(Request $httpRequest)
{
// Abort if disabled
if (!$this->config["enabled"]) {
return;
}
$user = $this->picoAuth->getUser();
if ($user->getAuthenticated()) {
$this->picoAuth->redirectToPage("index");
}
... | php | {
"resource": ""
} |
q249467 | Registration.validateRegistration | validation | protected function validateRegistration(array $reg)
{
$isValid = true;
// Username format
try {
$this->storage->checkValidName($reg["username"]);
} catch (\RuntimeException $e) {
$isValid = false;
$this->session->addFlash("error", $e->getMessage()... | php | {
"resource": ""
} |
q249468 | Registration.logSuccessfulRegistration | validation | protected function logSuccessfulRegistration(array $reg)
{
$this->getLogger()->info(
"New registration: {name} ({email}) from {addr}",
array(
"name" => $reg["username"],
"email" => $reg["email"],
"addr" => $_SERVER['REMOTE_ADDR']
... | php | {
"resource": ""
} |
q249469 | Registration.assertLimits | validation | protected function assertLimits()
{
if ($this->storage->getUsersCount() >= $this->config["maxUsers"]) {
$this->session->addFlash("error", "New registrations are currently disabled.");
$this->picoAuth->redirectToPage("register");
}
} | php | {
"resource": ""
} |
q249470 | FileStorage.readFile | validation | public static function readFile($fileName, $options = [])
{
$reader = new File\FileReader($fileName, $options);
$success = true;
$contents = null;
try {
$reader->open();
$contents = $reader->read();
} catch (\RuntimeException $e) {
self::$... | php | {
"resource": ""
} |
q249471 | FileStorage.writeFile | validation | public static function writeFile($fileName, $data, $options = [])
{
$writer = new File\FileWriter($fileName, $options);
$isSuccess = true;
$written = 0;
try {
$writer->open();
$written = $writer->write($data);
} catch (\RuntimeException $e) {
... | php | {
"resource": ""
} |
q249472 | FileStorage.getItemByUrl | validation | public static function getItemByUrl($items, $url)
{
if (!isset($items)) {
return null;
}
// Check for the exact rule
if (array_key_exists("/" . $url, $items)) {
return $items["/" . $url];
}
$urlParts = explode("/", trim($url, "/"));
$... | php | {
"resource": ""
} |
q249473 | FileStorage.readConfiguration | validation | protected function readConfiguration()
{
// Return if already loaded
if (is_array($this->config)) {
return;
}
$fileName = $this->dir . static::CONFIG_FILE;
// Abort if the file doesn't exist
if (!file_exists($fileName)) {
$thi... | php | {
"resource": ""
} |
q249474 | CSRF.getToken | validation | public function getToken($action = null, $reuse = true)
{
$tokenStorage = $this->session->get(self::SESSION_KEY, []);
$index = ($action) ? $action : self::DEFAULT_SELECTOR;
if (!isset($tokenStorage[$index])) {
$token = bin2hex(random_bytes(self::TOKEN_SIZE));
... | php | {
"resource": ""
} |
q249475 | CSRF.isExpired | validation | protected function isExpired(array $tokenData, $tokenValidity = null)
{
return time() >
$tokenData['time'] + (($tokenValidity!==null) ? $tokenValidity : self::TOKEN_VALIDITY);
} | php | {
"resource": ""
} |
q249476 | CSRF.ivalidateToken | validation | protected function ivalidateToken($index, array &$tokenStorage)
{
unset($tokenStorage[$index]);
$this->session->set(self::SESSION_KEY, $tokenStorage);
} | php | {
"resource": ""
} |
q249477 | Installer.checkServerConfiguration | validation | protected function checkServerConfiguration()
{
$pico = $this->picoAuth->getPico();
// Pico config.yml file
$configDir = $pico->getBaseUrl() . basename($pico->getConfigDir());
$configFile = $configDir . "/config.yml";
// index.md file
$contentDir = $pico->getBaseUrl... | php | {
"resource": ""
} |
q249478 | Installer.configGenerationAction | validation | protected function configGenerationAction(ParameterBag $post)
{
//CSRF validation
if (!$this->picoAuth->isValidCSRF($post->get("csrf_token"))) {
// On a token mismatch the submission gets ignored
$this->picoAuth->addOutput("installer_step", 1);
return;
}
... | php | {
"resource": ""
} |
q249479 | Installer.outputModulesConfiguration | validation | protected function outputModulesConfiguration(ParameterBag $post)
{
$modulesClasses = array();
$modulesNames = array();
foreach ($this->modules as $key => $value) {
if ($post->has($key)) {
$modulesClasses[] = $value;
$modulesNames[] = $key;
... | php | {
"resource": ""
} |
q249480 | User.setAuthenticated | validation | public function setAuthenticated($v)
{
if (!$v) {
$this->authenticator = null;
}
$this->authenticated = $v;
return $this;
} | php | {
"resource": ""
} |
q249481 | LocalAuthFileStorage.saveResetTokens | validation | protected function saveResetTokens($tokens, FileWriter $writer = null)
{
// Before saving, remove all expired tokens
$time = time();
foreach ($tokens as $id => $token) {
if ($time > $token['valid']) {
unset($tokens[$id]);
}
}
$fileName... | php | {
"resource": ""
} |
q249482 | LocalAuthFileStorage.getDirFiles | validation | protected function getDirFiles($searchDir)
{
// Error state is handled by the excpetion, warning disabled
$files = @scandir($searchDir, SCANDIR_SORT_NONE);
if ($files === false) {
throw new \RuntimeException("Cannot list directory contents: {$searchDir}.");
}
ret... | php | {
"resource": ""
} |
q249483 | LocalAuth.handleLogin | validation | protected function handleLogin(Request $httpRequest)
{
$post = $httpRequest->request;
if (!$post->has("username") || !$post->has("password")) {
return;
}
//CSRF validation
if (!$this->picoAuth->isValidCSRF($post->get("csrf_token"), self::LOGIN_CSRF_ACTION)) {
... | php | {
"resource": ""
} |
q249484 | LocalAuth.loginAttempt | validation | public function loginAttempt($username, Password $password)
{
$userData = $this->storage->getUserByName($username);
$encoder = $this->getPasswordEncoder($userData);
$dummy = bin2hex(\random_bytes(32));
$dummyHash = $encoder->encode($dummy);
if (!$userData) {
// ... | php | {
"resource": ""
} |
q249485 | LocalAuth.login | validation | public function login($id, $userData)
{
$this->abortIfExpired($id, $userData);
$u = new User();
$u->setAuthenticated(true);
$u->setAuthenticator($this->getName());
$u->setId($id);
if (isset($userData['groups'])) {
$u->setGroups($userData['groups']);
... | php | {
"resource": ""
} |
q249486 | LocalAuth.abortIfExpired | validation | protected function abortIfExpired($id, $userData)
{
if (isset($userData['pwreset']) && $userData['pwreset']) {
$this->session->addFlash("error", "Please set a new password.");
$this->picoAuth->getContainer()->get('PasswordReset')->startPasswordResetSession($id);
$this->pi... | php | {
"resource": ""
} |
q249487 | LocalAuth.getPasswordEncoder | validation | protected function getPasswordEncoder($userData = null)
{
if (isset($userData['encoder']) && is_string($userData['encoder'])) {
$name = $userData['encoder'];
} else {
$name = $this->config["encoder"];
}
$container = $this->picoAuth->getContainer();
... | php | {
"resource": ""
} |
q249488 | LocalAuth.userDataEncodePassword | validation | public function userDataEncodePassword(&$userData, Password $newPassword)
{
$encoderName = $this->config["encoder"];
$encoder = $this->picoAuth->getContainer()->get($encoderName);
$userData['pwhash'] = $encoder->encode($newPassword->get());
$userData['encoder'] = $encoderName;
... | php | {
"resource": ""
} |
q249489 | LocalAuth.checkPasswordPolicy | validation | public function checkPasswordPolicy(Password $password)
{
$result = true;
$policy = $this->picoAuth->getContainer()->get("PasswordPolicy");
$maxAllowedLen = $this->getPasswordEncoder()->getMaxAllowedLen();
if (is_int($maxAllowedLen) && strlen($password)>$maxAllowedLen) {
... | php | {
"resource": ""
} |
q249490 | LocalAuth.needsPasswordRehash | validation | protected function needsPasswordRehash(array $userData)
{
// Return if password rehashing is not enabled
if ($this->config["login"]["passwordRehash"] !== true) {
return false;
}
// Password hash is created using a different algorithm than default
if (isset($userD... | php | {
"resource": ""
} |
q249491 | LocalAuth.passwordRehash | validation | protected function passwordRehash($username, Password $password)
{
$userData = $this->storage->getUserByName($username);
try {
$this->userDataEncodePassword($userData, $password);
} catch (\PicoAuth\Security\Password\Encoder\EncoderException $e) {
// The enco... | php | {
"resource": ""
} |
q249492 | LocalAuth.isValidUsername | validation | protected function isValidUsername($name)
{
if (!is_string($name)
|| !$this->storage->checkValidName($name)
|| strlen($name) < $this->config["registration"]["nameLenMin"]
|| strlen($name) > $this->config["registration"]["nameLenMax"]
) {
return false;
... | php | {
"resource": ""
} |
q249493 | LocalAuth.logInvalidLoginAttempt | validation | protected function logInvalidLoginAttempt($name)
{
// Trim logged name to the maximum allowed length
$max = $this->config["registration"]["nameLenMax"];
if (strlen($name)>$max) {
$max = substr($name, 0, $max) . " (trimmed)";
}
$this->getLogger()->notice(
... | php | {
"resource": ""
} |
q249494 | LocalAuth.handleAccountPage | validation | protected function handleAccountPage(Request $httpRequest)
{
$user = $this->picoAuth->getUser();
if (!$user->getAuthenticated()) {
$this->session->addFlash("error", "Login to access this page.");
$this->picoAuth->redirectToLogin();
return;
}
// Pa... | php | {
"resource": ""
} |
q249495 | LocalAuth.handleRegistration | validation | protected function handleRegistration(Request $httpRequest)
{
$registration = $this->picoAuth->getContainer()->get('Registration');
$registration->setConfig($this->config)
->handleRegistration($httpRequest);
} | php | {
"resource": ""
} |
q249496 | LocalAuth.handlePasswordReset | validation | protected function handlePasswordReset(Request $httpRequest)
{
$passwordReset = $this->picoAuth->getContainer()->get('PasswordReset');
$passwordReset->setConfig($this->config)
->handlePasswordReset($httpRequest);
} | php | {
"resource": ""
} |
q249497 | OAuth.initProvider | validation | protected function initProvider($providerConfig)
{
$providerClass = $providerConfig['provider'];
$options = $providerConfig['options'];
if (!isset($options['redirectUri'])) {
// Set OAuth 2.0 callback page from the configuration
$options['redirectUri'] = $this->picoA... | php | {
"resource": ""
} |
q249498 | OAuth.startAuthentication | validation | protected function startAuthentication()
{
$authorizationUrl = $this->provider->getAuthorizationUrl();
$this->session->migrate(true);
$this->session->set("oauth2state", $this->provider->getState());
// The final redirect, halts the script
$this->picoAuth->redirectToP... | php | {
"resource": ""
} |
q249499 | OAuth.finishAuthentication | validation | protected function finishAuthentication(Request $httpRequest)
{
$sessionCode = $this->session->get("oauth2state");
$this->session->remove("oauth2state");
// Check that the state from OAuth response matches the one in the session
if ($httpRequest->query->get("state") !== $sessionCode... | php | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.