2017-03-23 1 views
-3

사용자가 mgrUser 테이블에 있는지 확인해야합니다. 이제 모델은 mgrUserModel에있는 동안 컨트롤러는 adminController에 있습니다. 어떻게 인증을 사용합니까? 일반적인 로그인 코드를 만든 이유가 그 때문입니다.php cake 내부 인증 클래스

public function login() { 
     // if ($this->Auth->login()) { 
     //  return $this->redirect($this->Auth->redirectUrl()); 
     // } 
     // $this->Flash->error(
     //  __('Username ou password incorrect') 
     //); 


     //since the model is in a different view, I needed to includ the mgrModel and create a generic login 
     //will revamp the code to fit the built in Aut code for php cake 
     if(isset($_POST['submit'])) { 
      $User_ID = htmlspecialchars($_POST['user_id']); 
      $Pass = htmlspecialchars($_POST['pass']); 

      try { 
        $mgrUserModel = new MgrUser(); 
        $isValid = $mgrUserModel->find('first', array(
         'conditions' => array("user_id" => $User_ID) 
        )); 
        if($isValid != null){ 
         if (($isValid['MgrUser']['pass']) == $Pass) { 
//this doesnot work 
$this->Auth->allow(); 
          $this->redirect($this->Auth->redirectUrl()); 
         } 
         else{ 

         } 
        } 

       } catch (Exception $e) { 
        //echo "not logged in"; 
       } 
      // this echo will show the id and pass that was taken based on the user_id and pass that the user will input 
      //for testing only 
      // echo $isValid2['MgrUser']['id']; 
      // echo $isValid2['MgrUser']['pass']; 
     } 

    } 

답변

0

당신은, 일을 비교하는 이중 == 필요 당신은 항상 할당이 가능했기 때문에 true 어쨌든

당신이 beforeFilter에서 사용한다 반환 변수 $user에 할당 "me" 문자열이었다 무슨 짓을했는지

function checkMe() 
{ 
    if($user == 'me'){ 
     $this->Auth->allow('detail'); 
    } 
} 

이 컨트롤러에서 모든 작업을 수행하기 전에 실행되고있는 것이 훨씬 더 의미가 있습니다.

public function beforeFilter() { 
    parent::beforeFilter(); 
    if($user == 'me'){ 
     $this->Auth->allow('detail'); 
    } 
} 
+0

하나는, 진짜 문제는 $ this- 단지 샘플입니다했다> Auth-> 수 ('세부 사항');

적절한 CakePHP의 버전에 대한 책을 참조하시기 바랍니다 조건이 충족 되더라도 조건이 만족스럽지 않습니다 (다른 코드에서) –

+0

@ReyNorbertBesmonte ok 내 편집을 확인하십시오 – Sojtin

+0

이미 시도했습니다. 단추를 클릭 할 때만 명령이 실행됩니다. 그래서 그것은 verify() {//} –