diff --git a/http/routing/login.go b/http/routing/login.go index a66d6e2..c41043a 100644 --- a/http/routing/login.go +++ b/http/routing/login.go @@ -33,13 +33,16 @@ func Login(s *response.Session, h http.Header, r *http.Request) rsvp.Response { } func LoginPost(session *response.Session, h http.Header, r *http.Request) rsvp.Response { - err := r.ParseForm() - if err != nil { - return response.Error(http.StatusBadRequest, "Failed to parse form") - } + username, password, ok := r.BasicAuth() + if !ok { + err := r.ParseForm() + if err != nil { + return response.Error(http.StatusBadRequest, "Failed to parse form") + } - username := r.Form.Get("username") - password := r.Form.Get("password") + username = r.Form.Get("username") + password = r.Form.Get("password") + } props := api.NewLoginProps(username, password) diff --git a/http/routing/register.go b/http/routing/register.go index d1b1262..36dc51a 100644 --- a/http/routing/register.go +++ b/http/routing/register.go @@ -29,14 +29,20 @@ func Register(session *response.Session, h http.Header, r *http.Request) rsvp.Re } func RegisterPost(s *response.Session, h http.Header, r *http.Request) rsvp.Response { - err := r.ParseForm() - if err != nil { - return response.Error(http.StatusBadRequest, "Failed to parse form") - } + var confirmPassword string + username, newPassword, ok := r.BasicAuth() + if ok { + confirmPassword = newPassword + } else { + err := r.ParseForm() + if err != nil { + return response.Error(http.StatusBadRequest, "Failed to parse form") + } - username := r.Form.Get("username") - newPassword := r.Form.Get("newPassword") - confirmPassword := r.Form.Get("confirmPassword") + username = r.Form.Get("username") + newPassword = r.Form.Get("newPassword") + confirmPassword = r.Form.Get("confirmPassword") + } props := api.NewRegisterProps(username, newPassword, confirmPassword) @@ -49,7 +55,7 @@ func RegisterPost(s *response.Session, h http.Header, r *http.Request) rsvp.Resp return rsvp.SeeOther(r.URL.Path, props) } - _, err = lishwist.Register(username, newPassword) + _, err := lishwist.Register(username, newPassword) if err != nil { if errors.Is(err, lishwist.ErrorUsernameTaken) { props.Username.Error = "Username is taken"