Way to redirect login page if user not login -


i want redirect user login page if not logged on page. have actionlogin in

registrationcontroller

so when use in common/main :

'as beforerequest' => [  //if guest user access site so, redirect login page.     'class' => 'yii\filters\accesscontrol',     'rules' => [         [             'actions' => ['login', 'error'],             'allow' => true,         ],         [             'allow' => true,             'roles' => ['@'],         ],     ], ], 

it alway redirect me

index.php?r=site%2flogin

it possible change main login redirect

index.php?r=registration%2flogin

if possible should overwrite code or change something.. !edit! ok,

'user' => [ 'loginurl' => ['registration/login'], ],

resolve problem when want go registration/index signup user redirect me registration/login. possible ruled out url enforced. want make:

index.php?r=registration

the available path

and here facebook login want enable too

public function oauthsuccess($client) {         // user data client         $userattributes = $client->getuserattributes();          $user = user::find()->where(['email' => $userattributes['email']])->one();          if (!$user) {             $newuser = new signupform();             $newuser->oauthsuccess($client);             $user = user::find()->where(['email' => $userattributes['email']])->one();             if ($newuser->validate() && yii::$app->getuser()->login($user)) {                 yii::$app->session->setflash('success', yii::t('app', 'udało się poprawnie zalogować. prosimy dokonać zmian w ustawianiach profilu.'));                 return $this->redirect('index.php?r=content/news');                 }         }          yii::$app->user->login($user);     } 

in app/config/web.php (for basic template) or app/frontend/config/main.php (for advance template) - reference

return [     // ...     'components' => [                     // ...         'user' => [             'identityclass' => 'common\models\useridentity',             'enableautologin' => true,             'loginurl'=>['registration/login']         ],          // ... 

and in controller eg registrationcontroller.php

// ... class registrationcontroller extends controller {         public function behaviors()     {         return [             'access' => [                 'class' => accesscontrol::classname(),                                 'rules' => [                     [                         'actions' => ['login', 'signup'], // action guest (?) user can access                         'allow' => true,                         'roles' => ['?'],                                             ],                     [                         'actions' => ['home', 'update'],  // action authorized (@) user can access                         'allow' => true,                         'roles' => ['@'],                     ],                 ],             ],             'verbs' => [                 'class' => verbfilter::classname(),                 'actions' => [                     'logout' => ['post'],                 ],             ],         ];     }      // ... 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -