C
C
cat_crash2014-08-29 10:57:52
Yii
cat_crash, 2014-08-29 10:57:52

Yii how to make different authorizations in different modules?

There is a site on Yii. It assumes 2 sources of authorization
- On the site itself, authorization through social networks using the EAuth module ( habrahabr.ru/post/129804/)
- There is a control panel for "suppliers". Made in the form of a module. Normal authorization from base of local users is planned there. I screwed www.yiiframework.com/extension/yii-user In
the porstors I found about setStateKeyPrefix but in fact it does not help.
in the suppliers module

class CpModule extends CWebModule
{
 public function init()
        {

                        $this->setComponents(array(
                'errorHandler' => array(
                        'errorAction' => 'site/error'),
                'user' => array(
                        'class' => 'CWebUser',
                        'allowAutoLogin'=>true,
                         'stateKeyPrefix' => '_cp',
                        'loginUrl' => Yii::app()->createUrl('user/login'),
                )
            ));

                // this method is called when the module is being created
                // you may place code here to customize the module or the application

                // import the module-level models and components
                $this->setImport(array(
                        'cp.models.*',
                        'cp.components.*',
                        'application.modules.user.models.*',
                        'application.modules.user.components.*',
                ));
        }

in EAuth code
protected function getStateKeyPrefix() {
                return '__eauth_' . $this->getServiceName() . '__';
        }

   protected function hasState($key) {
                $session = Yii::app()->session;
                $key = $this->getStateKeyPrefix() . $key;
                return isset($session[$key]);

        }

Authorization takes place in both modules, and if you are authorized on the site, then automatically in the module, respectively, if in the module, then the site perceives it as successfully authorized.
How to make it so that the authorization in the module is only for the module. On the site - for the site only

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Timur, 2014-09-04
@XAKEPEHOK

There was a similar situation. Too many problems from simultaneous authorizations within the same application instance. Try splitting applications into parts according to www.yiiframework.com/wiki/63 so that one part of the application will not depend on the other, and you can configure everything without problems

D
DjSebas, 2014-09-04
@DjSebas

First, try passing false as the second parameter to setComponents. This will force the module to replace the component, not to merge.
If this does not help, as an option, you can register 2 WebUser components under different names. Accordingly, depending on the context, use the desired component.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question