mirror of
https://github.com/1f349/lotus.git
synced 2024-11-09 22:52:53 +00:00
Read token from json
This commit is contained in:
parent
29b1694840
commit
675423c06e
23
api/api.go
23
api/api.go
@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"github.com/1f349/lotus/imap"
|
||||
"github.com/gorilla/websocket"
|
||||
@ -49,17 +50,25 @@ func SetupApiServer(listen string, auth *AuthChecker, send Smtp, recv Imap) *htt
|
||||
return
|
||||
}
|
||||
|
||||
// get a "possible" auth token value
|
||||
authToken := string(msg)
|
||||
// parse token from message
|
||||
var tokenMsg struct {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
dec := json.NewDecoder(bytes.NewReader(msg))
|
||||
dec.DisallowUnknownFields()
|
||||
err = dec.Decode(&tokenMsg)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// wait for authToken or error
|
||||
// exit on empty reply
|
||||
if authToken == "" {
|
||||
// get a "possible" auth token value
|
||||
// exit on empty token value
|
||||
if tokenMsg.Token == "" {
|
||||
return
|
||||
}
|
||||
|
||||
// check the token
|
||||
authUser, err := auth.Check(authToken)
|
||||
authUser, err := auth.Check(tokenMsg.Token)
|
||||
if err != nil {
|
||||
// exit on error
|
||||
return
|
||||
@ -69,7 +78,7 @@ func SetupApiServer(listen string, auth *AuthChecker, send Smtp, recv Imap) *htt
|
||||
|
||||
client, err := recv.MakeClient(authUser.Subject)
|
||||
if err != nil {
|
||||
_ = c.WriteJSON(map[string]string{"Error": "Making client failed"})
|
||||
_ = c.WriteJSON(map[string]string{"error": "Making client failed"})
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ func (c *Client) HandleWS(action string, args []string) (map[string]any, error)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return map[string]any{"Info": a}, nil
|
||||
return map[string]any{"info": a}, nil
|
||||
case "move":
|
||||
// TODO: implementation
|
||||
case "rename":
|
||||
|
Loading…
Reference in New Issue
Block a user