This commit is contained in:
laodaming 2023-11-23 12:05:18 +08:00
parent ab472a32f6
commit f18e1760a2
2 changed files with 35 additions and 45 deletions

View File

@ -6,7 +6,6 @@ import (
"fusenapi/utils/basic"
"fusenapi/utils/chinese_to_pinyin"
"fusenapi/utils/email"
"gorm.io/gorm"
"net/http"
"strings"
"time"
@ -63,38 +62,38 @@ func (l *CreateLdapUserLogic) CreateLdapUser(req *types.CreateLdapUserReq, r *ht
userDN := fmt.Sprintf("cn=%s,%s", req.Email, l.svcCtx.Config.Ldap.PeopleGroupDN)
//新增一条记录获取递增用户id
now := time.Now().UTC()
err := l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error {
userData := &gmodel.LdapUser{
UserDn: &userDN,
Ctime: &now,
Utime: &now,
}
if err := tx.WithContext(l.ctx).Model(&gmodel.LdapUser{}).Create(userData).Error; err != nil {
return err
}
return l.svcCtx.Ldap.Create(userDN, map[string][]string{
"objectClass": {"person", "organizationalPerson", "inetOrgPerson", "posixAccount", "top", "shadowAccount"}, //固有属性
"shadowLastChange": {"19676"}, //固有属性
"shadowMin": {"0"}, //固有属性
"shadowMax": {"99999"}, //固有属性
"shadowWarning": {"7"}, //固有属性
"loginShell": {"/usr/sbin/nologin"}, //固有属性
"homeDirectory": {"/home/users/" + userNamePinyin},
"employeeType": {fmt.Sprintf("%d", req.EmployeeType)}, //员工类型1正式 2实习 3外包
"uidNumber": {fmt.Sprintf("%d", userData.Id)}, //用户id
"gidNumber": {fmt.Sprintf("%d", userData.Id)}, //用户id
"uid": {userNamePinyin}, //用户名(拼音)
"cn": {req.Email}, //邮箱
"sn": {req.UserName}, //用户名
"mail": {req.Email}, //邮箱
"postalCode": {fmt.Sprintf("%d", req.Status)}, //状态
"departmentNumber": {fmt.Sprintf("%d", req.GroupId)}, //权限分组id
"postalAddress": {req.Avatar}, //头像
"mobile": {req.Mobile}, //手机号
"userPassword": {req.Password}, //密码
})
userData := &gmodel.LdapUser{
UserDn: &userDN,
Ctime: &now,
Utime: &now,
}
if err := l.svcCtx.AllModels.LdapUser.Create(l.ctx, userData); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "新增用户失败!")
}
err := l.svcCtx.Ldap.Create(userDN, map[string][]string{
"objectClass": {"person", "organizationalPerson", "inetOrgPerson", "posixAccount", "top", "shadowAccount"}, //固有属性
"shadowLastChange": {"19676"}, //固有属性
"shadowMin": {"0"}, //固有属性
"shadowMax": {"99999"}, //固有属性
"shadowWarning": {"7"}, //固有属性
"loginShell": {"/usr/sbin/nologin"}, //固有属性
"homeDirectory": {"/home/users/" + userNamePinyin},
"employeeType": {fmt.Sprintf("%d", req.EmployeeType)}, //员工类型1正式 2实习 3外包
"uidNumber": {fmt.Sprintf("%d", userData.Id)}, //用户id
"gidNumber": {fmt.Sprintf("%d", userData.Id)}, //用户id
"uid": {userNamePinyin}, //用户名(拼音)
"cn": {req.Email}, //邮箱
"sn": {req.UserName}, //用户名
"mail": {req.Email}, //邮箱
"postalCode": {fmt.Sprintf("%d", req.Status)}, //状态
"departmentNumber": {fmt.Sprintf("%d", req.GroupId)}, //权限分组id
"postalAddress": {req.Avatar}, //头像
"mobile": {req.Mobile}, //手机号
"userPassword": {req.Password}, //密码
})
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "添加用户失败,"+err.Error())
}
return resp.SetStatusWithMessage(basic.CodeOK, "添加用户成功")

View File

@ -6,8 +6,6 @@ import (
"fusenapi/utils/basic"
"time"
"gorm.io/gorm"
"context"
"fusenapi/server/ldap-admin/internal/svc"
@ -38,18 +36,11 @@ func (l *DeleteMenuLogic) DeleteMenu(req *types.DeleteMenuReq, userinfo *auth.Us
if req.Id <= 0 {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数id无效")
}
err := l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error {
menusModel := gmodel.NewLdapMenusModel(tx)
status := int64(0)
now := time.Now().UTC()
err := menusModel.Update(l.ctx, req.Id, &gmodel.LdapMenus{
Status: &status,
Utime: &now,
})
if err != nil {
return err
}
return nil
status := int64(0)
now := time.Now().UTC()
err := l.svcCtx.AllModels.LdapMenus.Update(l.ctx, req.Id, &gmodel.LdapMenus{
Status: &status,
Utime: &now,
})
if err != nil {
logx.Error(err)