コード例 #1
0
ファイル: UsrAuthFactory.php プロジェクト: nafigator/Veles
 /**
  * Algorithm for choosing auth strategy
  *
  * @todo Move validation and error handling into separate class
  * @return AbstractAuthStrategy
  */
 public function create()
 {
     $post = $this->getPost();
     $cookies = $this->getCookies();
     $auth = null;
     switch (true) {
         case isset($post['ln'], $post['pw']):
             $auth = new LoginFormStrategy($post['ln'], $post['pw'], new User());
             $post['ln'] || $auth->setError($auth::ERR_NOT_VALID_LOGIN);
             $post['pw'] || $auth->setError($auth::ERR_NOT_VALID_PASSWORD);
             break;
         case isset($cookies['id'], $cookies['pw']):
             $auth = new CookieStrategy($cookies['id'], $cookies['pw'], new User());
             $cookies['id'] || $auth->setError($auth::ERR_NOT_VALID_UID);
             $cookies['pw'] || $auth->setError($auth::ERR_NOT_VALID_HASH);
             break;
         default:
             $auth = new GuestStrategy(new User());
     }
     return $auth;
 }