24 lines
504 B
Go
24 lines
504 B
Go
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))
|
|
}
|