mirror of
https://github.com/fumiama/paper-manager.git
synced 2026-06-16 07:12:17 +08:00
finish register
This commit is contained in:
@@ -3,6 +3,7 @@ package backend
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/fumiama/paper-manager/backend/utils"
|
||||
)
|
||||
@@ -75,6 +76,39 @@ func init() {
|
||||
writeresult(w, codeSuccess, nil, messageOk, typeSuccess)
|
||||
}}
|
||||
|
||||
apimap["/api/register"] = &apihandler{"POST", func(w http.ResponseWriter, r *http.Request) {
|
||||
type registerbody struct {
|
||||
Username string `json:"username"`
|
||||
Mobile string `json:"mobile"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
if r.Header.Get("Authorization") != "" {
|
||||
writeresult(w, codeError, nil, errInvalidToken.Error(), typeError)
|
||||
return
|
||||
}
|
||||
var body registerbody
|
||||
defer r.Body.Close()
|
||||
err := json.NewDecoder(r.Body).Decode(&body)
|
||||
if err != nil {
|
||||
writeresult(w, codeError, nil, err.Error(), typeError)
|
||||
return
|
||||
}
|
||||
ip := r.RemoteAddr
|
||||
i := strings.LastIndex(ip, ":")
|
||||
if i >= 0 {
|
||||
ip = ip[:i]
|
||||
}
|
||||
err = register(ip, body.Username, body.Mobile, body.Password)
|
||||
if err != nil {
|
||||
writeresult(w, codeError, nil, err.Error(), typeError)
|
||||
return
|
||||
}
|
||||
type message struct {
|
||||
M string `json:"msg"`
|
||||
}
|
||||
writeresult(w, codeSuccess, &message{M: "成功, 请耐心等待通知"}, messageOk, typeSuccess)
|
||||
}}
|
||||
|
||||
apimap["/api/getUsersCount"] = &apihandler{"GET", func(w http.ResponseWriter, r *http.Request) {
|
||||
token := r.Header.Get("Authorization")
|
||||
n, err := getUsersCount(token)
|
||||
|
||||
Reference in New Issue
Block a user