-
Notifications
You must be signed in to change notification settings - Fork 1
/
attach.go
49 lines (38 loc) · 1.2 KB
/
attach.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
package user
import (
"fmt"
"github.com/labstack/echo/v4"
"github.com/lucky-byte/reactgo/serve/db"
"github.com/lucky-byte/reactgo/serve/route/lib/acl"
"github.com/lucky-byte/reactgo/serve/route/lib/secretcode"
)
func Attach(up *echo.Group, code int) {
group := up.Group("/user", acl.AllowRead(code))
group.GET("/list", list)
group.GET("/info", info)
group.Use(acl.AllowWrite(code))
group.POST("/add", add)
group.PUT("/modify", modify)
group.PUT("/passwd", passwd)
group.PUT("/acl", aclUpdate)
group.PUT("/bank", bank, secretcode.Verify())
group.POST("/clearsecretcode", clearSecretCode)
group.POST("/cleartotp", clearTOTP)
group.POST("/disable", disable)
group.Use(acl.AllowAdmin(code))
group.GET("/profile", profile)
group.DELETE("/delete", del, secretcode.Verify())
}
// 是否允许修改用户信息
func isUpdatable(user_uuid string) (*db.User, error) {
ql := `select * from users where uuid = ?`
var user db.User
if err := db.SelectOne(ql, &user, user_uuid); err != nil {
return nil, err
}
// 已禁用或删除的用户不能修改信息
if user.Disabled || user.Deleted {
return nil, fmt.Errorf("用户已被禁用或删除,不能修改用户信息")
}
return &user, nil
}