Change login route, add form
This commit is contained in:
parent
6556c8049c
commit
81135c29f0
4 changed files with 38 additions and 9 deletions
|
@ -57,7 +57,7 @@ func main() {
|
||||||
loginForm.Add("username", *username)
|
loginForm.Add("username", *username)
|
||||||
loginForm.Add("password", *password)
|
loginForm.Add("password", *password)
|
||||||
|
|
||||||
loginReq, err := http.NewRequest("POST", "http"+secureSuffix()+"://"+*addr+"/login", strings.NewReader(loginForm.Encode()))
|
loginReq, err := http.NewRequest("POST", "http"+secureSuffix()+"://"+*addr+"/api/login", strings.NewReader(loginForm.Encode()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,10 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
_ "embed"
|
||||||
|
|
||||||
"dynatron.me/x/stillbox/pkg/config"
|
"dynatron.me/x/stillbox/pkg/config"
|
||||||
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/go-chi/jwtauth/v5"
|
"github.com/go-chi/jwtauth/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -66,3 +69,20 @@ func ErrorResponse(w http.ResponseWriter, err error) {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Auth) PublicRoutes(r chi.Router) {
|
||||||
|
r.Post("/api/login", a.routeAuth)
|
||||||
|
r.Get("/api/login", a.routeLogin)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Auth) PrivateRoutes(r chi.Router) {
|
||||||
|
r.Get("/refresh", a.routeRefresh)
|
||||||
|
}
|
||||||
|
|
||||||
|
//go:embed login.html
|
||||||
|
var loginPage []byte
|
||||||
|
|
||||||
|
func (a *Auth) routeLogin(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Add("Content-Type", "text/html")
|
||||||
|
_, _ = w.Write(loginPage)
|
||||||
|
}
|
||||||
|
|
|
@ -110,14 +110,6 @@ func (a *Auth) newToken(uid int32) string {
|
||||||
return tokenString
|
return tokenString
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Auth) PublicRoutes(r chi.Router) {
|
|
||||||
r.Post("/login", a.routeAuth)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *Auth) PrivateRoutes(r chi.Router) {
|
|
||||||
r.Get("/refresh", a.routeRefresh)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *Auth) allowInsecureCookie(r *http.Request) bool {
|
func (a *Auth) allowInsecureCookie(r *http.Request) bool {
|
||||||
host := strings.Split(r.Host, ":")
|
host := strings.Split(r.Host, ":")
|
||||||
v, has := a.cfg.AllowInsecure[host[0]]
|
v, has := a.cfg.AllowInsecure[host[0]]
|
||||||
|
|
17
pkg/auth/login.html
Normal file
17
pkg/auth/login.html
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Login</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
<form action="/login" method="POST">
|
||||||
|
<label for="username">Username: </label>
|
||||||
|
<input type="text" name="username" />
|
||||||
|
<label for="password">Password: </label>
|
||||||
|
<input type="password" name="password" />
|
||||||
|
<input type="submit" value="Login" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in a new issue