2017 © Pedro Peláez
 

library standard-auth

CakePHP StandardAuth

image

junkins/standard-auth

CakePHP StandardAuth

  • Wednesday, December 28, 2016
  • by Junkins
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

StandardAuth

Introduction

Authentication mail function when creating a user. Password reminder function., (*1)

Setup

  1. you load StandardAuthComponent.
<?php
namespace App\Controller

use Cake\Controller\Controller;

/**
 * AdminAppController
 */
class AdminAppController extends Controller
{
  /**
   * initialize
   */
  public function initialize()
  {
      parent::initialize();
      $this->loadComponent('StandardAuth.StandardAuth', [
        'authenticate' => [
            'Form' => [
                'userModel' => 'Admins',
                'fields' => [
                    'username' => 'username',
                    'password' => 'password'
                ],
            ]
        ],
      ]);
  }
}
  1. you load StandardAuthBehavior.
<?php
namespace App\Model\Table;

use Cake\ORM\Table;

/**
 * AdminsTable
 */
class AdminsTable extends Table
{
  /**
   * initialize
   */
  public function initialize(array $config)
  {
      $this->addBehavior('StandardAuth.StandardAuth');
  }
}
  1. you define action on Controller.
<?php

    /**
     * approval
     */
    public function approval($id, $hash)
    {
        $this->Admins->get($id);
        $result = $this->StandardAuth->approval($id, $hash);
        if ($result) {
            $this->Flash->success(__('The user has been saved.'));
        } else {
            $this->Flash->error(__('Invalid credentials, try again'));
        }
        return $this->redirect(['action' => 'login']);
    }

    /**
    * reset
    * @author ito
    */
    public function reset()
    {
        $this->viewBuilder()->layout('login');
        $entity = $this->Admins->newEntity();
        if ($this->request->is('post')) {
            $data = $this->request->data;
            $entity = $this->Admins->patchEntity($entity, $data, ['validate' => 'reset']);
            if (
                empty($entity->errors()) &&
                $this->Admins->resetPassword($entity->email)
            ) {
                $this->Flash->success(__('The user has been saved.'));
                return $this->redirect(['action' => 'login']);
            } else {
                $this->Flash->error(__('The user could not be saved. Please, try again.'));
            }
        }

        $this->set(compact('entity'));
        $this->set('_serialize', ['entity']);
    }
}

The Versions

28/12 2016

dev-master

9999999-dev

CakePHP StandardAuth

  Sources   Download

28/12 2016

dev-create-composer-json

dev-create-composer-json

CakePHP StandardAuth

  Sources   Download