diff --git a/application/admin/controller/user/User.php b/application/admin/controller/user/User.php index 814ecd03c1e3464d4d494fec95d008200a8481ec..45b9c7cf00822e15d43cacb3d04f490177417e6a 100644 --- a/application/admin/controller/user/User.php +++ b/application/admin/controller/user/User.php @@ -13,6 +13,7 @@ class User extends Backend { protected $relationSearch = true; + protected $modelValidate = true; /** @@ -60,6 +61,15 @@ class User extends Backend return $this->view->fetch(); } + /** + * 添加 + */ + public function add() + { + $this->view->assign('groupList', build_select('row[group_id]', \app\admin\model\UserGroup::column('id,name'), 0, ['class' => 'form-control selectpicker'])); + return parent::add(); + } + /** * 编辑 */ diff --git a/application/admin/lang/zh-cn/user/user.php b/application/admin/lang/zh-cn/user/user.php index 13f096dfd5f17b5f3789320e1bc7460577b37d27..57d4d27c3ae7e5fe405681d6198b784bd036fe05 100644 --- a/application/admin/lang/zh-cn/user/user.php +++ b/application/admin/lang/zh-cn/user/user.php @@ -1,33 +1,36 @@ 'ID', - 'Group_id' => '组别ID', - 'Username' => '用户名', - 'Nickname' => '昵称', - 'Password' => '密码', - 'Salt' => '密码盐', - 'Email' => '电子邮箱', - 'Mobile' => '手机号', - 'Avatar' => '头像', - 'Level' => '等级', - 'Gender' => '性别', - 'Male' => '男', - 'FeMale' => '女', - 'Birthday' => '生日', - 'Bio' => '格言', - 'Score' => '积分', - 'Successions' => '连续登录天数', - 'Maxsuccessions' => '最大连续登录天数', - 'Prevtime' => '上次登录时间', - 'Logintime' => '登录时间', - 'Loginip' => '登录IP', - 'Loginfailure' => '失败次数', - 'Joinip' => '加入IP', - 'Jointime' => '加入时间', - 'Createtime' => '创建时间', - 'Updatetime' => '更新时间', - 'Token' => 'Token', - 'Status' => '状态', + 'Id' => 'ID', + 'Group_id' => '组别ID', + 'Username' => '用户名', + 'Nickname' => '昵称', + 'Password' => '密码', + 'Salt' => '密码盐', + 'Email' => '电子邮箱', + 'Mobile' => '手机号', + 'Avatar' => '头像', + 'Level' => '等级', + 'Gender' => '性别', + 'Male' => '男', + 'FeMale' => '女', + 'Birthday' => '生日', + 'Bio' => '格言', + 'Score' => '积分', + 'Successions' => '连续登录天数', + 'Maxsuccessions' => '最大连续登录天数', + 'Prevtime' => '上次登录时间', + 'Logintime' => '登录时间', + 'Loginip' => '登录IP', + 'Loginfailure' => '失败次数', + 'Joinip' => '加入IP', + 'Jointime' => '加入时间', + 'Createtime' => '创建时间', + 'Updatetime' => '更新时间', + 'Token' => 'Token', + 'Status' => '状态', 'Leave password blank if dont want to change' => '不修改密码请留空', + 'Username can not be empty' => '用户名不能为空', + 'Username must be 3 to 30 characters' => '用户名必须3-30个字符', + 'Username already exist' => '用户名已经存在', ]; diff --git a/application/admin/model/User.php b/application/admin/model/User.php index 691f3b1248a54b34d07eb58c7474c39d1b9ec2cc..a698f14dba37e2c3f5cc898d22c34642ca089c8c 100644 --- a/application/admin/model/User.php +++ b/application/admin/model/User.php @@ -29,6 +29,21 @@ class User extends Model protected static function init() { + self::beforeInsert(function ($row) { + $changed = $row->getChangedData(); + $salt = \fast\Random::alnum(); + $row->password = \app\common\library\Auth::instance()->getEncryptPassword($changed['password'], $salt); + $row->salt = $salt; + $row->nickname = $row->nickname ? $row->nickname : $row->username; + $row->joinip = $row->loginip = '127.0.0.1'; + $row->jointime = request()->time(); + //如果生日为空 + if (isset($row->birthday) && empty($row->birthday)) { + unset($row->birthday); + } + }); + + self::beforeUpdate(function ($row) { $changed = $row->getChangedData(); //如果有修改密码 @@ -41,6 +56,10 @@ class User extends Model unset($row->password); } } + //如果生日为空 + if (isset($row->birthday) && empty($row->birthday)) { + unset($row->birthday); + } }); diff --git a/application/admin/validate/User.php b/application/admin/validate/User.php index e1747f4319aeb079c6fcc92f5c052b5a798e516f..c0b5d05ddf37a79f9a5914cacc743e268876718e 100644 --- a/application/admin/validate/User.php +++ b/application/admin/validate/User.php @@ -10,11 +10,15 @@ class User extends Validate * 验证规则 */ protected $rule = [ + 'username' => 'require|length:3,30|unique:user', ]; /** * 提示消息 */ protected $message = [ + 'username.require' => 'Username can not be empty', + 'username.length' => 'Username must be 3 to 30 characters', + 'username.unique' => 'Username already exist', ]; /** * 验证场景 diff --git a/application/admin/view/user/user/add.html b/application/admin/view/user/user/add.html new file mode 100644 index 0000000000000000000000000000000000000000..1e9835c14b0ef727f7e9c13bedf68f53d47608e1 --- /dev/null +++ b/application/admin/view/user/user/add.html @@ -0,0 +1,102 @@ +
+ +
+ +
+ {$groupList} +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ +
+ + +
+ +
+
    +
    +
    +
    + +
    + +
    +
    +
    + +
    + {:build_radios('row[gender]', ['1'=>__('Male'), '0'=>__('Female')])} +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + {:build_radios('row[status]', ['normal'=>__('Normal'), 'hidden'=>__('Hidden')])} +
    +
    + +
    diff --git a/application/admin/view/user/user/edit.html b/application/admin/view/user/user/edit.html index 426289bd19305306cc1b6cfeebf255e19d2defd6..6584ac73dca090c714019c474cf18e58919072c8 100644 --- a/application/admin/view/user/user/edit.html +++ b/application/admin/view/user/user/edit.html @@ -1,5 +1,5 @@
    - +
    diff --git a/application/admin/view/user/user/index.html b/application/admin/view/user/user/index.html index 00308e8d062f126ea29f5d14df74e0b57e793a9e..9ca85f5081fd69723835e7ea45302086634cbb9e 100644 --- a/application/admin/view/user/user/index.html +++ b/application/admin/view/user/user/index.html @@ -6,7 +6,7 @@
    - {:build_toolbar('refresh,edit,del')} + {:build_toolbar('refresh,add,edit,del')}