「認証」カテゴリーアーカイブ

会員、Auth

パスワードを暗号化させない

http://www.maruhisa.org/2011/11/30/cakephp2-0using_plainpassword/
http://www.matomater.com/687/

[php]
/lib/Cake/Utility/Security.php 107行目あたり

public static function hash($string, $type = null, $salt = false) {

return $string;
/*if (empty($type)) {
$type = self::$hashType;
}
$type = strtolower($type);

if ($type === ‘blowfish’) {
return self::_crypt($string, $salt);
}
if ($salt) {
if (!is_string($salt)) {
$salt = Configure::read(‘Security.salt’);
}
$string = $salt . $string;
}

if (!$type || $type === ‘sha1’) {
if (function_exists(‘sha1’)) {
return sha1($string);
}
$type = ‘sha256’;
}

if ($type === ‘sha256’ && function_exists(‘mhash’)) {
return bin2hex(mhash(MHASH_SHA256, $string));
}

if (function_exists(‘hash’)) {
return hash($type, $string);
}
return md5($string);*/
}
[/php]

ログインしているユーザー情報を取得

http://cakephp.jp/modules/newbb/viewtopic.php?topic_id=2573&forum=8

[php]
$userinfo = $this->Auth->user();
debug($userinfo);
[/php]

絞り込むぜいっ!

[php]
//ログインユーザーのIDとレクチャーのIDが同じやつ
$userinfo = $this->Auth->user();
debug($this->Lecture->find(‘all’,array(‘conditions’=>array(‘id’ => $userinfo))));
[/php]

または

[php]
$userinfo = $this->Auth->user(array(‘fields’ => ‘id’)); //ログインしているIDだけ取得
$this->set(‘children’, $this->Child->find(‘all’,array(‘conditions’=>array(‘user_id’=> $userinfo)))); //Childが持っているuser_idとログインのIDの同じやつ
[/php]

cakephp adminルーティング

adminルーティング

参考:http://blog.dicecream.net/2012/04/admin.php

/cake/app/Config/core.php

[php]
Configure::write(‘Routing.prefixes’, array(‘admin’)); //コメントを外す
[/php]

管理者用としても使いたいコントローラーのアクション名にadmin_をつける

UsersControllerのaddアクションを管理者用にしたいのであれば、

[php]
public function admin_add() {
// 処理
}
[/php]

view用のファイル(admin_add.ctp)を用意します。

http://www.example.com/admin/users/addが管理者用のURLになる

特定のページだけは認証なしで見えるようにする

参考:http://www.misty540.net/wp/article_187.html

pp_controller:beforeFilter  内で allow メソッドを使います。

[php]
// homeと test に誰でもアクセス可能
$this->Auth->allow(array(‘controller’ => ‘pages’, ‘action’ => ‘display’, ‘home’));
$this->Auth->allow(array(‘controller’ => ‘pages’, ‘action’ => ‘display’, ‘test’));
[/php]

ACLでアクセス管理「CakePHP2.2」

ACLのデータベーステーブルの初期化

[text]./app/Console/cake schema create DbAcl[/text]

ACOデータの作成

[text]./app/Console/cake acl create aco root controllers[/text]

参考: