craban/server/api/auth.go

25 lines
504 B
Go
Raw Normal View History

package api
import (
"net/http"
)
func (a *API) Login(w http.ResponseWriter, r *http.Request) {
body := ParseBody(r)
username := body.String("username")
password := body.String("password")
token, err := a.App.Login(username, password)
if err != nil {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
if token == "" {
http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
return
}
w.Write([]byte(token))
}