commento/api/owner_self.go
2018-07-24 12:28:43 +05:30

31 lines
640 B
Go

package main
import (
"net/http"
)
func ownerSelfHandler(w http.ResponseWriter, r *http.Request) {
type request struct {
OwnerToken *string `json:"ownerToken"`
}
var x request
if err := bodyUnmarshal(r, &x); err != nil {
bodyMarshal(w, response{"success": false, "message": err.Error()})
return
}
o, err := ownerGetByOwnerToken(*x.OwnerToken)
if err == errorNoSuchToken {
bodyMarshal(w, response{"success": true, "loggedIn": false})
return
}
if err != nil {
bodyMarshal(w, response{"success": false, "message": err.Error()})
return
}
bodyMarshal(w, response{"success": true, "loggedIn": true, "owner": o})
}