Adding some additional behavior to login controller
Permalink
Hello. I am new here and can't find anything regarding my problem.
I want to add some additional behavior to login/logout. Specifically, I want to add a cookie after successful login and delete that cookie after logout. The reason behind this that I use Varnish in front of my webserver and I don't want to cache pages of logged in users.
I found a blank implementation of custom login controller in - concrete/controllers/login.php
I implemented my custom logic as:
I thought this class will override the core login class - Concrete5_Controller_Login but my code doesn't seem to run.
What I am doing wrong? I have little experience with php.
Also, could someone tell me how to properly add a cookie and delete it in concrete5? Because I don't think that the above solution is 100% right.
I would appreciate any help. Also you could just point me to the right direction e.g. a link to specific doc or something..
I want to add some additional behavior to login/logout. Specifically, I want to add a cookie after successful login and delete that cookie after logout. The reason behind this that I use Varnish in front of my webserver and I don't want to cache pages of logged in users.
I found a blank implementation of custom login controller in - concrete/controllers/login.php
I implemented my custom logic as:
<?php defined('C5_EXECUTE') or die("Access Denied."); class LoginController extends Concrete5_Controller_Login { protected function finishLogin( $loginData=array() ) { Log::addEntry('CUSTOM LOGIN'); try { parent::finishLogin($loginData); if (!isset($_SESSION['Logged'])) { $_SESSION['Logged'] = "1"; } } } public function logout() { parent::logout(); if (isset($_SESSION['Logged'])) {
Viewing 15 lines of 20 lines. View entire code block.
I thought this class will override the core login class - Concrete5_Controller_Login but my code doesn't seem to run.
What I am doing wrong? I have little experience with php.
Also, could someone tell me how to properly add a cookie and delete it in concrete5? Because I don't think that the above solution is 100% right.
I would appreciate any help. Also you could just point me to the right direction e.g. a link to specific doc or something..
Thanks, I have already read that post. It wasn't really helpful. And that is why I decided to implement the above scheme. The question is not about using of varnish. I just want to know how to make the above code to work :)
This might help:http://stackoverflow.com/questions/15523661/overriding-core-login-c...
To override the login controller first make sure your file is at /controllers/singlepages/login.php.
Review the login class at /concrete/core/controllers/login.php.
You need to copy 2 functions over to your class the first is "do_login" the second is "logout". In do_login you could add a call to your finishLogin() function. You could merge your logout() function code into the standard logout function.
The key point here is you need to copy the original functions to your class if you want to change them.
A complete different approach to this might be to use Events, there is probably an event login and logout and you could have your code run during that event. That might actually be the more "correct" way... but overriding the class should be fine as well.
To override the login controller first make sure your file is at /controllers/singlepages/login.php.
Review the login class at /concrete/core/controllers/login.php.
You need to copy 2 functions over to your class the first is "do_login" the second is "logout". In do_login you could add a call to your finishLogin() function. You could merge your logout() function code into the standard logout function.
The key point here is you need to copy the original functions to your class if you want to change them.
A complete different approach to this might be to use Events, there is probably an event login and logout and you could have your code run during that event. That might actually be the more "correct" way... but overriding the class should be fine as well.
http://www.concrete5.org/community/forums/installation/c5-and-varni...