-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathotp.go
More file actions
63 lines (57 loc) · 1.54 KB
/
Copy pathotp.go
File metadata and controls
63 lines (57 loc) · 1.54 KB
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
package http
import (
"net/http"
"github.com/infraboard/keyauth/apps/otp"
"github.com/infraboard/mcube/http/context"
"github.com/infraboard/mcube/http/request"
"github.com/infraboard/mcube/http/response"
)
// enable OTP
func (h *handler) CreateOTP(w http.ResponseWriter, r *http.Request) {
req := otp.NewCreateOTPAuthRequest()
if err := request.GetDataFromRequest(r, req); err != nil {
response.Failed(w, err)
return
}
ins, err := h.service.CreateOTPAuth(r.Context(), req)
if err != nil {
response.Failed(w, err)
return
}
response.Success(w, ins)
}
func (h *handler) GetOTP(w http.ResponseWriter, r *http.Request) {
ctx := context.GetContext(r)
account := ctx.PS.ByName("account")
req := otp.NewDescribeOTPAuthRequestWithName(account)
ins, err := h.service.DescribeOTPAuth(r.Context(), req)
if err != nil {
response.Failed(w, err)
return
}
response.Success(w, ins)
}
func (h *handler) DeleteOTP(w http.ResponseWriter, r *http.Request) {
ctx := context.GetContext(r)
account := ctx.PS.ByName("account")
req := otp.NewDeleteOTPAuthRequestWithName(account)
ins, err := h.service.DeleteOTPAuth(r.Context(), req)
if err != nil {
response.Failed(w, err)
return
}
response.Success(w, ins)
}
func (h *handler) UpdateOTP(w http.ResponseWriter, r *http.Request) {
req := otp.NewUpdateOTPStatusRequest()
if err := request.GetDataFromRequest(r, req); err != nil {
response.Failed(w, err)
return
}
d, err := h.service.UpdateOTPAuthStatus(r.Context(), req)
if err != nil {
response.Failed(w, err)
return
}
response.Success(w, d)
}