2017 © Pedro Peláez
 

cakephp-plugin reminder

Password Reminder plugin for CakePHP

image

k1low/reminder

Password Reminder plugin for CakePHP

  • Friday, January 16, 2015
  • by k1LoW
  • Repository
  • 1 Watchers
  • 1 Stars
  • 1,850 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 1 % Grown

The README.md

Password reminder plugin for CakePHP

Usage

Create reminders table

$ cake schema create reminders --plugin Reminder

Load Reminder plugin

<?php
  CakePlugin::load([
    'Reminder' => ['bootstrap' => true, 'routes' => true],
  ]);

Set $reminder to app/Config/email.php

<?php
  public $reminder = [
    'transport' => 'Smtp',
    'subject' => 'Password reminder',
    'from' => ['reminder@example.com' => 'Reminder'],
    'host' => 'smtp.example.com',
    'username' => 'reminder@example.com',
    'password' => 'xxxxxxxxx',
    'log' => true,
    'charset' => 'utf-8',
    'headerCharset' => 'utf-8',
  ];

Set Reminder.models

<?php
  Configure::write('Reminder.models', [
    'User' => [
      'email' => 'email', // email field name
      'expire' => 60 * 60 * 24, // reminder url expire range (seconds)
      'subject' => 'This is Reminder mail', // reminder mail subject
    ],
  ]);

Create User::findAccountById(), User::validateAndFindAccount(), User::resetPassword()

<?php
  /**
   * findAccountById
   * find account by primary key
   * for Reminder plugin
   *
   */
  public function findAccountById($id){
    $query = array(
      'conditions' => array(
        'User.id' => $id
      ),
    );
    $user = $this->find('first', $query);
    return $user;
  }
<?php
  /**
   * validateAndFindAccount
   * check $data and find account
   * for Reminder plugin
   *
   */
  public function validateAndFindAccount($data){
    $email = $data['User']['email'];
    if (empty($email)) {
      $this->invalidate('email', 'Not empty email');
      throw new ReminderException();
    }
    $query = array(
      'conditions' => array(
        'User.email' => $email
      ),
    );
    $user = $this->find('first', $query);
    return $user;
  }
<?php
  /**
   * resetPassword
   * reset account password
   * for Reminder plugin
   *
   */
  public function resetPassword($data){
    $this->set($data);
    if (!empty($this->data['User']['password'])) {
      $this->data['User']['password'] = Security::hash($this->data['User']['password'], null, true);
    }
    if (!empty($this->data['User']['password_confirm'])) {
      $this->data['User']['password_confirm'] = Security::hash($this->data['User']['password_confirm'], null, true);
    }
    $result = $this->save(null, true);
    if ($result) {
      $this->data = $result;
      return true;
    } else {
      return false;
    }
  }

Access /reminder/user

Access /reminder/user, (*1)

Design change

Default layout

<?php
  // default layout setting
  Configure::write('Reminder.layout', 'mylayout');

View change

Create following view/template files., (*2)

  • app/View/Plugin/Reminder/Reminder/send.ctp
  • app/View/Plugin/Reminder/Reminder/sent.ctp
  • app/View/Plugin/Reminder/Reminder/reset_password.ctp
  • app/View/Plugin/Reminder/Reminder/complete.ctp
  • app/View/Plugin/Reminder/Emails/text/reset_mail.ctp

Custom settings

Create view/template/layout files and custom settings, (*3)

<?php
  Configure::write('Reminder.models', [
    'User' => [
      'email' => 'email',
      'expire' => 60 * 60 * 24,
      'layout' => 'User/default', // User custom layout setting
      'view' => [ // User custom view/template setting
        'send' => 'user_send',
        'sent' => 'user_sent',
        'reset_password' => 'user_reset_password',
        'complete' => 'user_complete',
        'reset_mail' => 'user_send',
      ],
    ],
    'Administrator' => [
      'email' => 'email',
      'expire' => 60 * 60,
      'layout' => 'Admin/default', // Administrator layout setting
    ],
  ]);

setFlash Messages

<?php
  // setFlash settings
  Configure::write('Reminder.setFlashElement', [
      'success' => 'alert',
      'error' => 'alert',
  ]);
  Configure::write('Reminder.setFlashParams', [
      'success' => [],
      'error' => [],
  ]);

License

The MIT License, (*4)

The Versions

16/01 2015

dev-master

9999999-dev https://github.com/k1LoW/Reminder

Password Reminder plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp reset password

16/01 2015

0.0.4

0.0.4.0 https://github.com/k1LoW/Reminder

Password Reminder plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp reset password

15/01 2015

0.0.3

0.0.3.0 https://github.com/k1LoW/Reminder

Password Reminder plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp reset password

15/01 2015

0.0.2

0.0.2.0 https://github.com/k1LoW/Reminder

Password Reminder plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp reset password

15/01 2015

0.0.1

0.0.1.0 https://github.com/k1LoW/Reminder

Password Reminder plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp reset password