2021-09-13 09:06:57 +01:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (a *API) Login(w http.ResponseWriter, r *http.Request) {
|
2021-09-13 11:46:43 +01:00
|
|
|
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))
|
2021-09-13 09:06:57 +01:00
|
|
|
}
|