사용자가 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'];
}
}
하나는, 진짜 문제는 $ this- 단지 샘플입니다했다> Auth-> 수 ('세부 사항');
적절한 CakePHP의 버전에 대한 책을 참조하시기 바랍니다 조건이 충족 되더라도 조건이 만족스럽지 않습니다 (다른 코드에서) –
@ReyNorbertBesmonte ok 내 편집을 확인하십시오 – Sojtin
이미 시도했습니다. 단추를 클릭 할 때만 명령이 실행됩니다. 그래서 그것은 verify() {//} –