-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
86 lines (80 loc) · 2.04 KB
/
user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package UserCore
import (
"encoding/json"
"errors"
CoreFilter "github.com/fotomxq/weeekj_core/v5/core/filter"
CoreSQL "github.com/fotomxq/weeekj_core/v5/core/sql"
Router2SystemConfig "github.com/fotomxq/weeekj_core/v5/router2/system_config"
)
// 检查用户是否可以成为上级
// 递归检查上级关系,如果形成悖论,则反馈失败
func checkUserParentID(id int64, parentID int64, systemMark string, checkParentIDs []int64) error {
checkParentIDs = append(checkParentIDs, id)
if id == parentID {
return errors.New("parent id is cycle")
}
parentData, err := GetUserByID(&ArgsGetUserByID{
ID: parentID,
})
if err != nil {
//上级不存在
return errors.New("parent is not exist")
}
//上级存在,则检查其上级是否在序列内?
for _, v := range checkParentIDs {
for _, v2 := range parentData.Parents {
if v == v2.ParentID && systemMark == v2.System {
return errors.New("parent id is cycle")
}
}
}
//不存在上级,则跳出
if len(parentData.Parents) < 1 {
return nil
}
//不存在则继续
for _, v := range parentData.Parents {
if err := checkUserParentID(parentData.ID, v.ParentID, systemMark, checkParentIDs); err != nil {
return err
}
}
return nil
}
// 获取用户组使用数量
func getUserCountByGroup(groupID int64, orgID int64) (count int64) {
type argType struct {
GroupID int64 `json:"group_id"`
}
argsJSON, err := json.Marshal([]argType{
{
GroupID: groupID,
},
})
if err != nil {
return
}
count, err = CoreSQL.GetAllCount(Router2SystemConfig.MainDB.DB, "user_core", "id", "org_id = $1 AND groups @> $2", orgID, string(argsJSON))
if err != nil {
return
}
return
}
// 检查密码
func checkPassword(password string) bool {
return CoreFilter.CheckPassword(password)
}
// 获取密码摘要
func getPasswordSha(password string) (string, error) {
return CoreFilter.GetSha1ByString(password)
}
// 检查status
func checkUserStatus(status int) error {
switch status {
case 0:
case 1:
case 2:
default:
return errors.New("status is error")
}
return nil
}