Commit 136adbd7 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/manage-user' into 'master'

Feature/manage user See merge request !430
parents 7516e69a 5056fa96
......@@ -34,6 +34,8 @@ class UserAuthInterceptor extends ActionFilter
goto doEnd;
}
return true;
$group = $user["data"]->group;
$user_id = $user["data"]->uid;
$platform_id = $user["data"]->platform_id;
......
......@@ -22,10 +22,11 @@ use yii\web\IdentityInterface;
* @property string $update_time
* @property integer $status
* @property integer $platform_id
* @property integer $group
*/
class Admin extends \common\modelsgii\Admin implements IdentityInterface
{
const STATUS_DELETED = 0;
const STATUS_DELETED = 2;
const STATUS_ACTIVE = 1;
/**
......@@ -33,7 +34,7 @@ class Admin extends \common\modelsgii\Admin implements IdentityInterface
*/
public static function findIdentity($uid)
{
return static::find()->where(['uid' => $uid, 'status' => self::STATUS_ACTIVE])->one();
return static::find()->where(['uid' => $uid])->one();
}
/**
......@@ -44,7 +45,7 @@ class Admin extends \common\modelsgii\Admin implements IdentityInterface
*/
public static function findByUsername($username)
{
return static::findOne(['username' => $username, 'status' => self::STATUS_ACTIVE]);
return static::findOne(['username' => $username]);
}
/**
......
......@@ -23,8 +23,8 @@ use yii\web\IdentityInterface;
*/
class User extends ActiveRecord implements IdentityInterface
{
const STATUS_DELETED = 0;
const STATUS_ACTIVE = 10;
const STATUS_DELETED = 2;
const STATUS_ACTIVE = 1;
const AUTH_SUPER = 'administrator';
......
......@@ -19,6 +19,7 @@ use yii\helpers\HtmlPurifier;
* @property string $update_time
* @property integer $status
* @property integer $platform_id
* @property integer $group
*/
class Admin extends \common\core\BaseActiveRecord
{
......@@ -48,7 +49,7 @@ class Admin extends \common\core\BaseActiveRecord
[['username'], 'string', 'max' => 32],
[['password'], 'string', 'min' => 6, 'max' => 60],
[['salt'], 'string', 'max' => 32],
['access_token', 'safe']
[['access_token','group'], 'safe']
];
}
......@@ -68,8 +69,8 @@ class Admin extends \common\core\BaseActiveRecord
'last_login_ip' => 'Last Login Ip',
'update_time' => 'Update Time',
'status' => 'Status',
'platform_id' => 'platform_id',
'group' => 'group'
'platform_id' => 'PlatformId',
'group' => 'Group'
];
}
}
......@@ -34,6 +34,12 @@ class UserController extends BaseController
$code = -1;
goto doEnd;
}
if (Admin::STATUS_DELETED == $user->status) {
$msg = '用户已停用';
$data = null;
$code = -1;
goto doEnd;
}
$token = [
'iss' => 'https://www.bitfeel.cn', //签发者 可选
'aud' => 'https://www.bitfeel.cn', //接收该JWT的一方,可选
......@@ -358,4 +364,80 @@ class UserController extends BaseController
doEnd :
return ['code' => $this->code, 'msg' => $this->msg, 'data' => $this->data];
}
public function actionAdd()
{
if (!Yii::$app->request->isPost) {
$this->msg = '请求方式错误';
$this->code = -1;
goto doEnd;
}
$group = Yii::$app->request->getGroup();
if (!in_array($group, ['administrator', 'admin'])) {
$this->code = -1;
$this->msg = '当前用户无权操作';
goto doEnd;
}
$platform_id = Yii::$app->request->getPlatformId();
if ('administrator' === $group) {
$platform_id = Yii::$app->request->post('platform_id', 1);
}
$token = Yii::$app->request->headers->get('Token');
$user_info = Admin::verfication($token);
if (0 != $user_info['code']) {
$this->msg = $user_info['data'];
$this->code = -1;
goto doEnd;
}
$data = Yii::$app->request->post();
$username = Yii::$app->request->post('username', null);
$password = Yii::$app->request->post('password', null);
if (empty($username)) {
$this->code = -1;
$this->msg = '用户名不能为空';
goto doEnd;
}
if (empty($password)) {
$this->code = -1;
$this->msg = '密码不能为空';
goto doEnd;
}
if (strlen($data['password']) < 6) {
$this->code = -1;
$this->msg = '密码不能小于6字符';
goto doEnd;
}
$user = Admin::findByUsername($username);
if ($user) {
$this->code = -1;
$this->msg = '用户名已存在';
goto doEnd;
}
$params = [
'username' => $username,
'reg_time' => time(),
'status' => $data['status'] ?? 0,
'update_time' => 0,
'last_login_time' => 0,
'group' => 'general',
'platform_id' => $platform_id,
'reg_ip' => ip2long(Yii::$app->request->getUserIP()),
'last_login_ip' => ip2long('127.0.0.1'),
];
$model = new Admin();
#var_dump($model->getAttributes());exit;
$model->setAttributes($params);
$model->generateAuthKey();
$model->setPassword($password);
$model->save();
doEnd :
return ['code' => $this->code, 'msg' => $this->msg, 'data' => $this->data];
}
}
\ No newline at end of file
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