Page 1 of 1
					
				Custom Login / Registration Look & Feel
				Posted: Tue Feb 05, 2019 6:31 pm
				by jafo
				Hi,
One of the things we are looking to do, is deep link into an event.  I think i have figured out some of that but one thing we would like to do is change the look and feel on the login / registration pages.  I found the Template/Users/login.ctp file but clearly there is an entire theme being applied to it.  Do you have some directions or docs (might be just in the cake stuff that I haven't found yet) to help me customize the look and feel of those pages only OR let me "create a custom page" that I direct users to?
Hope that makes sense...
Thanks,
Brian
			 
			
					
				Re: Custom Login / Registration Look & Feel
				Posted: Tue Feb 05, 2019 6:42 pm
				by GregS
				There is a section about Themes in the readme, that should get you on the right path. If you run into specific issues, let me know.
			 
			
					
				Re: Custom Login / Registration Look & Feel
				Posted: Thu Feb 07, 2019 2:26 pm
				by jafo
				First, as I'm still learning CakePHP, I am really impressed with what all it can do quickly.
Second, here is the challenge at this point:
- I can create a plugin and make a theme which affects everyone by adding a default.ctp into /plugins/MyTheme/src/Template/Layout.  NOTE: I altered the app_local.php as noted in the readme
- What I can't figure out how to do, is theme ONLY the login.ctp & create_account.ctp located in /src/Template/Users/
Thoughts on how to proceed:
- I could create the exact same layout as what you have now into my theme/plugin, BUT put code logic in it to see the request is for the login page and then use a different file.
- I could modify the User controller to specify the theme but then I think i'm breaking the whole point of how CakePHP is supposed to work.
Neither seems right but it is what I have found so far.  In the theme and plugin manuals, it looked like I could replace functionality of another plugin, but that didn't seem to fit to what I was trying to do.  Let me know your thoughts.
~Brian
			 
			
					
				Re: Custom Login / Registration Look & Feel
				Posted: Thu Feb 07, 2019 3:04 pm
				by GregS
				Ah, interesting! I'm not sure off the top of my head how to do this. Plugins are excellent for replacing things, but not always so good for extending. What I should probably do is add a callback method that will be used when loading a theme plugin. You could then implement a callback that would register an event listener which would be called before the view is rendered; that listener would check the controller and action and change the layout as required. Sounds complicated, but it's really not too bad. I won't have a chance to do this for a few days, as I'm in the middle of another update. If you're an experienced programmer and just new to CakePHP, you could look at my existing InitializationListener (under src/Event), make your own based on that, and load it manually (for now) in config/bootstrap.php.
			 
			
					
				Re: Custom Login / Registration Look & Feel
				Posted: Fri Feb 08, 2019 2:20 am
				by jafo
				Hi Greg,
Great suggestion on using your listener.  I hacked yours up a bit for now until the new method works (sorry  

 ).
Code: Select all
	public function beforeRender(Event $event) {
		// Set the theme, if any
		
		//\Cake\Log\Log::write('error', $event->subject);
		$event_info = $event->subject->request->url;
		\Cake\Log\Log::write('error', $event_info);
		if ($event_info == 'users/login') {
			\Cake\Log\Log::write('error','Found User Login');
			Plugin::load('LoginTheme');
			$event->subject()->viewBuilder()->theme('LoginTheme');
		}
		else {
			\Cake\Log\Log::write('error','Not user login: ' . $event_info);
			$theme = Configure::read('App.theme');
			if (!empty($theme)) {
				Plugin::load($theme);
				// Assumption here is that the subject is always a controller
				$event->subject()->viewBuilder()->theme($theme);
			}
		}
	}
NOTE: no judgement on my php skills please, they are a tad rusty.  

 
			
					
				Re: Custom Login / Registration Look & Feel
				Posted: Thu Mar 14, 2019 11:43 pm
				by GregS
				Just looking into the same thing for another project today, and learned that you can change the layout from inside a view. So, you might just need to:
- create your plugin folder
- make your own src/Template/Users/login.ctp
- make your own src/Template/Layout/login.ctp
- somewhere in your login view, include 
No need for a listener at all! Easy peasy.