2013-07-09 1 views
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()); 
} 

답변

0
  • 은 '당신처럼 보이는이 blabla에서 원치 않는 제거하는 방법을 예를 들어 .. 내 웹 사이트 빠르게 만드는 몇 가지 팁을 알려 DO ... 너무 보안 측면에서 언급 앱을 보안하려는 경우 이미 SecurityComponent을 사용하여 어디서나 사용할 수 있습니다. AJAX 양식에 필요한 필드 만 흰색 목록으로 표시합니다. 구성 요소를 비활성화하지 마십시오!
  • App 넣기 :: 용도 ('Utility', 'Utility'); 파일 상단에
  • $ mobileNo = 유틸리티 :: addPlusToMobileNo ($ mobileNo); beforeSave() 모델에서 발생합니다.
  • 이것이 전 세계에서 사용되기로되어 있다면 번역을 원한다고 가정합니다. 번역 메서드 호출이 __()입니다. setFlash ('Incorrect Email/Password Combination');
  • 대부분의 코드는 모델 레이어로 들어갈 수 있고 있어야합니다.
  • 단위 테스트가 있습니까? 단위 테스트를 추가하지 않으면 특별히 데이터 유효성 검사 및 잘못된 데이터 입력을 테스트합니다. 단위 테스트를 위해 ~ 85 % + 코드 커버리지가 필요합니다.
  • 당신은 CakePHP의 코딩 표준

을 전체 응용 프로그램 코드에 액세스 할 수있는 및 코드 검토를하지 않고이 당신보다 더 알 수있는 방법은 없습니다 다음 아니에요 (I는 할 수있다). 쿼리의 경우 항상 필요한 데이터를 쿼리하고 생성 된 SQL 쿼리를 확인하고 DebugKit을 사용하여 쿼리 시간을 확인하여 느린 쿼리를 찾고 천천히 페이지를 렌더링합니다.

+0

@thankyou burzum .... 내가 말하면 당신에게 AppController를 게시 할 수 있습니다 ... 네 번째 지점을 얻지 못한 두 번째 .. 나는 메서드 호출에 대해 잘 모릅니다. 들어 본 적이 없으며 ... 단위 테스트에 관한 6 번째 요점 ... 그것이 무엇을 의미하는지 .. 당신이 나에게 모범을 줄 수 있는지 그리고 마지막으로 당신은 내가 케이크의 코딩 표준을 따르지 않는다고 말하고 있습니다 .. 어떻게? – mynameisjohn

+0

그리고 또한 파일 위에 앱을 넣어 두는 것이 좋습니다. 클래스 선언 후 클래스 UsersController extends AppController {App :: uses ('Utility', 'Utility'); 하지만 여기에 오류 – mynameisjohn

+0

을 제공하고 내가 디버그 키트를 다운로드하는 중입니다 ... 그래서 내가 디버그 키트를 삭제해야할까요? – mynameisjohn

관련 문제