mirror of
https://github.com/1f349/tulip.git
synced 2024-12-22 16:24:10 +00:00
Autofill login name sent from external service
This commit is contained in:
parent
b33454627a
commit
a8afddb02b
@ -18,11 +18,11 @@
|
||||
<input type="hidden" name="redirect" value="{{.Redirect}}"/>
|
||||
<div>
|
||||
<label for="field_username">User Name:</label>
|
||||
<input type="text" name="username" id="field_username" required/>
|
||||
<input type="text" name="username" id="field_username" {{if gt (len .LoginName) 0}} value="{{.LoginName}}" {{else}} autofocus {{end}} required/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="field_password">Password:</label>
|
||||
<input type="password" name="password" id="field_password" required/>
|
||||
<input type="password" name="password" id="field_password" {{if gt (len .LoginName) 0}} autofocus {{end}} required/>
|
||||
</div>
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
|
@ -16,18 +16,37 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// getUserLoginName finds the `login_name` query parameter within the `/authorize` redirect url
|
||||
func getUserLoginName(req *http.Request) string {
|
||||
q := req.URL.Query()
|
||||
if !q.Has("redirect") {
|
||||
return ""
|
||||
}
|
||||
originUrl, err := url.ParseRequestURI(q.Get("redirect"))
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
if originUrl.Path != "/authorize" {
|
||||
return ""
|
||||
}
|
||||
return originUrl.Query().Get("login_name")
|
||||
}
|
||||
|
||||
func (h *HttpServer) LoginGet(rw http.ResponseWriter, req *http.Request, _ httprouter.Params, auth UserAuth) {
|
||||
if !auth.IsGuest() {
|
||||
h.SafeRedirect(rw, req)
|
||||
return
|
||||
}
|
||||
|
||||
loginName := getUserLoginName(req)
|
||||
|
||||
rw.Header().Set("Content-Type", "text/html")
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
pages.RenderPageTemplate(rw, "login", map[string]any{
|
||||
"ServiceName": h.serviceName,
|
||||
"Redirect": req.URL.Query().Get("redirect"),
|
||||
"Mismatch": req.URL.Query().Get("mismatch"),
|
||||
"LoginName": loginName,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ func NewHttpServer(listen, domain, otpIssuer, serviceName string, mailer mail.Ma
|
||||
if !scope2.ScopesExist(a) {
|
||||
return "", errInvalidScope
|
||||
}
|
||||
return "openid", nil
|
||||
return a, nil
|
||||
})
|
||||
|
||||
r.GET("/.well-known/openid-configuration", func(rw http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
||||
|
Loading…
Reference in New Issue
Block a user