PHP code example of ceeram / authenticate
1. Go to this page and download the library: Download ceeram/authenticate library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once ('vendor/autoload.php' );
ceeram / authenticate example snippets
public $components = array (
'Auth' => array (
'authenticate' => array (
'Authenticate.MultiColumn' => array (
'fields' => array (
'username' => 'login' ,
'password' => 'password'
),
'columns' => array ('username' , 'email' ),
'userModel' => 'User' ,
'scope' => array ('User.active' => 1 )
)
)
)
);
$this ->Auth->authenticate = array (
'Authenticate.MultiColumn' => array (
'fields' => array (
'username' => 'login' ,
'password' => 'password'
),
'columns' => array ('username' , 'email' ),
'userModel' => 'User' ,
'scope' => array ('User.active' => 1 )
)
);
public $components = array (
'Auth' => array (
'authenticate' => array (
'Authenticate.Cookie' => array (
'fields' => array (
'username' => 'login' ,
'password' => 'password'
),
'userModel' => 'SomePlugin.User' ,
'scope' => array ('User.active' => 1 )
)
)
)
);
$this ->Auth->authenticate = array (
'Authenticate.Cookie' => array (
'fields' => array (
'username' => 'login' ,
'password' => 'password'
),
'userModel' => 'SomePlugin.User' ,
'scope' => array ('User.active' => 1 )
)
);
public $components = array (
'Auth' => array (
'authenticate' => array (
'Authenticate.Cookie' => array (
'fields' => array (
'username' => 'login' ,
'password' => 'password'
),
'userModel' => 'SomePlugin.User' ,
'scope' => array ('User.active' => 1 )
),
'Authenticate.MultiColumn' => array (
'fields' => array (
'username' => 'login' ,
'password' => 'password'
),
'columns' => array ('username' , 'email' ),
'userModel' => 'User' ,
'scope' => array ('User.active' => 1 )
)
)
)
);
public function beforeFilter () {
$this ->Cookie->type('rijndael' );
}
App::uses('AppController' , 'Controller' );
class UsersController extends AppController {
public $components = array ('Cookie' );
public function beforeFilter () {
$this ->Cookie->type('rijndael' );
}
public function login () {
if ($this ->Auth->loggedIn() || $this ->Auth->login()) {
$this ->_setCookie();
$this ->redirect($this ->Auth->redirect());
}
}
protected function _setCookie () {
if (!$this ->request->data('User.remember_me' )) {
return false ;
}
$data = array (
'username' => $this ->request->data('User.username' ),
'password' => $this ->request->data('User.password' )
);
$this ->Cookie->write('User' , $data, true , '+1 week' );
return true ;
}
public function logout () {
$this ->Auth->logout();
$this ->Session->setFlash('Logged out' );
$this ->redirect($this ->Auth->redirect('/' ));
}
}
public $components = array (
'Auth' => array (
'authenticate' => array (
'Authenticate.Token' => array (
'parameter' => '_token' ,
'header' => 'X-MyApiTokenHeader' ,
'userModel' => 'User' ,
'scope' => array ('User.active' => 1 ),
'fields' => array (
'username' => 'username' ,
'password' => 'password' ,
'token' => 'public_key' ,
),
'continue' => true
)
)
)
);
$this ->Auth->authenticate = array (
'Authenticate.Token' => array (
'parameter' => '_token' ,
'header' => 'X-MyApiTokenHeader' ,
'userModel' => 'User' ,
'scope' => array ('User.active' => 1 ),
'fields' => array (
'username' => 'username' ,
'password' => 'password' ,
'token' => 'public_key' ,
),
'continue' => true
)
);