Commit e7280538 authored by shajiaiming's avatar shajiaiming

user add

parent 49f32d09
......@@ -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,6 +22,7 @@ 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
{
......
......@@ -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'
];
}
}
......@@ -358,4 +358,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