Client UUID added to JWT
This commit is contained in:
parent
dfd6260a7a
commit
dc010df448
6 changed files with 65 additions and 38 deletions
24
main.go
24
main.go
|
|
@ -167,7 +167,7 @@ func authenticated(fn func(http.ResponseWriter, *http.Request)) func(http.Respon
|
|||
user := NewUser(claims)
|
||||
r = r.WithContext(context.WithValue(r.Context(), CONTEXT_USER, user))
|
||||
|
||||
Log.Info("webserver", "op", "request", "method", r.Method, "url", r.URL.String(), "username", user.Username)
|
||||
Log.Debug("webserver", "op", "request", "method", r.Method, "url", r.URL.String(), "username", user.Username, "client", user.ClientUUID)
|
||||
fn(w, r)
|
||||
}
|
||||
} // }}}
|
||||
|
|
@ -246,22 +246,11 @@ func actionSyncFromServer(w http.ResponseWriter, r *http.Request) { // {{{
|
|||
// The purpose of the Client UUID is to avoid
|
||||
// sending nodes back once again to a client that
|
||||
// just created or modified it.
|
||||
request := struct {
|
||||
ClientUUID string
|
||||
}{}
|
||||
body, _ := io.ReadAll(r.Body)
|
||||
err := json.Unmarshal(body, &request)
|
||||
if err != nil {
|
||||
Log.Error("/node/tree", "error", err)
|
||||
httpError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
user := getUser(r)
|
||||
changedFrom, _ := strconv.Atoi(r.PathValue("sequence"))
|
||||
offset, _ := strconv.Atoi(r.PathValue("offset"))
|
||||
|
||||
nodes, maxSeq, moreRowsExist, err := Nodes(user.ID, offset, uint64(changedFrom), request.ClientUUID)
|
||||
nodes, maxSeq, moreRowsExist, err := Nodes(user.UserID, offset, uint64(changedFrom), user.ClientUUID)
|
||||
if err != nil {
|
||||
Log.Error("/node/tree", "error", err)
|
||||
httpError(w, err)
|
||||
|
|
@ -285,7 +274,7 @@ func actionNodeRetrieve(w http.ResponseWriter, r *http.Request) { // {{{
|
|||
var err error
|
||||
|
||||
uuid := r.PathValue("uuid")
|
||||
node, err := RetrieveNode(user.ID, uuid)
|
||||
node, err := RetrieveNode(user.UserID, uuid)
|
||||
if err != nil {
|
||||
responseError(w, err)
|
||||
return
|
||||
|
|
@ -301,7 +290,6 @@ func actionSyncToServer(w http.ResponseWriter, r *http.Request) { // {{{
|
|||
|
||||
body, _ := io.ReadAll(r.Body)
|
||||
var request struct {
|
||||
ClientUUID string
|
||||
NodeData string
|
||||
}
|
||||
err := json.Unmarshal(body, &request)
|
||||
|
|
@ -310,7 +298,7 @@ func actionSyncToServer(w http.ResponseWriter, r *http.Request) { // {{{
|
|||
return
|
||||
}
|
||||
|
||||
db.Exec(`CALL add_nodes($1, $2, $3::jsonb)`, user.ID, request.ClientUUID, request.NodeData)
|
||||
db.Exec(`CALL add_nodes($1, $2, $3::jsonb)`, user.UserID, user.ClientUUID, request.NodeData)
|
||||
|
||||
responseData(w, map[string]interface{}{
|
||||
"OK": true,
|
||||
|
|
@ -359,7 +347,7 @@ func changePassword(username string) { // {{{
|
|||
|
||||
fmt.Printf("\nPassword changed\n")
|
||||
} // }}}
|
||||
func getUser(r *http.Request) User { // {{{
|
||||
user, _ := r.Context().Value(CONTEXT_USER).(User)
|
||||
func getUser(r *http.Request) UserSession { // {{{
|
||||
user, _ := r.Context().Value(CONTEXT_USER).(UserSession)
|
||||
return user
|
||||
} // }}}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue