Jump to content
jploch

Admin Theme login screen

Recommended Posts

Hey folks,
Iam working on a new Admin Theme, based on AdminThemeReno, which I would like to release for the public soon.
Now I want to style the login page to fit the look and feel of the backend.

After some research, I found out that I have to set the "$config->defaultAdminTheme = 'AdminThemeName' " inside my site config.php file to load all the styles from my admin theme on the login page instead of the default ones.
Is it possible to set this via api from my Admin Theme settings, without the need of editing the config file?
 

Share this post


Link to post
Share on other sites
1 hour ago, jploch said:

Is it possible to set this via api from my Admin Theme settings, without the need of editing the config file?

Haven't done it myself, but I guess it should be possible. Have a look at AdminThemeUikit settings when editing it in Admin / Module /. You see this:

uikit-login-screen-settings.thumb.png.6d4ea9a7606f4ada396eed98fb309131.png

That shows it should be possible.

  • Like 2

Share this post


Link to post
Share on other sites
15 hours ago, kongondo said:

Haven't done it myself, but I guess it should be possible. Have a look at AdminThemeUikit settings when editing it in Admin / Module /. You see this:

Thx Kongondo! I already tried to find the code inside the AdminThemeUikit module files, but could not find this setting.
I will take another look and repost my findings 

Share this post


Link to post
Share on other sites
42 minutes ago, jploch said:

I will take another look and repost my findings 

Follow the rabbit from here: wire/core/AdminThemeFramework.php

/**
 * AdminTheme Framework
 * 
 * The methods in this class may eventually be merged to AdminTheme.php, 
 * but are isolated to this class during development. 
 *
 * @property bool $isSuperuser
 * @property bool $isEditor
 * @property bool $isLoggedIn
 * @property bool|string $isModal
 * @property bool|int $useAsLogin <------- this one?
 * @method array getUserNavArray()
 *
 */

$useAsLogin maybe?

Share this post


Link to post
Share on other sites
1 hour ago, kongondo said:

Follow the rabbit from here: wire/core/AdminThemeFramework.php

$useAsLogin maybe?

This seems to be it. The problem is that I don't know how to change that setting. My admin theme is based on reno and is not extending 'AdminThemeFramework' like the Uikit based themes, but the original 'AdminTheme'. So I could not integrate that setting in my theme.

I tried this in my theme (taken from AdminThemeFramework.php), wich resets the login settings on all the admin  themes, but then it switches back to AdminThemeUikit as the default:

$class = $this->className();
			foreach($this->modules->findByPrefix('AdminTheme') as $name) {
				if($name == $class) continue;
				$cfg = $this->modules->getConfig($name);
				if(!empty($cfg['useAsLogin'])) {
					unset($cfg['useAsLogin']);
					$this->modules->saveConfig($name, $cfg);
					$this->message("Removed 'useAsLogin' setting from $name", Notice::debug);
				}
			}

In the docs I found this:

AdminThemeFramework::useAsLogin

 

Share this post


Link to post
Share on other sites

I'll see if I can get time to have a play. From what I can tell, in AdminThemeFramework::init we have this code:

<?php namespace ProcessWire;
$user = $this->wire('user');
if(!$user->isLoggedin() && $this->useAsLogin) $this->setCurrent();
parent::init();

That checks if the user is NOT logged in and if useAsLogin is true...

$this->setCurrent() is a method in the base class, AdminTheme. Like you said, $useAsLogin is native to AdminThemeFramework. However, AdminThemeFramework only uses it internally to see if to use setCurrent().

In AdminTheme::init, it will first check if there is a user specified theme and if that matches the current admin theme. If true, it will use setCurrent() to set it as the current theme. Else, it will fall back to what is specified in $config->defaultAdminTheme, if a value exists there.

<?php namespace ProcessWire;
if($adminTheme) {
// there is user specified admin theme
// check if this is the one that should be used
if($adminTheme == $this->className()) $this->setCurrent();

} else if($this->wire('config')->defaultAdminTheme == $this->className()) {
// there is no user specified admin theme, so use this one
$this->setCurrent();
}

I am guessing that in the init() method of your custom AdminTheme, you can use the above logic (first code) similar to what is in AdminThemeFrameWork::init (the bit about user not logged in....).

Sorry if this doesn't make sense; Written in a hurry...

Edited by kongondo
  • Like 1

Share this post


Link to post
Share on other sites

@kongondo Thanks! This worked very well. With your help I implemented a setting to use my admin theme for the login. It works only if I also set the guest user to use my admin theme. This needs to be done manually in the profile settings, in addition to the module settings. For better usabillity it would be nice to set the guest user admin theme via api as well. I know that "$user->admin_theme" gives me the name for the admin theme of the current user but I have no Idea how to set the theme for the guest user. Any ideas?

Share this post


Link to post
Share on other sites
1 hour ago, jploch said:

This worked very well.

Glad you got it sorted! 😄.

1 hour ago, jploch said:

It works only if I also set the guest user to use my admin theme. This needs to be done manually in the profile settings, in addition to the module settings.

Hmm. That sounds like one-too-many hoops.

1 hour ago, jploch said:

For better usabillity it would be nice to set the guest user admin theme via api as well. I know that "$user->admin_theme" gives me the name for the admin theme of the current user but I have no Idea how to set the theme for the guest user. Any ideas?

This is an interesting one. I have never really thought of the guest needing to have a preferred theme, but I can see the setting in Users > guest. Why would the guest need a theme at all?

I'll have a think unless someone beats me to this.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By DanielKit
      Hi. I'm currently stuck at the login page in my project. Once I enter my admin username and my password and press login, nothing happens. The page just reloads. However, the URL changes from http://myipaddress/processwire to http://myipaddress/processwire/?login=1. I've checked all of my server settings, and to my knowledge, all seems to be fine there. I don't know where to go from here.. Thanks in advance!
    • By Tyssen
      I have a client who is reporting that in the last couple of days they can no longer login to their site with their normal browser (Chrome). Using another browser or an incognito window works.
      I've tried logging into the site using the same login details in my usual browser (Firefox) and have had no problems.
      The site is a membership site and today other members are reporting the same problem.
      The site is running 3.0.148 and has the session handler DB and login throttle modules installed. It was recently upgraded to 3.x from 2.x. But no changes have been made to the site between the time when they were able to login OK and when the problem started happening.
    • By codevark
      The Minimal Site works fine, but if I try to login as admin, I have no idea what the credentials are.
      I did not do the "install" process myself. The OVA came with everything set up, but there's no mention of the PW admin credentials being set to some initial value.
      Wondering if anyone else has tried the Bitnami OVA and if there's a simple answer.
      --Pete
    • By franciccio-ITALIANO
      Hi, I need to provide a quite complex user registration form: description, subdescription, drop-down lists etc. 
      Through this registration, users will be able to access and comment.
      If someone responds to their comments, I would like a NOTIFICATION to appear when accessing their panel.
      My social interaction project is just that, it seems simple, I don't need more.
      Now I am undecided whether to use buddypress, elgg, or a native processwire system.
      What do you recommend? 
      If you recommend processwire, which modules should I install?
      Do they work or is processwire too immature for that?
      Translated with www.DeepL.com/Translator (free version)
    • By abdulqayyum
      Dear processwire community,
      i have a problem in loginRegister module, i could not add custom field in login and register page.
      i read from plugin documentation. they are saying.
      " By default, the email and password fields are required for both forms. You may want to add more fields. To do this, you’ll need to add fields to your “user” template. You can add fields to your user template in the admin by going to “Setup > Templates > Show system templates > user”.

      but i could not find similar scenario like “Setup > Templates > Show system templates > user”
      i can see just "Setup > Templates" not seeing "Show system templates > user" in my admin panel.

      Please help me in this case that how i can add custom field in these two page.
      Regards AbdulQayyum

×
×
  • Create New...