Commit 84d833e0 authored by difox's avatar difox

Authorization module

parent 55912306
...@@ -79,7 +79,7 @@ class AuthItem extends \common\components\ActiveRecordModel ...@@ -79,7 +79,7 @@ class AuthItem extends \common\components\ActiveRecordModel
} }
public function getAssignment() { public function getAssignment() {
return $this->hasOne(AuthAssignment::className(), ['name' => 'item_name']); return $this->hasMany(AuthAssignment::className(), ['item_name' => 'name']);
} }
public function relations() public function relations()
...@@ -97,7 +97,6 @@ class AuthItem extends \common\components\ActiveRecordModel ...@@ -97,7 +97,6 @@ class AuthItem extends \common\components\ActiveRecordModel
'auth_items_childs(parent, child)', 'auth_items_childs(parent, child)',
'condition' => 'type = "' . self::TYPE_TASK . '"' 'condition' => 'type = "' . self::TYPE_TASK . '"'
), ),
'assignments' => array(self::HAS_MANY, 'AuthAssignment', 'itemname'),
'users' => array(self::HAS_MANY, 'User', 'userid', 'through' => 'assignments') 'users' => array(self::HAS_MANY, 'User', 'userid', 'through' => 'assignments')
); );
} }
...@@ -188,7 +187,8 @@ class AuthItem extends \common\components\ActiveRecordModel ...@@ -188,7 +187,8 @@ class AuthItem extends \common\components\ActiveRecordModel
if(!$roles) if(!$roles)
{ {
$roles = $this->findAllByAttributes(array( $roles = $this->findAllByAttributes(array(
'type' => self::TYPE_ROLE //'type' => self::TYPE_ROLE
'rule_name' => 'group'
)); ));
} }
return $roles; return $roles;
......
...@@ -355,7 +355,7 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter ...@@ -355,7 +355,7 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
public function relations() public function relations()
{ {
return array( return array(
'assignment' => array(self::HAS_ONE, 'AuthAssignment', 'userid'), 'assignment' => array(self::HAS_ONE, 'AuthAssignment', 'user_id'),
'city' => array(self::BELONGS_TO, 'City', 'city_id') 'city' => array(self::BELONGS_TO, 'City', 'city_id')
); );
} }
...@@ -394,8 +394,13 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter ...@@ -394,8 +394,13 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
public function getRole() public function getRole()
{ {
/*$assigment = AuthAssignment::find(['userid' => $this->id])->one(); $auth = AuthItem::find()->joinWith('assignment', true)
->andWhere(['rule_name' => 'group'])
->andWhere(['auth_assignment.user_id' => $this->id])
->one();
return $auth->name;
/*$assigment = AuthAssignment::find(['userid' => $this->id])->one();
if (!$assigment) if (!$assigment)
{ {
$assigment = new AuthAssignment(); $assigment = new AuthAssignment();
...@@ -404,8 +409,8 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter ...@@ -404,8 +409,8 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
$assigment->save(false); $assigment->save(false);
} }
return $assigment->role;*/ return $assigment->role;
return 'admin'; return 'admin';*/
} }
public function getRoleName() public function getRoleName()
......
...@@ -81,7 +81,7 @@ return [ ...@@ -81,7 +81,7 @@ return [
//'css_linebreak_pos' => false, //'css_linebreak_pos' => false,
], ],
'user' => [ 'user' => [
'identityClass' => 'common\modules\scoring\models\ScClient', 'identityClass' => 'common\modules\users\models\User',
'loginUrl' => ['/site/login'], 'loginUrl' => ['/site/login'],
'enableAutoLogin' => true, 'enableAutoLogin' => true,
], ],
...@@ -165,6 +165,7 @@ return [ ...@@ -165,6 +165,7 @@ return [
'school' => 'school/course/index', 'school' => 'school/course/index',
'school/course/<id>' => 'school/course/view', 'school/course/<id>' => 'school/course/view',
'school/lesson/<id>' => 'school/lesson/view', 'school/lesson/<id>' => 'school/lesson/view',
'login' => 'site/login',
'<page:(/)>' => 'content/page/view', '<page:(/)>' => 'content/page/view',
'<_m>/<_c>/<_a>/<id:\d+>' => '<_m>/<_c>/<_a>', '<_m>/<_c>/<_a>/<id:\d+>' => '<_m>/<_c>/<_a>',
...@@ -178,10 +179,10 @@ return [ ...@@ -178,10 +179,10 @@ return [
], ],
'authManager' => [ 'authManager' => [
'class' => 'yii\rbac\DbManager', 'class' => 'yii\rbac\DbManager',
/*'connectionID' => 'db', 'connectionID' => 'db',
'itemTable' => 'auth_items', 'itemTable' => 'auth_items',
'assignmentTable' => 'auth_assignments', 'assignmentTable' => 'auth_assignments',
'itemChildTable' => 'auth_item_child',*/ 'itemChildTable' => 'auth_item_child',
'defaultRoles' => [ 'defaultRoles' => [
'user', 'user',
'moderator', 'moderator',
......
...@@ -3,7 +3,7 @@ namespace frontend\controllers; ...@@ -3,7 +3,7 @@ namespace frontend\controllers;
use common\modules\scoring\models\ScRequest; use common\modules\scoring\models\ScRequest;
use Yii; use Yii;
use frontend\models\LoginForm; //use frontend\models\LoginForm;
use frontend\models\PasswordResetRequestForm; use frontend\models\PasswordResetRequestForm;
use frontend\models\ResetPasswordForm; use frontend\models\ResetPasswordForm;
use frontend\models\SignupForm; use frontend\models\SignupForm;
...@@ -22,6 +22,7 @@ use common\modules\request\models\ScZodiac; ...@@ -22,6 +22,7 @@ use common\modules\request\models\ScZodiac;
use \yii\web\Response; use \yii\web\Response;
use \yii\widgets\ActiveForm; use \yii\widgets\ActiveForm;
use common\modules\scoring\models\ScClient; use common\modules\scoring\models\ScClient;
use common\models\LoginForm;
/** /**
* Site controller * Site controller
...@@ -115,6 +116,14 @@ class SiteController extends BaseController ...@@ -115,6 +116,14 @@ class SiteController extends BaseController
} }
public function actionLogin() public function actionLogin()
{
//Yii::$app->user->getIdentity()->getRole()
$model = new LoginForm();
$model->load(Yii::$app->request->post());
$model->login();
}
/*public function actionLogin()
{ {
$this->layout = '//main-short'; $this->layout = '//main-short';
$model = new \frontend\models\LoginForm(); $model = new \frontend\models\LoginForm();
...@@ -178,7 +187,7 @@ class SiteController extends BaseController ...@@ -178,7 +187,7 @@ class SiteController extends BaseController
'model' => $model, 'model' => $model,
]); ]);
} }
} }*/
public function actionLogout() public function actionLogout()
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment