Binds access control with user authentication and session management.
Inheritance: extends AuthComponent
 /**
  * 共通設定
  *
  * @return	void
  * @access	public
  */
 public function beforeFilter()
 {
     //基底の設定
     parent::beforeFilter();
     /* 認証設定 */
     //専用セッションキーの指定
     BcAuthComponent::$sessionKey = "BcAuth.MobilePost";
     //未認証許可
     $this->BcAuth->allow('login', 'smartphone_login');
     // 認証時の設定
     $this->BcAuth->authenticate = array('Form' => array('userModel' => 'User', 'fields' => array('username' => 'name', 'password' => 'password')));
     //ログインアクション
     $this->BcAuth->loginAction = array('controller' => 'mobile_posts', 'action' => 'login', 'plugin' => 'mobile_post');
     $this->BcAuth->loginRedirect = array('controller' => 'mobile_posts', 'action' => 'index', 'plugin' => 'mobile_post');
     $this->BcAuth->logoutRedirect = array('controller' => 'mobile_posts', 'action' => 'login', 'plugin' => 'mobile_post');
     //自動ログイン
     $userID = $this->BcAuth->user('id');
     if (empty($userID)) {
         $cookieData = $this->Cookie->read('BcAuth');
         if (!empty($cookieData)) {
             $loginData['User']['username'] = $cookieData['MobilePost']['username'];
             $loginData['User']['password'] = $cookieData['MobilePost']['password'];
             if ($this->BcAuth->login($loginData)) {
                 $this->Session->setFlash(__('ログインしました。'));
                 $this->redirect($this->BcAuth->redirect());
             }
         }
     }
     /* 表示設定 */
     //専用レイアウト適用
     $this->layout = 'MobilePost.mobile_post';
 }
 /**
  * セッションキーをセットする
  * 
  * @param string $sessionKey
  */
 public function setSessionKey($sessionKey)
 {
     self::$sessionKey = $sessionKey;
 }
Example #3
0
 /**
  * ログインしているユーザーのセッションキーを取得
  */
 public function testGetLoginUserSessionKey()
 {
     // セッションキーを未設定の場合
     $result = BcUtil::getLoginUserSessionKey();
     $this->assertEquals('User', $result, 'セッションキーを取得を正しく取得できません');
     // セッションキーを設定した場合
     BcAuthComponent::$sessionKey = 'Auth.Hoge';
     $result = BcUtil::getLoginUserSessionKey();
     $this->assertEquals($result, 'Hoge', 'セッションキーを取得を正しく取得できません');
 }