2017 © Pedro Peláez
 

cakephp-plugin cake3-cookieauth

A simple Cake3 plugin to authenticate users with Cookies.

image

xety/cake3-cookieauth

A simple Cake3 plugin to authenticate users with Cookies.

  • Tuesday, October 25, 2016
  • by Xety
  • Repository
  • 4 Watchers
  • 18 Stars
  • 14,399 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 10 Forks
  • 5 Open issues
  • 6 Versions
  • 6 % Grown

The README.md

Cake3 CookieAuth

A simple Cake3 plugin to authenticate users with Cookies. This plugin is based on the awesome plugin FriendsOfCake/Authenticate but with a different setup., (*1)

Build Status Coverage Status Scrutinizer Latest Stable Version Total Downloads License, (*2)

Requirements

  • CakePHP 3.X

Installation

Run : composer require xety/cake3-cookieauth:1.* Or add it in your composer.json: ``` php "require": { "xety/cake3-cookieauth": "1.*" },, (*3)


## Configuration ``` php 'Xety/Cake3CookieAuth.Cookie' => [ 'cookie' => [ 'name' => 'CookieAuth' ] ]

All others configuration option can be found on the official CakePHP documentation., (*4)

Usage

In your config/bootstrap.php add : ``` php Plugin::load('Xety/Cake3CookieAuth');, (*5)


In your `AppController` : ``` php public $components = [ 'Cookie', 'Auth' => [ 'authenticate' => [ 'Form', 'Xety/Cake3CookieAuth.Cookie' ] ] ];

In your AppController, in the beforeFilter action : ``` php public function beforeFilter(Event $event) { //Automaticaly Login. if (!$this->Auth->user() && $this->Cookie->read('CookieAuth')) {, (*6)

    $user = $this->Auth->identify();
    if ($user) {
        $this->Auth->setUser($user);
    } else {
        $this->Cookie->delete('CookieAuth');
    }
}

}, (*7)

//If you want to update some fields, like the last_login_date, or last_login_ip, just do : public function beforeFilter(Event $event) { //Automaticaly Login. if (!$this->Auth->user() && $this->Cookie->read('CookieAuth')) { $this->loadModel('Users');, (*8)

    $user = $this->Auth->identify();
    if ($user) {
        $this->Auth->setUser($user);

        $user = $this->Users->newEntity($user);
        $user->isNew(false);

        //Last login date
        $user->last_login = new Time();
        //Last login IP
        $user->last_login_ip = $this->request->clientIp();
        //etc...

        $this->Users->save($user);
    } else {
        $this->Cookie->delete('CookieAuth');
    }
}

}, (*9)


In your `login` action, after `$this->Auth->setUser($user);` : ``` php //It will write Cookie without RememberMe checkbox $this->Cookie->configKey('CookieAuth', [ 'expires' => '+1 year', 'httpOnly' => true ]); $this->Cookie->write('CookieAuth', [ 'username' => $this->request->data('username'), 'password' => $this->request->data('password') ]); //If you want use a RememberMe checkbox in your form : //In your view echo $this->Form->checkbox('remember_me'); //In the login action : if($this->request->data('remember_me')) { $this->Cookie->configKey('CookieAuth', [ 'expires' => '+1 year', 'httpOnly' => true ]); $this->Cookie->write('CookieAuth', [ 'username' => $this->request->data('username'), 'password' => $this->request->data('password') ]); }

Contribute

Follow this guide to contribute, (*10)

The Versions

25/10 2016

dev-master

9999999-dev https://github.com/Xety/Cake3-CookieAuth

A simple Cake3 plugin to authenticate users with Cookies.

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin cakephp auth cookie login authenticate cake3

25/10 2016

v1.4

1.4.0.0 https://github.com/Xety/Cake3-CookieAuth

A simple Cake3 plugin to authenticate users with Cookies.

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin cakephp auth cookie login authenticate cake3

05/01 2016

v1.3

1.3.0.0 https://github.com/Xety/Cake3-CookieAuth

A simple Cake3 plugin to authenticate users with Cookies.

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin cakephp auth cookie login authenticate cake3

01/04 2015

v1.2

1.2.0.0 https://github.com/Xety/Cake3-CookieAuth

A simple Cake3 plugin to authenticate users with Cookies.

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin cakephp auth cookie login authenticate cake3

07/11 2014

v1.1

1.1.0.0 https://github.com/Xety/Cake3-CookieAuth

A simple Cake3 plugin to authenticate users with Cookies.

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin cakephp auth cookie login authenticate cake3

05/11 2014

v1.0

1.0.0.0 https://github.com/Xety/Cake3-CookieAuth

A simple Cake3 plugin to authenticate users with Cookies.

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin cakephp auth cookie login authenticate cake3