@wiz I failed to answer your question last time around, sorry about that!
I'm not really on anything social, but I'd be fine with just anonymous ๐
I've gotten around to update this. The code has been updated on it's GitHub repo.
I've made a few changes and a few issues remain as well:
- ๐๐ป - Plugin now automatically activated after install, steps for manual installation removed from GitHub
๐๐ป - Check if user is on the login page has been simplified and uses the native (index.php) method
- ๐๐ป - Existing <?= $Wcms->page('content') ?> tag causes duplicate input fields and console warnings
๐๐ป - CSS to margin-top doesn't want to function on condition of user being on login page
The current solution is not as elegant as I'd hoped. You guys wouldn't believe in how many ways/hours I've tried to solve the issue of automatic activation and duplicate logins ๐ต I've first tried simply inserting ($Wcms->page('content')), to no avail. Then I tried with JavaScript:
Code: Select all
let invoke = document.createElement("div");
invoke.innerHTML = "<?php echo login_header(); ?>"
document.body.appendChild(invoke);
and the PHP DOM parser:
Code: Select all
$doc = new DOMDocument();
$doc->loadHTMLFile("{$Wcms->url()}{$this->get('config', 'theme')}");
$login = $doc->getElementById('login');
$login->setAttribute("class", "login_header");
echo $doc->saveHTML();
and then I tried to prevent the duplicate login situation trough preg-replace, which worked as intended but for some reason persistenly mixed the <head> contents into the <body> tag and messed up the html layout:
Code: Select all
echo preg_replace("/<div id=\"login\".*>.*<\/div>/", "", $Wcms->page('content'));
The current "solution" is simply to re-insert the html content produced by $Wcms->page('content') after wrapping it with another div id="login_header":
Code: Select all
function insert ($args) {
global $Wcms;
// insert div-wrapped default contents of $Wcms->page('content')
$args[0] .= <<<EOT
<div id='login_header'>
<div id='login' style='color:#ccc;left:0;top:0;width:100%;height:100%;display:none;position:fixed;text-align:center;padding-top:100px;background:rgba(51,51,51,.8);z-index:2448'>
<h2>Logging in and checking for updates</h2>
<p>This might take a minute, updates are checked once per day.</p>
</div>
<form action='{$Wcms->url()}{$Wcms->get('config', 'login')}' method='post'>
<div class='input-group'>
<input type='password' class='form-control' id='password' name='password' placeholder='password' autofocus=''>
<span class='input-group-btn input-group-append'>
<button type='submit' class='btn btn-info' onclick='$('#login').show();'>Login</button>
</span>
</div>
</form>
</div>
EOT;
return $args;
}
I've also tried to change the default logout behavior, since the default redirect (back to the login page) makes little sense together with this plugin. I'd need to make changes in the logoutAction function in index.php, this line:
Code: Select all
$this->redirect($this->get('config', 'login'));
to
Code: Select all
$this->redirect($this->get('config', 'defaultPage'));
so i tried trough with preg_replace:
Code: Select all
echo preg_replace("/\$this->redirect(\$this->get('config', 'login'));/", "\$this->redirect(\$this->get('config', 'defaultPage'));", $_SERVER['PHP_SELF']);
but no luck. Not that that could've worked well, there's 2 enties matching that RegEx in index.php ๐ Also, using the $_SERVER['PHP_SELF'] seems rather intrusive. Any thoughts on how I'd go about changing this? Ideally it would only override the logout behavior as long as the plugin is installed/activated.