Ajax Handler v1.2
The Ajax Handler is a CakePHP Component that processes and handles AJAX requests. It determines what action should be dealt as an AJAX call, applies the appropriate filters, prepares the data for a response and responds with the appropriate headers.
Manual v1.x : Table of Contents
Auto Login v1.6 (Log)
Uploaded: 10/03/2009
Requires: PHP 5, CakePHP 1.2
Tested On: PHP 5.2.5, CakePHP 1.2.5
View Manual:
Auto Login
Package: Component
Category: CakePHP
Views: 4,742
AutoLogin is a CakePHP Component that will automatically login an Auth session if the user agrees to. The user has the ability to "remember" their login info when logging in and AutoLogin will store their information in a cookie to automatically log them in on their next visit.
Class Features:
Class Features:
- Requires no installation except for adding the checkbox into your user login forms
- Automatically saves the cookie and info when a user logs in
- Automatically kills the cookie and session when a user logs out
- Inserts a hash within the cookie so that it cannot be hijacked
- Encrypts the cookie so the information cannot be harvested
- Configuration options for cookie name and length
- Functionality for additional user updating or error logging
Top
1 - Installation
If you haven't already, download the script and place the auto_login.php file in your app/controllers/components/ folder. Once complete, simply add AutoLogin into your controllers $components property. AutoLogin must be placed after Auth in the $components array or it will not work properly.
The AutoLogin component will automatically save the user info to a cookie when they login at the location given for the Auth property $loginAction. It also works when logging out at by removing the cookie.
The final step is to create a checkbox in your login form named auto_login. The model used in the form should also match the User model you are using in your Auth.
var $components = array('Auth', 'AutoLogin');
The AutoLogin component will automatically save the user info to a cookie when they login at the location given for the Auth property $loginAction. It also works when logging out at by removing the cookie.
The final step is to create a checkbox in your login form named auto_login. The model used in the form should also match the User model you are using in your Auth.
<?php echo $form->input('auto_login', array('type' => 'checkbox', 'label' => 'Log me in automatically?')); ?>
Top
Read the whole documentation? Download the script now and try it yourself! Return to the Top
2 - Configuration
If you would like to change the name of the cookie, or the duration until the cookie expires (defaults to 2 weeks), you can change it in your AppController's beforeFilter().
Additionally, AutoLogin will try to determine what controller and action your login takes place at, by using the Auth->loginAction property. If it cannot determine the urls, you can set fallbacks by editing the $settings property (you must supply all settings if you are overwriting).
Adding your own logic or logging
If you need to do additional logging and updating that is not initially in Auths user login (for example updating a users last login time), you can place this extra code in a method called _autoLogin() within your AppController. Also if Auth login fails, you can do some error logging and reporting by creating a method called _autoLoginError(). Both of these will be called automatically and only if the method exists.
Additionally, AutoLogin will try to determine what controller and action your login takes place at, by using the Auth->loginAction property. If it cannot determine the urls, you can set fallbacks by editing the $settings property (you must supply all settings if you are overwriting).
function beforeFilter() { $this->AutoLogin->cookieName = 'rememberMe'; $this->AutoLogin->expires = '+1 month'; $this->AutoLogin->settings = array( 'controller' => 'Members', 'loginAction' => 'signin', 'logoutAction' => 'signout' ); }
Adding your own logic or logging
If you need to do additional logging and updating that is not initially in Auths user login (for example updating a users last login time), you can place this extra code in a method called _autoLogin() within your AppController. Also if Auth login fails, you can do some error logging and reporting by creating a method called _autoLoginError(). Both of these will be called automatically and only if the method exists.
class AppController extends Controller { /** * Run whenever auto login is successful * @param array $user - The Auth user session * @access private */ function _autoLogin($user) { } /** * Run whenever auto login fails * @param array $cookie - The login cookie data * @access private */ function _autoLoginError($cookie) { } }