Set correct login flow
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Melora Hugues 2023-10-15 20:11:50 +02:00
parent 20fde2335e
commit 1e8b9ef161
9 changed files with 34 additions and 43 deletions

View file

@ -35,8 +35,14 @@ func NewIndexController(l *logrus.Logger, downstream http.Handler) *IndexControl
}
func (ic IndexController) serveUI(w http.ResponseWriter, r *http.Request) (int, int, error) {
funcs := template.FuncMap{
"issuer": func() string { return "toto" },
}
lp := filepath.Join("templates", "index.html")
tmpl, err := template.ParseFiles(lp)
hdrTpl := filepath.Join("templates", "header.html")
footTpl := filepath.Join("templates", "footer.html")
tmpl, err := template.New("index.html").Funcs(funcs).ParseFiles(hdrTpl, footTpl, lp)
if err != nil {
return http.StatusInternalServerError, -1, fmt.Errorf("failed to init template: %w", err)
}
@ -55,14 +61,13 @@ func (ic IndexController) serveUI(w http.ResponseWriter, r *http.Request) (int,
func (ic *IndexController) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.RequestURI != "/" {
ic.l.Debugf("Serving URI %q to dex handler", r.RequestURI)
ic.downstreamConstroller.ServeHTTP(w, r)
return
}
returncode, contentLength, err := ic.serveUI(w, r)
returncode, _, err := ic.serveUI(w, r)
if err != nil {
ic.l.Errorf("Error serving UI: %s", err.Error())
helpers.HandleResponse(w, r, returncode, nil, ic.l)
} else {
helpers.AddToContext(r, returncode, contentLength)
}
}

View file

@ -29,8 +29,3 @@ func HandleResponse(w http.ResponseWriter, r *http.Request, returncode int, cont
contextedReq := r.WithContext(context.WithValue(r.Context(), ResponseInfoKey, ResponseInfo{ReturnCode: returncode, ContentLength: len(content)}))
*r = *contextedReq
}
func AddToContext(r *http.Request, returncode, contentLength int) {
contextedReq := r.WithContext(context.WithValue(r.Context(), ResponseInfoKey, ResponseInfo{ReturnCode: returncode, ContentLength: contentLength}))
*r = *contextedReq
}

View file

@ -39,7 +39,7 @@ type LoggerMiddleware struct {
func (lm *LoggerMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
recorder := loggedResponseWriter{
contentLength: -1,
contentLength: 0,
statusCode: -1,
w: w,
}

View file

@ -64,7 +64,7 @@ func New(appConf *config.AppConfig, dexSrv *dex_server.Server, logger *logrus.Lo
}
controllers := map[string]http.Handler{
ui.StaticRoute: &ui.StaticController{},
ui.StaticRoute: middlewares.WithLogger(&ui.StaticController{}, logger),
"/": middlewares.WithLogger(ui.NewIndexController(logger, dexSrv), logger),
}

View file

@ -0,0 +1,11 @@
let connectorForm = document.getElementById("connectorform");
connectorForm.addEventListener("submit", (e) => {
e.preventDefault();
let nextURL = new URL(window.location.href);
let connectorName = document.getElementById("cname").value;
nextURL.searchParams.append("connector_id", connectorName)
window.location.href = nextURL;
});

View file

@ -1,4 +1,3 @@
</div>
</body>
</html>

View file

@ -8,11 +8,4 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body class="theme-body">
<div class="theme-navbar">
<div class="theme-navbar__logo-wrap">
</div>
</div>
<div class="dex-container">
<body>

View file

@ -1,15 +1,5 @@
<html>
{{ template "header.html" . }}
<head>
<h1>Polycule Connect home page</h1>
</head>
<body>
<form action="/login" method="post">
<div>
<input type="submit" value="login">
</div>
</form>
</body>
</html>
{{ template "footer.html" . }}

View file

@ -1,15 +1,13 @@
{{ template "header.html" . }}
<div class="theme-panel">
<h2 class="theme-heading">Log in to {{ issuer }} </h2>
<div>
{{ range $c := .Connectors }}
<div>
'{{ $c.ID }}'
<a href="{{ $c.URL }}">{{ $c.Name }} </a>
</div>
{{ end }}
</div>
<script src="/static/scripts/index.js" defer></script>
<div>
<form action="" id="connectorform">
<label for="cname">Connector name</label>
<input type="text" id="cname" name="connector_id">
<input type="submit">
</form>
</div>
{{ template "footer.html" . }}