Commit 84d833e0 authored by difox's avatar difox

Authorization module

parent 55912306
......@@ -79,7 +79,7 @@ class AuthItem extends \common\components\ActiveRecordModel
}
public function getAssignment() {
return $this->hasOne(AuthAssignment::className(), ['name' => 'item_name']);
return $this->hasMany(AuthAssignment::className(), ['item_name' => 'name']);
}
public function relations()
......@@ -97,7 +97,6 @@ class AuthItem extends \common\components\ActiveRecordModel
'auth_items_childs(parent, child)',
'condition' => 'type = "' . self::TYPE_TASK . '"'
),
'assignments' => array(self::HAS_MANY, 'AuthAssignment', 'itemname'),
'users' => array(self::HAS_MANY, 'User', 'userid', 'through' => 'assignments')
);
}
......@@ -188,7 +187,8 @@ class AuthItem extends \common\components\ActiveRecordModel
if(!$roles)
{
$roles = $this->findAllByAttributes(array(
'type' => self::TYPE_ROLE
//'type' => self::TYPE_ROLE
'rule_name' => 'group'
));
}
return $roles;
......
......@@ -355,8 +355,8 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
public function relations()
{
return array(
'assignment' => array(self::HAS_ONE, 'AuthAssignment', 'userid'),
'city' => array(self::BELONGS_TO, 'City', 'city_id')
'assignment' => array(self::HAS_ONE, 'AuthAssignment', 'user_id'),
'city' => array(self::BELONGS_TO, 'City', 'city_id')
);
}
......@@ -394,18 +394,23 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
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();
if (!$assigment)
return $auth->name;
/*$assigment = AuthAssignment::find(['userid' => $this->id])->one();
if (!$assigment)
{
$assigment = new AuthAssignment();
$assigment = new AuthAssignment();
$assigment->item_name = AuthItem::ROLE_DEFAULT;
$assigment->user_id = $this->id;
$assigment->save(false);
}
return $assigment->role;*/
return 'admin';
return $assigment->role;
return 'admin';*/
}
public function getRoleName()
......
......@@ -81,7 +81,7 @@ return [
//'css_linebreak_pos' => false,
],
'user' => [
'identityClass' => 'common\modules\scoring\models\ScClient',
'identityClass' => 'common\modules\users\models\User',
'loginUrl' => ['/site/login'],
'enableAutoLogin' => true,
],
......@@ -165,6 +165,7 @@ return [
'school' => 'school/course/index',
'school/course/<id>' => 'school/course/view',
'school/lesson/<id>' => 'school/lesson/view',
'login' => 'site/login',
'<page:(/)>' => 'content/page/view',
'<_m>/<_c>/<_a>/<id:\d+>' => '<_m>/<_c>/<_a>',
......@@ -178,10 +179,10 @@ return [
],
'authManager' => [
'class' => 'yii\rbac\DbManager',
/*'connectionID' => 'db',
'connectionID' => 'db',
'itemTable' => 'auth_items',
'assignmentTable' => 'auth_assignments',
'itemChildTable' => 'auth_item_child',*/
'itemChildTable' => 'auth_item_child',
'defaultRoles' => [
'user',
'moderator',
......
......@@ -3,7 +3,7 @@ namespace frontend\controllers;
use common\modules\scoring\models\ScRequest;
use Yii;
use frontend\models\LoginForm;
//use frontend\models\LoginForm;
use frontend\models\PasswordResetRequestForm;
use frontend\models\ResetPasswordForm;
use frontend\models\SignupForm;
......@@ -22,6 +22,7 @@ use common\modules\request\models\ScZodiac;
use \yii\web\Response;
use \yii\widgets\ActiveForm;
use common\modules\scoring\models\ScClient;
use common\models\LoginForm;
/**
* Site controller
......@@ -115,6 +116,14 @@ class SiteController extends BaseController
}
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';
$model = new \frontend\models\LoginForm();
......@@ -178,7 +187,7 @@ class SiteController extends BaseController
'model' => $model,
]);
}
}
}*/
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