CakePHPã§ã¦ã¼ã¶ã¼IDãã¡ã¼ã«ã¢ãã¬ã¹ã©ã¡ãã§ããã°ã¤ã³ã§ããããã«ããæ¹æ³
èªè¨¼æã«ãã¦ã¼ã¶IDã¨ãã¹ã¯ã¼ããªã©ã®çµã¿åããã ãã§ã¯ãªãã
ã¡ã¼ã«ã¢ãã¬ã¹ã¨ãã¹ã¯ã¼ãçãè¤æ°ã®ã«ã©ã ã©ãã§ããã°ã¤ã³ã§ããããã«ããæ¹æ³ã
ãµã³ãã«
Authã³ã³ãã¼ãã³ãããã®ã¾ã¾ä½¿ç¨ã
ä¸æ¹ã®çµã¿åããã§èªè¨¼ã«å¤±æããããããä¸åº¦ãå¥ã«ã©ã ãåç
§ãã¦ãã°ã¤ã³ã試ã¿ãã
ãã¥ã¼ã®inputã¿ã°ã®nameã«ã¯ä¸çµç®ã®ã«ã©ã åãã»ãããã¦ããã
<?php class UsersController extends AppController { var $components = array('Auth'); function beforeFilter() { parent::beforeFilter(); ãããã// ä¸çµç®ã®åç §ã«ã©ã è¨å® $this->Auth->fields = array( 'username' => 'username1', 'password' => 'password', ); $this->Auth->autoRedirect = false; // èªåã§ãªãã¤ã¬ã¯ãããªã $model = $this->Auth->userModel; if ($this->params['action'] === 'login' && isset($this->data[$model][$this->Auth->fields['password']])) { // ä¸åº¦èªè¨¼ãè¡ãã¨passwordãã£ã¼ã«ãã«NULLãè¨å®ããã¦ãã¾ãã®ã§éé¿ããã ãããããã// Configureã§ã¯ãªããã³ã³ããã¼ã©ã®ããããã£ãªã©ã«ä¿åãã¦ããã $password = $this->Auth->password($this->data[$model][$this->Auth->fields['password']]); Configure::write($model . '.password', $password); } } function login() { if (!empty($this->data) { if ($this->Auth->user()) { // ä¸çµç®ã®èªè¨¼ã«æåããå ´åã¯ãªãã¤ã¬ã¯ã $this->redirect($this->Auth->redirect());ã } else { // 失æããå ´å $field = 'username2'; $data = $this->data; $model = $this->Auth->userModel; // ãã¼ã¿ãåã»ãã $data[$model][$this->Auth->fields['password']] = Configure::read($model . '.password'); $data[$model][$field] = $data[$model][$this->Auth->fields['username']]; ãã // å¥ã«ã©ã ãåç §ããããã«å¤æ´ ãããããã$this->Auth->fields['username'] = $field; // ããä¸åº¦ãã°ã¤ã³ã試ã¿ã if ($this->Auth->login($data)) { // sessionã®ã¡ãã»ã¼ã¸ãåé¤ $this->Session->del('Message.auth'); $this->redirect($this->Auth->redirect());ã } } } } }
â»8/4 ä¸é¨ä¿®æ£
SQLãè¤æ°å¼ã°ãããã¨ã«ãªãã®ã§ãå¯è½ãªãã°ä¸è¨ãã¼ã¸ã§ç´¹ä»ããã¦ãããæ¹ã®ã»ããããããã
http://cakephp.jp/modules/newbb/viewtopic.php?topic_id=1128&forum=8&post_id=2297