mirror of
https://github.com/1f349/lotus.git
synced 2024-11-12 23:11:36 +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
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/1f349/lotus/imap"
|
"github.com/1f349/lotus/imap"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
@ -49,17 +50,25 @@ func SetupApiServer(listen string, auth *AuthChecker, send Smtp, recv Imap) *htt
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// get a "possible" auth token value
|
// parse token from message
|
||||||
authToken := string(msg)
|
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
|
// get a "possible" auth token value
|
||||||
// exit on empty reply
|
// exit on empty token value
|
||||||
if authToken == "" {
|
if tokenMsg.Token == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the token
|
// check the token
|
||||||
authUser, err := auth.Check(authToken)
|
authUser, err := auth.Check(tokenMsg.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// exit on error
|
// exit on error
|
||||||
return
|
return
|
||||||
@ -69,7 +78,7 @@ func SetupApiServer(listen string, auth *AuthChecker, send Smtp, recv Imap) *htt
|
|||||||
|
|
||||||
client, err := recv.MakeClient(authUser.Subject)
|
client, err := recv.MakeClient(authUser.Subject)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = c.WriteJSON(map[string]string{"Error": "Making client failed"})
|
_ = c.WriteJSON(map[string]string{"error": "Making client failed"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ func (c *Client) HandleWS(action string, args []string) (map[string]any, error)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return map[string]any{"Info": a}, nil
|
return map[string]any{"info": a}, nil
|
||||||
case "move":
|
case "move":
|
||||||
// TODO: implementation
|
// TODO: implementation
|
||||||
case "rename":
|
case "rename":
|
||||||
|
Loading…
Reference in New Issue
Block a user