Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // AppController.php
- public function initialize() {
- parent::initialize();
- $this->loadComponent('Flash');
- $this->loadComponent('Auth', [
- 'loginRedirect' => ['controller' => 'Users', 'action' => 'profile'],
- 'logoutRedirect' => ['controller' => 'Search', 'action' => 'index'],
- 'loginAction' => ['controller' => 'Users','action' => 'login'],
- ]);
- }
- // UsersController.php
- public function login() {
- /*$user = $this->Users->newEntity(['id' => 1]);
- $user = $this->Users->patchEntity($user, ['password' => '123456']);
- $this->Users->save($user);*/
- if ($this->request->is('post')) {
- $user = $this->Auth->identify();
- $this->set('req', $this->request->data);
- $this->set('user', $user);
- }
- }
- // Model/Table/UsersTable.php
- class UsersTable extends Table {
- }
- // Model/Entity/User.php
- class User extends Entity {
- protected $_accessible = ['*' => true];
- protected function _setPassword($value) {
- return (new DefaultPasswordHasher)->hash($value);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment