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 Marvin
      Hi,
      I'm still new at processwire, i want to ask, i was create a website with sign in system, but i want to add a access roles/permission for each user at my website. For now, i just can create a login user without any permission and the user data became as a pages in my processwire.
      Here i attach my code for login
      <?php $note = $note2 = $hidden =""; if($input->get->id == "logout") { $session->remove('login_id'); } if($input->post->submit) { $email = $sanitizer->email($input->post->email); $pass = $sanitizer->text($input->post->pass); $result = $pages->find("email=$email, text_1=$pass"); if(!$email || !$pass) { $note = "Data belum lengkap"; } else { if($result->count > 0) { $session->login_id = "$result"; $hidden = "style = 'diplay:none'"; $url=$pages->get("/files/")->httpUrl; header("Location:$url"); die(); } else { $note = "Akun tidak ditemukan"; } } } ?> And this code for login form
      <div class="frow-container"> <div class="frow centered mt-50"> <div class="col-md-1-3"> <div class="box p-40 shadow-light"> <h2 class="mb-20 text-center" <?=$hidden?>>Database Partitur<br>GII HIT</h2> <form method="post" <?=$hidden?>> <label>Username <input type="text" name="email"></label> <label>Password <input type="password" name="pass"></label> <input type="submit" name="submit" value="Masuk"> </form> <p class="notif"><?=$note;?></p> <div class="text-center"><?=$note2;?></div> </div> </div> </div> </div> Just for remember, my user data now is a pages, and i cannot give any permission to user data.
      Thank you very much for help.
    • By kyksh
      Hi!
      I need users to login by their email address. This works when I change the value in ProcessLogin.module
       122     protected $useEmailLogin = null;
      to
      122     protected $useEmailLogin = true;
      What would be a recommended way to enable this?
      There's this line in ProcessLogin.module:
        15  * @property bool|int $allowEmail Whether or not email login is allowed (0|false=off, 1|true=Yes, 2=Yes or name also allowed)
      But I can't figure out how to set this. I tried next to $useEmailLogin in ProcessLogin.module and in config.php, but neither takes effect.
      BTW I tried module LoginWithEmail but it seems outdated. My PW version is 3.0.165
    • By jploch
      Admin Theme Canvas
      A minimal admin theme with optimised page editor UI, based on Uikit 3.
      Currently this is close to stable, but users are advised to be cautious and test thoroughly.
      This theme is tested in all major Browsers including IE 11, Edge (>85), Chrome (>85), Firefox (>81), Safari (>11).

      If you find any bugs or have ideas for improvements, feel free to post your feedback.
      Download from Github
      Download from Modules Page
      Features
      Minimal black and white admin theme Fixed masthead navigation Direct access to page tree navigation inside page dropdown Less distraction for editors (when editing a page, the tabs are displayed as a dropdown menu inside the main navigation) Options to customise the ui Less distraction for editors

      Direct access to page tree navigation inside dropdown

      Page tree

      Options to customise the ui

      Login (inspired by AdminThemeBoss)

      Requirements
      Process Wire 3.0.100 or greater
      Installation
      Go to “Modules > Site > Add New“ Paste the Module Class Name “AdminThemeCanvas“ into the field “Add Module From Directory“ Click “Download And Install“ On the overview, click “Download And Install“ again… On the following screen, click “Install Now“ Go to your user profile page and change the theme to Admin Theme Canvas
    • 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.
×
×
  • Create New...