Skip to content

Commit

Permalink
feat: dynamically configure new user passwords
Browse files Browse the repository at this point in the history
  • Loading branch information
Trevor-Lan committed Aug 23, 2022
1 parent a633f8f commit 0c08075
Showing 3 changed files with 9 additions and 13 deletions.
8 changes: 2 additions & 6 deletions app/core/cmd/api/internal/logic/sys/user/addsysuserlogic.go
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ import (
"ark-admin-zero/app/core/cmd/api/internal/svc"
"ark-admin-zero/app/core/cmd/api/internal/types"
"ark-admin-zero/app/core/model"
"ark-admin-zero/common/config"
"ark-admin-zero/common/errorx"
"ark-admin-zero/common/utils"

@@ -39,12 +38,9 @@ func (l *AddSysUserLogic) AddSysUser(req *types.AddSysUserReq) error {
}

bytes, err := json.Marshal(req.RoleIds)
if err != nil {
return err
}

sysUser.RoleIds = string(bytes)
sysUser.Password = utils.MD5(config.SysNewUserDefaultPassword + l.svcCtx.Config.Salt)
dictionary, err := l.svcCtx.SysDictionaryModel.FindOneByUniqueKey(l.ctx, "sys_pwd")
sysUser.Password = utils.MD5(dictionary.Value + l.svcCtx.Config.Salt)
_, err = l.svcCtx.SysUserModel.Insert(l.ctx, sysUser)
if err != nil {
return errorx.NewDefaultError(errorx.ServerErrorCode)
3 changes: 1 addition & 2 deletions common/config/system.go
Original file line number Diff line number Diff line change
@@ -8,10 +8,9 @@ const (
SysSuperAdminUserId = 1
SysSuperAdminRoleId = 1
SysPermMenuPrefix = "/"
SysNewUserDefaultPassword = "123456"
SysDefaultPermType = 2
SysMaxPermMenuId = 50
SysMaxDictionaryId = 0
SysMaxDictionaryId = 2
SysEnable = 1
SysTopMenuId = 0
SysLoginLogType = 1
11 changes: 6 additions & 5 deletions doc/sql/ark_admin.sql
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
-- https://www.phpmyadmin.net/
--
-- 主机: mysql
-- 生成日期: 2022-08-23 10:07:30
-- 生成日期: 2022-08-23 13:44:56
-- 服务器版本: 5.7.36
-- PHP 版本: 7.4.27

@@ -75,7 +75,7 @@ CREATE TABLE `sys_dictionary` (

INSERT INTO `sys_dictionary` (`id`, `parent_id`, `name`, `type`, `unique_key`, `value`, `status`, `order_num`, `remark`, `create_time`, `update_time`) VALUES
(1, 0, '系统配置', 0, 'sys', '', 1, 0, '', '2022-08-22 10:03:58', '2022-08-23 01:25:31'),
(2, 1, '默认密码', 1, 'sys_pwd', '123456', 1, 0, '新建用户默认密码', '2022-08-22 10:03:58', '2022-08-23 10:04:57');
(2, 1, '默认密码', 1, 'sys_pwd', '123456', 1, 0, '新建用户默认密码', '2022-08-22 10:03:58', '2022-08-23 13:43:51');

-- --------------------------------------------------------

@@ -237,7 +237,8 @@ CREATE TABLE `sys_role` (
--

INSERT INTO `sys_role` (`id`, `parent_id`, `name`, `unique_key`, `remark`, `perm_menu_ids`, `status`, `order_num`, `create_time`, `update_time`) VALUES
(1, 0, '超级管理员', 'superadmin', '超级管理员', '[]', 1, 0, '2022-08-19 02:38:19', '2022-08-19 02:38:19');
(1, 0, '超级管理员', 'superadmin', '超级管理员', '[]', 1, 0, '2022-08-19 02:38:19', '2022-08-19 02:38:19'),
(2, 0, '测试', 'test', '', '[42, 43, 44, 45]', 1, 0, '2022-08-23 13:13:05', '2022-08-23 13:44:28');

-- --------------------------------------------------------

@@ -375,13 +376,13 @@ ALTER TABLE `sys_profession`
-- 使用表AUTO_INCREMENT `sys_role`
--
ALTER TABLE `sys_role`
MODIFY `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '编号', AUTO_INCREMENT=5;
MODIFY `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '编号', AUTO_INCREMENT=6;

--
-- 使用表AUTO_INCREMENT `sys_user`
--
ALTER TABLE `sys_user`
MODIFY `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '编号', AUTO_INCREMENT=3;
MODIFY `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '编号', AUTO_INCREMENT=2;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

0 comments on commit 0c08075

Please sign in to comment.