2014-02-22 7 views
0

내 웹 프로젝트에 Yii PHP 프레임 워크를 사용하고 있습니다. 내 질문은이 문제를 해결하는 방법이다. 부서 페이지 방문시 오류 403이 발생했습니다.Yii - 오류 403이 작업을 수행 할 권한이 없습니다.

내 LoginForm.php

public function authenticate($attribute,$params) 
    { 
     if(!$this->hasErrors()) // we only want to authenticate when no input errors 
     { 
      $identity=new UserIdentity($this->email,$this->password); 
      $identity->authenticate(); 
      switch($identity->errorCode) 
      { 
       case UserIdentity::ERROR_NONE: 
        Yii::app()->user->login($identity); 
        break; 
       case UserIdentity::ERROR_USERNAME_INVALID: 
        $this->addError('email','Email address is incorrect.'); 
        break; 
       default: // UserIdentity::ERROR_PASSWORD_INVALID 
        $this->addError('password','Password is incorrect.'); 
        break; 
      } 
     } 
    } 

UserIdentity.php

<?php 

/** 
* UserIdentity represents the data needed to identity a user. 
* It contains the authentication method that checks if the provided 
* data can identity the user. 
*/ 
class UserIdentity extends CUserIdentity 
{ 

    // Need to store the user's ID: 
    private $_merchantId; 


    /** 
    * Authenticates a user. 
    * The example implementation makes sure if the username and password 
    * are both 'demo'. 
    * In practical applications, this should be changed to authenticate 
    * against some persistent user identity storage (e.g. database). 
    * @return boolean whether authentication succeeds. 
    */ 
    public function authenticate() 
    { 
     $merchant= Merchant::model()->findByAttributes(array('email'=>$this->username)); 

     if ($merchant===null) { // No user found! 
      $this->errorCode=self::ERROR_USERNAME_INVALID; 
     } else if ($merchant->password!== SHA1($this->password)) { // Invalid password! 
      $this->errorCode=self::ERROR_PASSWORD_INVALID; 
     } else { // Okay! 
      $this->errorCode=self::ERROR_NONE; 
      // Store the role in a session: 
      $this->setState('role', $merchant->role); 
      $this->_merchantId= $merchant->merchantId; 
     } 
     return!$this->errorCode; 
    } 

    public function getId() 
    { 
    return $this->_merchantId; 
    } 


} 

Department.php

public function accessRules() 
    { 
     return array(
      array('allow', // allow all users to perform 'index' and 'view' actions 
       'actions'=>array('index','view'), 
       'users'=>array('*'), 
      ), 
      array('allow', // allow authenticated user to perform 'create' and 'update' actions 
       'actions'=>array('create','update'), 
       'users'=>array('@'), 
      ), 
      array('allow', // allow admin user to perform 'admin' and 'delete' actions 
       'actions'=>array('admin','delete'), 
       'users'=>array('admin'), 
      ), 
      array('deny', // deny all users 
       'users'=>array('*'), 
      ), 
     ); 
    } 

이유는 무엇입니까?

+0

이 오류가 발생하기 위해 액세스하는 URL은 무엇입니까? –

+0

r = department/admin –

+0

사용자 역할이 무엇입니까? 'admin' 역할 만'admin' 기능에 접근 할 수 있습니다. –

답변

0

을 말했듯이 확인 다음 줄에 'users'=>array('admin')'users'=>array('@')에 변경해야합니다.

1

관리자가 정의한 액세스 규칙에 따라 액세스 할 수 있습니다.

array('allow', // allow admin user to perform 'admin' and 'delete' actions 
    'actions'=>array('admin','delete'), 
    'users'=>array('@'), 
), 

가 승인되지 않은 오류를 수정해야합니다 아래 볼 수 있듯이 그래서() @kumar_v이 department.php의 accessRules에서

관련 문제