]> gitweb.erp-flowers.ru Git - yii-erp24/.git/commitdiff
add admin/auth-by-hash
authorAlexander Smirnov <fredeom@mail.ru>
Sat, 27 Apr 2024 14:04:37 +0000 (17:04 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Sat, 27 Apr 2024 14:04:37 +0000 (17:04 +0300)
erp24/api3/modules/v1/controllers/AdminController.php
erp24/records/AuthAssignment.php [new file with mode: 0644]
erp24/records/AuthItem.php [new file with mode: 0644]
erp24/records/AuthItemChild.php [new file with mode: 0644]
erp24/records/AuthRule.php [new file with mode: 0644]

index cbd00a7e4bb3f9734a7d12ebed8494d28ade04f4..40a8dce059e0c6bb84b8f463888ae4e980292781 100644 (file)
@@ -2,10 +2,16 @@
 
 namespace yii_app\api3\modules\v1\controllers;
 
+use Yii;
+use yii\db\Expression;
 use yii\db\Query;
 use yii\helpers\ArrayHelper;
+use yii\helpers\Json;
+use yii\web\NotFoundHttpException;
+use yii\web\UnauthorizedHttpException;
 use yii_app\api3\modules\v1\models\Admin;
 use yii_app\records\AdminGroup;
+use yii_app\records\AuthAssignment;
 
 class AdminController extends \yii_app\api3\controllers\ActiveController
 {
@@ -47,4 +53,51 @@ class AdminController extends \yii_app\api3\controllers\ActiveController
         }
         return $results;
     }
+
+    public function actionAuthByHash() {
+        $hash = Yii::$app->request->bodyParams["hash"] ?? null;
+        if (!$hash) {
+            throw new UnauthorizedHttpException("hash не найден");
+        }
+
+        $admin = Admin::find()
+            ->where(['group_id' => 27])
+            ->andWhere(['or',
+                ['MD5(CONCAT(id, \':\', pass_user))' => $hash],
+                ['MD5(CONCAT(login_user, \':\', pass_user))' => $hash]
+            ])
+            ->one();
+
+        if ($admin !== null) {
+            $admin->group_name = "Курьер";
+            $admin->id = "-" . $admin->id;
+        } else {
+            $admin = Admin::find()
+                ->where(['>', 'group_id', 0])
+                ->andWhere(['or',
+                    ['MD5(CONCAT(id, \':\', pass_user))' => $hash],
+                    ['MD5(CONCAT(login_user, \':\', pass_user))' => $hash]
+                ])
+                ->one();
+        }
+
+        if ($admin === null) {
+            throw new NotFoundHttpException("Нет такого сотрудника");
+        }
+
+        $permissions = AuthAssignment::find()
+            ->select('item_name')
+            ->where(['user_id' => $admin->id])
+            ->all();
+
+        $response = [
+            'group_id' => $admin->group_id,
+            'name' => $admin->name,
+            'group_name' => $admin->group_name,
+            'id' => $admin->id,
+            'permissions' => $permissions
+        ];
+
+        return $response;
+    }
 }
\ No newline at end of file
diff --git a/erp24/records/AuthAssignment.php b/erp24/records/AuthAssignment.php
new file mode 100644 (file)
index 0000000..95702af
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "auth_assignment".
+ *
+ * @property string $item_name
+ * @property string $user_id
+ * @property int|null $created_at
+ *
+ * @property AuthItem $itemName
+ */
+class AuthAssignment extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'auth_assignment';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['item_name', 'user_id'], 'required'],
+            [['created_at'], 'default', 'value' => null],
+            [['created_at'], 'integer'],
+            [['item_name', 'user_id'], 'string', 'max' => 64],
+            [['item_name', 'user_id'], 'unique', 'targetAttribute' => ['item_name', 'user_id']],
+            [['item_name'], 'exist', 'skipOnError' => true, 'targetClass' => AuthItem::class, 'targetAttribute' => ['item_name' => 'name']],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'item_name' => 'Item Name',
+            'user_id' => 'User ID',
+            'created_at' => 'Created At',
+        ];
+    }
+
+    /**
+     * Gets query for [[ItemName]].
+     *
+     * @return \yii\db\ActiveQuery
+     */
+    public function getItemName()
+    {
+        return $this->hasOne(AuthItem::class, ['name' => 'item_name']);
+    }
+}
diff --git a/erp24/records/AuthItem.php b/erp24/records/AuthItem.php
new file mode 100644 (file)
index 0000000..b4f7547
--- /dev/null
@@ -0,0 +1,126 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "auth_item".
+ *
+ * @property string $name
+ * @property int $type
+ * @property string|null $description
+ * @property string|null $rule_name
+ * @property resource|null $data
+ * @property int|null $created_at
+ * @property int|null $updated_at
+ *
+ * @property AuthAssignment[] $authAssignments
+ * @property AuthItemChild[] $authItemChildren
+ * @property AuthItemChild[] $authItemChildren0
+ * @property AuthItem[] $children
+ * @property AuthItem[] $parents
+ * @property AuthRule $ruleName
+ */
+class AuthItem extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'auth_item';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['name', 'type'], 'required'],
+            [['type', 'created_at', 'updated_at'], 'default', 'value' => null],
+            [['type', 'created_at', 'updated_at'], 'integer'],
+            [['description', 'data'], 'string'],
+            [['name', 'rule_name'], 'string', 'max' => 64],
+            [['name'], 'unique'],
+            [['rule_name'], 'exist', 'skipOnError' => true, 'targetClass' => AuthRule::class, 'targetAttribute' => ['rule_name' => 'name']],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'name' => 'Name',
+            'type' => 'Type',
+            'description' => 'Description',
+            'rule_name' => 'Rule Name',
+            'data' => 'Data',
+            'created_at' => 'Created At',
+            'updated_at' => 'Updated At',
+        ];
+    }
+
+    /**
+     * Gets query for [[AuthAssignments]].
+     *
+     * @return \yii\db\ActiveQuery
+     */
+    public function getAuthAssignments()
+    {
+        return $this->hasMany(AuthAssignment::class, ['item_name' => 'name']);
+    }
+
+    /**
+     * Gets query for [[AuthItemChildren]].
+     *
+     * @return \yii\db\ActiveQuery
+     */
+    public function getAuthItemChildren()
+    {
+        return $this->hasMany(AuthItemChild::class, ['parent' => 'name']);
+    }
+
+    /**
+     * Gets query for [[AuthItemChildren0]].
+     *
+     * @return \yii\db\ActiveQuery
+     */
+    public function getAuthItemChildren0()
+    {
+        return $this->hasMany(AuthItemChild::class, ['child' => 'name']);
+    }
+
+    /**
+     * Gets query for [[Children]].
+     *
+     * @return \yii\db\ActiveQuery
+     */
+    public function getChildren()
+    {
+        return $this->hasMany(AuthItem::class, ['name' => 'child'])->viaTable('auth_item_child', ['parent' => 'name']);
+    }
+
+    /**
+     * Gets query for [[Parents]].
+     *
+     * @return \yii\db\ActiveQuery
+     */
+    public function getParents()
+    {
+        return $this->hasMany(AuthItem::class, ['name' => 'parent'])->viaTable('auth_item_child', ['child' => 'name']);
+    }
+
+    /**
+     * Gets query for [[RuleName]].
+     *
+     * @return \yii\db\ActiveQuery
+     */
+    public function getRuleName()
+    {
+        return $this->hasOne(AuthRule::class, ['name' => 'rule_name']);
+    }
+}
diff --git a/erp24/records/AuthItemChild.php b/erp24/records/AuthItemChild.php
new file mode 100644 (file)
index 0000000..bafb0dc
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "auth_item_child".
+ *
+ * @property string $parent
+ * @property string $child
+ *
+ * @property AuthItem $child0
+ * @property AuthItem $parent0
+ */
+class AuthItemChild extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'auth_item_child';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['parent', 'child'], 'required'],
+            [['parent', 'child'], 'string', 'max' => 64],
+            [['parent', 'child'], 'unique', 'targetAttribute' => ['parent', 'child']],
+            [['parent'], 'exist', 'skipOnError' => true, 'targetClass' => AuthItem::class, 'targetAttribute' => ['parent' => 'name']],
+            [['child'], 'exist', 'skipOnError' => true, 'targetClass' => AuthItem::class, 'targetAttribute' => ['child' => 'name']],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'parent' => 'Parent',
+            'child' => 'Child',
+        ];
+    }
+
+    /**
+     * Gets query for [[Child0]].
+     *
+     * @return \yii\db\ActiveQuery
+     */
+    public function getChild0()
+    {
+        return $this->hasOne(AuthItem::class, ['name' => 'child']);
+    }
+
+    /**
+     * Gets query for [[Parent0]].
+     *
+     * @return \yii\db\ActiveQuery
+     */
+    public function getParent0()
+    {
+        return $this->hasOne(AuthItem::class, ['name' => 'parent']);
+    }
+}
diff --git a/erp24/records/AuthRule.php b/erp24/records/AuthRule.php
new file mode 100644 (file)
index 0000000..f22d3f0
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "auth_rule".
+ *
+ * @property string $name
+ * @property resource|null $data
+ * @property int|null $created_at
+ * @property int|null $updated_at
+ *
+ * @property AuthItem[] $authItems
+ */
+class AuthRule extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'auth_rule';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['name'], 'required'],
+            [['data'], 'string'],
+            [['created_at', 'updated_at'], 'default', 'value' => null],
+            [['created_at', 'updated_at'], 'integer'],
+            [['name'], 'string', 'max' => 64],
+            [['name'], 'unique'],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'name' => 'Name',
+            'data' => 'Data',
+            'created_at' => 'Created At',
+            'updated_at' => 'Updated At',
+        ];
+    }
+
+    /**
+     * Gets query for [[AuthItems]].
+     *
+     * @return \yii\db\ActiveQuery
+     */
+    public function getAuthItems()
+    {
+        return $this->hasMany(AuthItem::class, ['rule_name' => 'name']);
+    }
+}