k1low/reminder

CakePHP 的密码提醒插件

支持包维护!
k1LoW

安装量: 3,482

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 2

分支: 0

公开问题: 0

类型:cakephp-plugin

0.0.4 2015-01-16 07:34 UTC

This package is auto-updated.

Last update: 2024-09-06 09:34:33 UTC


README

使用方法

创建提醒表

$ cake schema create reminders --plugin Reminder

加载提醒插件

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

将 $reminder 设置为 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',
  ];

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

创建 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;
    }
  }

访问 /reminder/user

访问 /reminder/user

设计更改

默认布局

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

视图更改

创建以下视图/模板文件。

  • 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

自定义设置

创建视图/模板布局文件和自定义设置

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

设置闪存消息

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

许可证

MIT 许可证