PHP code example of k1low / reminder

1. Go to this page and download the library: Download k1low/reminder library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

k1low / reminder example snippets



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


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


  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
    ],
  ]);


  /**
   * 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;
  }


  /**
   * 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;
  }


  /**
   * 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;
    }
  }


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


  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 settings
  Configure::write('Reminder.setFlashElement', [
      'success' => 'alert',
      'error' => 'alert',
  ]);
  Configure::write('Reminder.setFlashParams', [
      'success' => [],
      'error' => [],
  ]);