6

浏览GitHub,我发现了一个非常强大的CakePHP 插件,名为CakeDC Users,它有很多功能(帐户验证、密码重置等)用于创建登录/身份验证系统。我喜欢它,因为它似乎是由一些实际的 CakePHP 开发人员编写的,并且它得到了很多更新,但它的任何地方似乎都绝对是文档。我最近刚刚遇到这个插件,因为我试图看看是否有比使用我自己的解决方案“滚动”更好的方法。所以我想知道这里是否有人有过这方面的经验,如果有的话,可以在网上找到一些不错的文档。

编辑自述文件的底部有一些东西,但对我来说并不太直观。

另一个问题,如果您不使用此插件,是否有您在 CakePHP 中使用的用于登录/身份验证的登录/身份验证插件?

4

3 回答 3

4

我在使用 CakeDC 插件时遇到了同样的问题,其中很多插件很少/没有文档。

但是,它没有“零”文档,您可以在阅读我的 github 页面底部的大部分内容中查看如何设置它。您还需要将它放在 AppController::beforeFilter() 方法中。

$this->Auth->authorize = 'controller';
$this->Auth->fields = array('username' => 'email', 'password' => 'passwd');
$this->Auth->loginAction = array('plugin' => 'users', 'controller' => 'users', 'action' => 'login', 'admin' => false);
$this->Auth->loginRedirect = '/';
$this->Auth->logoutRedirect = '/';
$this->Auth->authError = __('Sorry, but you need to login to access this location.', true);
$this->Auth->loginError = __('Invalid e-mail / password
combination.  Please try again', true);
$this->Auth->autoRedirect = true;
$this->Auth->userModel = 'User';
$this->Auth->userScope = array('User.active' => 1);
if ($this->Auth->user()) {
    $this->set('userData', $this->Auth->user());
    $this->set('isAuthorized', ($this->Auth->user('id') != ''));
} 

此外,您需要一个isAuthorized()函数,就像这样简单:

public function isAuthorized() {
    return true;
}

此外,您需要允许“登录”操作(这将涉及编辑插件文件)。只需将“登录”添加到$this->Auth->allow()in users_controller.php

于 2011-06-24T09:36:42.473 回答
1

经过详尽的搜索,我找到了关于如何使用 CakeDC 的教程!

这里是

于 2014-03-03T18:16:05.097 回答
1

这个问题现在已经很老了,但是由于它没有被标记为已解决,并且从那时起我们在文档上做了很多工作,我认为值得更新:

文档可以在这里找到:

对于 3+ 版本的框架

对于(旧)版本 2

于 2016-03-07T10:41:34.823 回答