fix
This commit is contained in:
parent
787f33f555
commit
be076197d2
|
@ -2,11 +2,15 @@ package gmodel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ldap_user ldap_用户id递增表
|
// ldap_user ldap_用户id递增表
|
||||||
type LdapUser struct {
|
type LdapUser struct {
|
||||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` //
|
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` //
|
||||||
|
UserDn *string `gorm:"index;default:'';" json:"user_dn"` //
|
||||||
|
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` //
|
||||||
|
Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` //
|
||||||
}
|
}
|
||||||
type LdapUserModel struct {
|
type LdapUserModel struct {
|
||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
|
|
|
@ -6,3 +6,18 @@ import "context"
|
||||||
func (u *LdapUserModel) Create(ctx context.Context, data *LdapUser) error {
|
func (u *LdapUserModel) Create(ctx context.Context, data *LdapUser) error {
|
||||||
return u.db.WithContext(ctx).Model(&LdapUser{}).Create(&data).Error
|
return u.db.WithContext(ctx).Model(&LdapUser{}).Create(&data).Error
|
||||||
}
|
}
|
||||||
|
func (u *LdapUserModel) Update(ctx context.Context, userDN string, data *LdapUser) error {
|
||||||
|
return u.db.WithContext(ctx).Model(&LdapUser{}).Where("user_dn = ?", userDN).Updates(&data).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *LdapUserModel) Delete(ctx context.Context, id int64) error {
|
||||||
|
return u.db.WithContext(ctx).Model(&LdapUser{}).Where("id = ?", id).Delete(&LdapUser{}).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *LdapUserModel) GetAllByIds(ctx context.Context, ids []int64) (resp []LdapUser, err error) {
|
||||||
|
if len(ids) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = u.db.WithContext(ctx).Model(&LdapUser{}).Where("id in (?)", ids).Find(&resp).Error
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
|
@ -9,7 +9,9 @@ import (
|
||||||
"fusenapi/utils/email"
|
"fusenapi/utils/email"
|
||||||
"fusenapi/utils/encryption_decryption"
|
"fusenapi/utils/encryption_decryption"
|
||||||
"fusenapi/utils/ldap_lib"
|
"fusenapi/utils/ldap_lib"
|
||||||
|
"gorm.io/gorm"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
@ -57,19 +59,23 @@ func (l *CreateLdapUserLogic) CreateLdapUser(req *types.CreateLdapUserReq, useri
|
||||||
ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN, l.svcCtx.Config.Ldap.PeopleGroupDN)
|
ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN, l.svcCtx.Config.Ldap.PeopleGroupDN)
|
||||||
//把用户名转pinyin
|
//把用户名转pinyin
|
||||||
userNamePinyin := chinese_to_pinyin.ChineseToPinyin(req.UserName)
|
userNamePinyin := chinese_to_pinyin.ChineseToPinyin(req.UserName)
|
||||||
//新增一条记录获取递增用户id
|
|
||||||
userData := &gmodel.LdapUser{}
|
|
||||||
if err := l.svcCtx.AllModels.LdapUser.Create(l.ctx, userData); err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "获取自增用户id失败")
|
|
||||||
}
|
|
||||||
userDN := fmt.Sprintf("cn=%s,%s", req.Email, l.svcCtx.Config.Ldap.PeopleGroupDN)
|
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
|
||||||
|
}
|
||||||
pwd, err := encryption_decryption.CBCEncrypt(req.Password)
|
pwd, err := encryption_decryption.CBCEncrypt(req.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
return err
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "加密密码失败")
|
|
||||||
}
|
}
|
||||||
if err := ldapServer.Create(userDN, map[string][]string{
|
return ldapServer.Create(userDN, map[string][]string{
|
||||||
"objectClass": {"person", "organizationalPerson", "inetOrgPerson", "posixAccount", "top", "shadowAccount"}, //固有属性
|
"objectClass": {"person", "organizationalPerson", "inetOrgPerson", "posixAccount", "top", "shadowAccount"}, //固有属性
|
||||||
"shadowLastChange": {"19676"}, //固有属性
|
"shadowLastChange": {"19676"}, //固有属性
|
||||||
"shadowMin": {"0"}, //固有属性
|
"shadowMin": {"0"}, //固有属性
|
||||||
|
@ -89,8 +95,9 @@ func (l *CreateLdapUserLogic) CreateLdapUser(req *types.CreateLdapUserReq, useri
|
||||||
"postalAddress": {req.Avatar}, //头像
|
"postalAddress": {req.Avatar}, //头像
|
||||||
"mobile": {req.Mobile}, //手机号
|
"mobile": {req.Mobile}, //手机号
|
||||||
"userPassword": {"{crypt}" + pwd}, //密码
|
"userPassword": {"{crypt}" + pwd}, //密码
|
||||||
}); err != nil {
|
})
|
||||||
logx.Error(err)
|
})
|
||||||
|
if err != nil {
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "添加用户失败,"+err.Error())
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "添加用户失败,"+err.Error())
|
||||||
}
|
}
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "添加用户成功")
|
return resp.SetStatusWithMessage(basic.CodeOK, "添加用户成功")
|
||||||
|
|
|
@ -90,6 +90,13 @@ func (l *GetLdapOrganizationMembersLogic) GetLdapOrganizationMembers(req *types.
|
||||||
}
|
}
|
||||||
list := make([]types.GetLdapOrganizationMembersItem, 0, memberCount)
|
list := make([]types.GetLdapOrganizationMembersItem, 0, memberCount)
|
||||||
for _, user := range userList {
|
for _, user := range userList {
|
||||||
|
if user.Status != 1 {
|
||||||
|
//从部门member中移出
|
||||||
|
if err = ldapServer.RemoveUserFromOrganization(req.OrganizationDN, user.UserDN); err != nil {
|
||||||
|
logx.Error("移除用户成员失败:", err)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
list = append(list, types.GetLdapOrganizationMembersItem{
|
list = append(list, types.GetLdapOrganizationMembersItem{
|
||||||
UserId: user.UserId,
|
UserId: user.UserId,
|
||||||
UserDN: user.UserDN,
|
UserDN: user.UserDN,
|
||||||
|
@ -99,8 +106,6 @@ func (l *GetLdapOrganizationMembersLogic) GetLdapOrganizationMembers(req *types.
|
||||||
Avatar: user.Avatar,
|
Avatar: user.Avatar,
|
||||||
EmployeeType: user.EmployeeType,
|
EmployeeType: user.EmployeeType,
|
||||||
Status: user.Status,
|
Status: user.Status,
|
||||||
//CreateTime: user.CreateTime.Format("2006-01-02 15:04:05"),
|
|
||||||
//UpdateTime: user.UpdateTime.Format("2006-01-02 15:04:05"),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetLdapOrganizationMembersRsp{
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetLdapOrganizationMembersRsp{
|
||||||
|
|
|
@ -2,12 +2,14 @@ package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/chinese_to_pinyin"
|
"fusenapi/utils/chinese_to_pinyin"
|
||||||
"fusenapi/utils/email"
|
"fusenapi/utils/email"
|
||||||
"fusenapi/utils/ldap_lib"
|
"fusenapi/utils/ldap_lib"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
@ -53,6 +55,7 @@ func (l *UpdateLdapUserLogic) UpdateLdapUser(req *types.UpdateLdapUserReq, useri
|
||||||
//把用户名转pinyin
|
//把用户名转pinyin
|
||||||
userNamePinyin := chinese_to_pinyin.ChineseToPinyin(req.UserName)
|
userNamePinyin := chinese_to_pinyin.ChineseToPinyin(req.UserName)
|
||||||
ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN, l.svcCtx.Config.Ldap.PeopleGroupDN)
|
ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN, l.svcCtx.Config.Ldap.PeopleGroupDN)
|
||||||
|
now := time.Now()
|
||||||
//更新的属性
|
//更新的属性
|
||||||
attr := map[string][]string{
|
attr := map[string][]string{
|
||||||
"homeDirectory": {"/home/users/" + userNamePinyin},
|
"homeDirectory": {"/home/users/" + userNamePinyin},
|
||||||
|
@ -69,6 +72,12 @@ func (l *UpdateLdapUserLogic) UpdateLdapUser(req *types.UpdateLdapUserReq, useri
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "更新用户失败,"+err.Error())
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "更新用户失败,"+err.Error())
|
||||||
}
|
}
|
||||||
|
err = l.svcCtx.AllModels.LdapUser.Update(l.ctx, req.UserDN, &gmodel.LdapUser{
|
||||||
|
Utime: &now,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
}
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "更新用户成功")
|
return resp.SetStatusWithMessage(basic.CodeOK, "更新用户成功")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user