Add login endpoint and generate a valid token
This commit is contained in:
parent
83a2d2a31f
commit
9b6f7cbdcc
6 changed files with 89 additions and 11 deletions
|
@ -1,10 +1,24 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (a *API) Login(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "FROM API")
|
||||
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))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue