Ubuntuのlocaleの変更
いつも忘れるのでメモ
apt-get install language-pack-ja
dpkg-reconfigure locales
reboot
CakePHPのAuthのredirect
以下
$this->Auth->autoRedirect = false;
になっている前提
CakePHPの設計上,認証が通ったあと,以前認証が必要だったurlならそこへ,それがない場合webrootに飛ばされる.
今回は認証が必要だったurlがない場合,webrootから変更する際のお話
loginの後の処理にかくのが王道だと思うけど,そのとき使うであろう「$this->Auth->redirect();」について
この関数は中身を見てみると呼び出されたときにSessionのurlを一旦消しているので
loginの後の処理に書く場合,2度以上使用するともちろん以前のurlが変更される
つまり,「以前認証が必要だったurlならそこへ,そうでないならwebroot以外に飛ばす」処理を書く場合,「$this->Auth->redirect();」は変数として関数内に格納しとかないといけない.
上記のことを書くと
<?php class AdminController extends AppController { var $uses = null; var $components = array('Auth'); function beforeFilter() { parent::beforeFilter(); $this->Auth->autoRedirect = false; } function login() { if($this->Auth->user()) { $url = $this->Auth->redirect(); if($url == DS) { $this->redirect('/admin'); } else { $this->redirect($url); } exit(); } } function logout() { $this->redirect($this->Auth->logout()); exit(); } } ?>
なんかつまずいたのでメモしときました
あとconfig/routes.phpでwebrootの処理を書くとか考えたけど全体にかかるのでないっぽい
コマンド(シェル)からAuthで使用するパスワードを表示する
認証機能を導入するとき,はじめの管理者のパスワードを
phpMyAdminなどから直接入力するときとかに便利
/vendors/shells/password.php
<?php App::import('Core', 'Security'); class PasswordShell extends Shell { /* function startup() { $this->controller = new Controller(); //print_r($this->controller); $this->Auth = new AuthComponent(); $this->Auth->startup($this->controller); } */ function main() { e(Security::hash(Configure::read('Security.salt').$this->args[0], $this->args[1])); e("\n"); $this->hr(); } } ?>
使い方(「orz」をmd5で暗号化した場合の文字列)
./cake password orz md5
結果
Welcome to CakePHP v1.2.3.8166 Console --------------------------------------------------------------- App : app Path: /home/hoge/public_html/project/hellow/lib/app --------------------------------------------------------------- 3c42c1b6d1fff2c1aeaf9076ad2c3892 ---------------------------------------------------------------