.ログイン
ユーザ名:

パスワード:


パスワード紛失

新規登録

.検索

.メインメニュー

.フォーラムメニュー

.オンライン状況
15 人のユーザが現在オンラインです。 (14 人のユーザが フォーラム を参照しています。)

登録ユーザ: 0
ゲスト: 15

もっと...

.
.リンク集

メイン
   helper,component,script
     Authコンポーネントで、ログイン成功時に・・・
投稿するにはまず登録を

スレッド表示 | 新しいものから 前のトピック | 次のトピック | 下へ
投稿者 スレッド
dododo
投稿日時: 2008-7-2 22:19
Baker スタート
登録日: 2008-5-14
居住地:
投稿: 13
Authコンポーネントで、ログイン成功時に・・・
1.2 RC2を使用しています。

Authコンポーネントで、ログイン成功時に、
特定のアクション
(たとえば、usersテーブルのlastloginを更新)を実行したいのですが、どのようにすればよいでしょうか?

よろしくお願いします。
shun
投稿日時: 2008-7-3 10:37
Cake 職人
登録日: 2006-7-14
居住地: 東京、日本
投稿: 1007
Re: Authコンポーネントで、ログイン成功時に・・・
AuthComponent には、

<?php
$this
->Auth->loginRedirect '/users/loginStart';
?>



などのように、ログイン後に飛ぶ先を設定できます。
そこで、またはそこから、“特定のアクション”を設定してみるのはいかがでしょうか。
redgasuki
投稿日時: 2008-7-3 19:36
Baker ユーザ
登録日: 2008-2-5
居住地:
投稿: 24
Re: Authコンポーネントで、ログイン成功時に・・・
shunさんの方法の方がエレガントですが
こんな感じで泥臭く書くと、ログインに失敗した場合の処理もかけます
(一定回数失敗したら、しばらくログインできなくなる、など)

<?php
function login(){
    if(
$this ->data){    
        
$user $this->Auth->user();    
        if(!empty(
$user)){
            
//ログインに成功した時の処理
        
}else{
            
//ログイン失敗した時の処理
        
}
    }
}
?>

dododo
投稿日時: 2008-7-5 22:48
Baker スタート
登録日: 2008-5-14
居住地:
投稿: 13
Re: Authコンポーネントで、ログイン成功時に・・・
shunさん、redgasukiさん、ありがとうございます。
Authコンポーネントは、以外と自由度が高くて、
かなり便利ですね!

いろいろいじくってみたいと思います。
max
投稿日時: 2008-7-8 11:54
Baker ユーザ
登録日: 2006-11-7
居住地:
投稿: 28
Re: Authコンポーネントで、ログイン成功時に・・・
redgasukiさんの例の補足です。

autoRedirectをオフにしておくとアクション内の処理を実行させる事が出来ます。


function beforeFilter() {  
    $this->Auth->autoRedirect = false; 
}


マニュアルに記述あります。
http://book.cakephp.org/view/172/authentication#autoredirect-395
news
投稿日時: 2008-7-15 21:38
Cake 職人
登録日: 2007-4-4
居住地:
投稿: 1277
Re: Authコンポーネントで、ログイン成功時に・・・
英語ですが、まさにこの話題です。

HirdWeb
CakePHP Authentication
http://www.hirdweb.com/2008/07/14/cakephp-authentication/


<?php
function login() {
    if (
$this->Auth->user()) {
        if (!empty(
$this->data)) {
            
$san = new Sanitize();
            
// Sanitize the input of items we do not know what the end user put in.
            
$this->data['User']['username'] = $san->paranoid($this->data['User']['username']);

            
// Grab the data from the User table and set them to the cookie array
            
$cookie = array();
            
$cookie['user_id'] = $this->Auth->user(’user_id’);
            
$cookie['full_name'] = $this->Auth->user(’full_name’);
            
$cookie['ast_login'] = $this->Auth->user(’last_login’);
            
$cookie['last_login_ip'] = $this->Auth->user(’last_login_ip’);

            
$this->Session->write(’Auth.User’$cookie); 

            
$update['User']['user_id'] = $userid;
            
$update['User']['last_login'] = $this->data['User']['last_login'];
            
$update['User']['last_login_ip'] = $this->data['User']['last_login_ip'];
            
$this->User->save($updatefalse, array(’user_id’‘last_login’‘last_login_ip’));

            
$this->redirect($this->Auth->redirect());
        }
    }

    if (empty(
$this->data)) {
        
// Check to see if they are logged in
        
if (isset($_SESSION['Auth']['User']['username'])){
            
$this->Session->setFlash(__(’You are already logged intrue));
            
$this->redirect(array(’action’ => ‘index’));
        }

        
// Perform other checks on the empty data and set up the form.
        
$cookie $this->Session->read(’Auth.User’);
        if (!
is_null($cookie)) {
            if (
$this->Auth->login($cookie)) {
                
//  Clear auth message, just in case we use it.
                
$this->Session->del(’Message.auth’);
                
$this->redirect($this->Auth->redirect());
            }
        }
    }

}
?>

スレッド表示 | 新しいものから 前のトピック | 次のトピック | トップ

投稿するにはまず登録を
 


. .