-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin.go
72 lines (65 loc) · 1.63 KB
/
admin.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
package main
import (
"fmt"
"net/http"
"github.com/go-chi/chi/v5"
"github.com/rkonfj/lln/state"
"github.com/rkonfj/lln/tools"
)
func userVerified(w http.ResponseWriter, r *http.Request) {
u := state.UserByID(chi.URLParam(r, tools.UID))
if u == nil {
w.WriteHeader(http.StatusNotFound)
return
}
code, err := tools.URLQueryInt64(r, "code")
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprint(w, err.Error())
return
}
err = u.SetVerified(code)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprint(w, err.Error())
return
}
state.UserChanged <- u
state.DefaultSessionManager.Expire(u.ID)
}
func recommendStatus(w http.ResponseWriter, r *http.Request) {
if err := state.RecommendStatus(chi.URLParam(r, tools.StatusID)); err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprint(w, err.Error())
}
}
func notRecommendStatus(w http.ResponseWriter, r *http.Request) {
if err := state.NotRecommendStatus(chi.URLParam(r, tools.StatusID)); err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprint(w, err.Error())
}
}
func disableUser(w http.ResponseWriter, r *http.Request) {
u := state.UserByID(chi.URLParam(r, tools.UID))
if u == nil {
w.WriteHeader(http.StatusNotFound)
return
}
err := u.Disable()
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprint(w, err.Error())
}
}
func enableUser(w http.ResponseWriter, r *http.Request) {
u := state.UserByID(chi.URLParam(r, tools.UID))
if u == nil {
w.WriteHeader(http.StatusNotFound)
return
}
err := u.Enable()
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprint(w, err.Error())
}
}