2017 © Pedro PelĂĄez
 

cakephp-plugin t-auth

Auth plugin for CakePHP

image

rederlo/t-auth

Auth plugin for CakePHP

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

TAuth

in config/bootstrap.php


//Enable Cors DispatcherFactory::add('TAuth.Cors', ['priority' => 1]); //Enable plugin Plugin::load('TAuth', ['bootstrap' => false, 'routes' => false]);

in src/AppController.php

use \TAuth\Controller\AuthTrait;
    public function initialize()
    {
        parent::initialize();
        $auth = new \TAuth\Controller\AuthBuilder([
            'model' => 'peoples',
            'scope_auth' => ['username' => 'email'],
            'scope_jwt' => ['username' => 'id']
        ]);

        $this->loadComponent('Auth', $auth->getConfig());
    }

is get user id

    public function getUserId()
    {
        return $this->getUser();
    }

Generate database

bin/cake migrations migrate --plugin TAuth

Generate data in tables

bin/cake migrations seed --seed <fileSeed> --plugin TAuth

New User

public function add()
{
    $users = $this->Users->newEntity();
    if($this->request->is('post')){
        $users = $this->Users->patchEntity($users, $this->request->data());
        if ($this->Users->save($users)) {
            $auth = new AuthFactory();
            //Expected Type Entity
            $auth->create($users);
            $token = $auth->build();
        }
    }
    $this->set(compact('token'));
    $this->set('_serialize', ['token']);
}

Login

public function login()
{
    if ($this->request->is('post')) {
        $user = $this->Auth->identify();
        if ($user) {
            $this->Auth->setUser($user);
            return $this->redirect($this->Auth->redirectUrl());
        }
        $this->Flash->error(__('Usernamme or password Ă­nvalid, try again.'));
    }
}

Authorized

/**
* @param $user
* @return bool
*/
public function isAuthorized($user)
{
    return (new Authorize($this, $user['id']))->exec();
}

Params token

$auth = new AuthFactory();
$auth->create($users, ['group_id' => $group_id]);

GetParamsToken

/**
* @return Array
*/
$this->getParamsHeader();

The Versions

28/04 2017

dev-master

9999999-dev

Auth plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires