Login Header Plugin

Post Reply
anonymous1337

Login Header Plugin

Post by anonymous1337 »

The <?= $Wcms->page('content') ?> tag being both content as well as a login form didn't work for me.
I've written a small plugin that creates a login header atop the login page, allowing for consistent and theme-independent styling and location of the login environment.

screenshot.png
screenshot.png (441.49 KiB) Viewed 8534 times

The plugin and it's instructions on use can be found over on Github.

I have also opened it's first issue (enhancement)(help needed), looking to change the default logout behavior to better suit the plugin. I've also toyed with the idea of moving/removing the existing <?= $Wcms->page('content') ?> tag as long as the plugin is active, and restoring it upon uninstall.

I'm curious about your thoughts and any further suggestions for improvement. ^_^
User avatar
wiz
Posts: 749
Joined: Sat Oct 30, 2010 12:23 am

Re: Login Header Plugin

Post by wiz »

Hi anonymous, have a warm welcome to the community!

Thanks for upgrading the user experience, we will most likely include this in our next release.
Since you've contributed to WonderCMS development, it's only right we list you on https://wondercms.com/special-contributors.

Would you mind sharing me your name + website/social so we can add you?
anonymous1337

Re: Login Header Plugin

Post by anonymous1337 »

Hi wiz and thank you for welcoming me! (✿◡‿◡)

I'm not sure this plugin is already in a ready-for-release state, although i've done some futher tweaking to different bits and pieces and might push those changes soon. I've been at it with the issues opened on GitHub, but so far with little results.

I was hoping my post could spark discussion/debate/mindstorm on the current login construction, where the <?= $Wcms->page('content') ?> tag seems ambiguous to me. Something along the lines of a <?= $Wcms->login() ?> core tag, perhaps..?

On a different topic, is there something like a Teamspeak/Discord/Mumble/Teams channel where active developers can collaberate and share/review/debate their current plugins and or projects? I find it difficult to get a grasp of how many people are actively occupied with wondercms in a development fashion.
anonymous1337

Re: Login Header Plugin

Post by anonymous1337 »

@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.
User avatar
wiz
Posts: 749
Joined: Sat Oct 30, 2010 12:23 am

Re: Login Header Plugin

Post by wiz »

Sorry for the late response, been super busy and finally getting to some vacation.

In regards to our dev chat, you can join us on Slack: wondercms.slack.com (open for everyone).
Also, you've been added to our official contributors list: https://www.wondercms.com/special-contributors (do you have a website/social link to add on top of your name?).

I'd also like to take this opportunity to thank you again for struggling with this. We have a dedicated dev (Slaven), who could also help us figure this out, we just have to set a schedule and hopefully I'll be able to contribute with something more useful.

Also, do you have PayPal or something like a crypto address? Would love to reward your effor with a symbolic donation!

Additionally, this could be opened as a separate bug issue on GitHub so we can track better progress?
anonymous1337

Re: Login Header Plugin

Post by anonymous1337 »

Hi wiz, I hope you had a nice vacation! ☀⛱

I wanted to message you privately but can't seem to find the option. Has it been disabled on this board?
Or does one need to be friends with another first? 🤔 I've sent you a friend request already just in case.
I'll answer everything non-plugin related trough there and do my best to stay on-topic here.

Regarding GitHub, I have set up issues for the plugin in it's repository.
Is that what you had in mind, or do you mean to set those up elsewhere?
User avatar
wiz
Posts: 749
Joined: Sat Oct 30, 2010 12:23 am

Re: Login Header Plugin

Post by wiz »

I seem to have totally missed your message, my apologies.
I personally feel bad for forgetting to also reward you. Please contact us at hi@wondercms.com or join our Slack where we can also talk privately: https://wondercms.slack.com

The private messages have been disabled due to bots/spammers abusing it to send links to other users.
I also never got to review your plugin, also sorry for that (the repository seems to be removed).


@indianembassyrome, please check back once this plugin has been reviewed. Thank you for reviving this thread and reminding me of the matter.
Post Reply