Set correct login flow
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
20fde2335e
commit
1e8b9ef161
9 changed files with 34 additions and 43 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
||||
|
|
11
polyculeconnect/static/scripts/index.js
Normal file
11
polyculeconnect/static/scripts/index.js
Normal 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;
|
||||
});
|
|
@ -1,4 +1,3 @@
|
|||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -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>
|
|
@ -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" . }}
|
|
@ -1,15 +1,13 @@
|
|||
{{ template "header.html" . }}
|
||||
|
||||
<div class="theme-panel">
|
||||
<h2 class="theme-heading">Log in to {{ issuer }} </h2>
|
||||
<script src="/static/scripts/index.js" defer></script>
|
||||
|
||||
<div>
|
||||
{{ range $c := .Connectors }}
|
||||
<div>
|
||||
'{{ $c.ID }}'
|
||||
<a href="{{ $c.URL }}">{{ $c.Name }} </a>
|
||||
</div>
|
||||
{{ end }}
|
||||
</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" . }}
|
Loading…
Reference in a new issue