/
user_utils.go
48 lines (38 loc) · 1.17 KB
/
user_utils.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
package api
import (
"github.com/Ptt-official-app/go-pttbbs/bbs"
"github.com/Ptt-official-app/go-pttbbs/ptttype"
)
// valid users to see/change the user-info.
func userInfoIsValidUser(uuserID bbs.UUserID, queryUUserID bbs.UUserID) (isValid bool) {
if queryUUserID == bbs.UUserID(ptttype.STR_GUEST) {
return false
}
permSysop := ptttype.PERM_ACCOUNTS | ptttype.PERM_SYSOP | ptttype.PERM_ACCTREG
if bbs.IsSysop(uuserID, permSysop) {
return true
}
return uuserID == queryUUserID
}
// valid users to see/change email / user-level2
func userInfoIsValidEmailUser(uuserID bbs.UUserID, queryUUserID bbs.UUserID, jwt string, context EmailTokenContext, isAllowSysop bool) (isValid bool, email string) {
if queryUUserID == bbs.UUserID(ptttype.STR_GUEST) {
return false, ""
}
isSysop := false
if isAllowSysop {
permSysop := ptttype.PERM_ACCOUNTS | ptttype.PERM_SYSOP | ptttype.PERM_ACCTREG
isSysop = bbs.IsSysop(uuserID, permSysop)
}
if !isSysop && uuserID != queryUUserID {
return false, ""
}
emailUserID, _, _, email, err := VerifyEmailJwt(jwt, context)
if err != nil {
return false, ""
}
if queryUUserID != emailUserID {
return false, ""
}
return true, email
}