Yii Framework Forum: Redirect Ke Login - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Redirect Ke Login Rate Topic: -----

#1 User is offline   Fachrizal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 30-November 11

Posted 29 January 2012 - 11:58 PM

mau tanya dong para2 master yii ...

ane pingin redirect suatu aplikasi ke halaman login apabila dia belum teridentifikasi n terotentifikasi ,, gmana ya gan caranya ?? otorisasi yang ane bikin tu pake teknik session ...

ni source codenya gan di user identity

public function authenticate()
	{
		$users=array(
			// username => password
			
			'admin'=>'superb1234',
                        
		);
			if ($this->password == 'superb1234'){
				$this->errorCode=self::ERROR_NONE;
                                $this->setState('nikuser', 'admin');                                
                                $session = Yii::app()->session;
                                $session['adminsuper'] = TRUE;
				return !$this->errorCode;	
			}
                        if(!isset($users[$this->username]))
				$this->errorCode=self::ERROR_USERNAME_INVALID;
			else if($users[$this->username]!==$this->password)
				$this->errorCode=self::ERROR_PASSWORD_INVALID;
			else
				$this->errorCode=self::ERROR_NONE;
		
		}

		return !$this->errorCode;
        }


}


terus di salah satu controler ane buat access roles nya seperti ini :

    public function accessRules() {
        $iduser = Yii::app()->user->nikuser;
        $session = Yii::app()->session;

        if ($session['superadmin'] == TRUE) {
            $admin = array($iduser);
        } else {
            $admin = array('01010101');
        } 
        if ($session['hrbenefit'] == TRUE) {
            $hrbenefit = array($iduser);
        } else {
            $hrbenefit = array('01010101');
        }


        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' => $admin,
            ),
            array('allow', // allow authenticated user to perform 'create' and 'update' actions
                'actions' => array('create', 'update','admin'),
                'users' => $hrbenefit,
            ),
            array('allow', // allow admin user to perform 'admin' and 'delete' actions
                'actions' => array('admin', 'delete'),
                'users' => $admin,
            ),
            array('deny', // deny all users
                'users' => array('*'),
            ),
        );
    }




ane pingin ketika ada user yang iseng langsung memasukkan url misalnya :
http://localhost/apl...ggaranhr/create

maka bukan pesen : cwebuser.nikuser is not define yang keluar gan ,,,
tp langsung di redirect ke menu login ...

mohon bantuaanya gan ...

thx banget
0

#2 User is offline   Ade Fyrman 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 27-September 11

Posted 03 February 2012 - 10:48 PM

Coba pake ini gan..

Yii::app()->user->loginRequired();

0

#3 User is offline   afs07 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 13-November 12

Posted 30 November 2012 - 05:23 AM

View PostAde Fyrman, on 03 February 2012 - 10:48 PM, said:

Coba pake ini gan..

Yii::app()->user->loginRequired();



dieditnya dimananya ya gan..ane lg cb hal yg sama nih..thanks sebelumnya
0

#4 User is offline   J.J 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 126
  • Joined: 01-April 11

Posted 01 December 2012 - 04:27 AM

Tambahin di config/main.php aja gan, itu langsung redirect ke halaman login.

'defaultController' => 'site/login',

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users