0
저는 매우 큰 프로젝트에서 Cakephp 2.3을 작업 중이며 전세계에서 내 사이트를 시작하려고합니다.보안 및 코드 관리 목적으로이 작업을 수행하는 더 나은 방법
내 응용 프로그램에 로그인 시스템이 있습니다. 나는 내 코드를 공유하고있다. 왜냐하면 내가 옳은 것인지 아닌지를 확인하고 싶다. 또한 누락 된 기능이나 코드를 무언가를 추가하거나 무언가를 제거하는 충고에 크게 감사 할 것이기 때문이다. 또한
나에게 더 빠른 쿼리를 작성하거나
class UsersController extends AppController
{
public $components = array('Cookie');
public function beforeFilter()
{
parent::beforeFilter();
App::uses('Utility', 'Utility');
$this->Auth->allow('index');
$this->Security->requireSecure('login'); // for security
$this->Auth->authenticate = array(
'Authenticate.Cookie' => array(
'fields' => array(
'username' => 'email',
'password' => 'password'
),
'userModel' => 'User',
'scope' => array(
'User.active' => 1
)
),
'Authenticate.MultiColumn' => array(
'fields' => array(
'username' => 'email',
'password' => 'password'
),
'columns' => array(
'email',
'mobileNo'
),
'userModel' => 'User'
)
);
}
public function index()
{
$this->layout = 'logindefault';
if (!$this->Auth->login() || !$this->Auth->loggedIn()) {
$this->redirect(array(
'controller' => 'users',
'action' => 'login'
));
} else {
$this->redirect(array(
'controller' => 'users',
'action' => 'dashboard'
));
}
}
public function login()
{
$this->layout = 'logindefault';
$this->set('title_for_layout', 'Account Login');
if ($this->Auth->login() || $this->Auth->loggedIn()) {
$lastLogin = $this->Auth->User('lastLogin');
if ($lastLogin != null) {
$this->redirect($this->Auth->redirect());
} else {
$this->redirect(array(
'controller' => 'Userinfo',
'action' => 'gettingstarted'
));
}
} else {
if ($this->request->is('post')) {
$mobileNo = $this->request->data['User']['email'];
$mobileNo = Utility::addPlusToMobileNo($mobileNo);
$this->request->data['User']['email'] = $mobileNo;
if ($this->Auth->login() || $this->Auth->loggedIn()) {
if ($this->Session->check('Auth.User')) {
$this->_setCookie($this->Auth->user('idUser'));
$lastLogin = $this->Auth->User('lastLogin');
if ($lastLogin != null) {
$this->redirect(array(
'controller' => 'users',
'action' => 'dashboard'
));
} else {
$this->redirect(array(
'controller' => 'Userinfo',
'action' => 'gettingstarted'
));
}
}
} else {
$this->Session->setFlash('Incorrect Email/Password Combination');
}
}
}
}
protected function _setCookie($id)
{
if (!$this->request->data('User.remember_me')) {
return false;
}
$data = array(
'username' => $this->request->data('User.email'),
'password' => $this->request->data('User.password')
);
$this->Cookie->write('User', $data, true, '1 week');
return true;
}
public function logout()
{
$this->Cookie->delete('User');
$this->redirect($this->Auth->logout());
}
@thankyou burzum .... 내가 말하면 당신에게 AppController를 게시 할 수 있습니다 ... 네 번째 지점을 얻지 못한 두 번째 .. 나는 메서드 호출에 대해 잘 모릅니다. 들어 본 적이 없으며 ... 단위 테스트에 관한 6 번째 요점 ... 그것이 무엇을 의미하는지 .. 당신이 나에게 모범을 줄 수 있는지 그리고 마지막으로 당신은 내가 케이크의 코딩 표준을 따르지 않는다고 말하고 있습니다 .. 어떻게? – mynameisjohn
그리고 또한 파일 위에 앱을 넣어 두는 것이 좋습니다. 클래스 선언 후 클래스 UsersController extends AppController {App :: uses ('Utility', 'Utility'); 하지만 여기에 오류 – mynameisjohn
을 제공하고 내가 디버그 키트를 다운로드하는 중입니다 ... 그래서 내가 디버그 키트를 삭제해야할까요? – mynameisjohn