Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
public function initialize()
{
if (empty($this->config['encryption'])) {
$this->config['encryption'] = "plaintext";
}
$this->addTwigFunction('passwordprotect', 'passwordProtect');
$this->addTwigFunction('passwordform', 'passwordForm');
$path = $this->app['config']->get('general/branding/path') . '/generatepasswords';
$this->app->match($path, array($this, "generatepasswords"));
$extension = $this;
// Register this extension's actions as an early event.
$this->app->before(function (Request $request) use ($extension) {
return $extension->handleRequest($request);
}, SilexApplication::EARLY_EVENT);
$this->addMenuOption('Edit Access Code', $this->app['resources']->getUrl('bolt').'generatepasswords', 'fa:pencil-square-o');
}
public function handleRequest(Request $request)
{
$path = explode("/", $request->getPathInfo());
if (isset($path[1])) {
if ($path[1] === $this->config['contentType']) {
if ($this->app['session']->get('passwordprotect') == 1) {
return true;
} else {
$redirectto = $this->app['storage']->getContent($this->config['redirect'], array('returnsingle' => true));
$returnto = $this->app['request']->getRequestUri();
return $this->app->redirect($redirectto->link(). "?returnto=" . urlencode($returnto));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment