Handle unavailability of recaptcha key and session id

This commit is contained in:
Parminder Singh 2018-03-10 14:20:44 +05:30
parent 55552050c6
commit a3ff68c2b1

View file

@ -104,12 +104,18 @@ func AuthFallback(
w http.ResponseWriter, req *http.Request, authType string, w http.ResponseWriter, req *http.Request, authType string,
cfg config.Dendrite, cfg config.Dendrite,
) *util.JSONResponse { ) *util.JSONResponse {
sessionID := req.Form.Get("session") sessionID := req.URL.Query().Get("session")
if sessionID == "" {
w.Write([]byte("Session ID not provided"))
return nil
}
ServeRecaptcha := func() { ServeRecaptcha := func() {
data := map[string]string{ data := map[string]string{
"MyUrl": req.URL.String(), "MyUrl": req.URL.String(),
"Session": sessionID, "Session": sessionID,
"SiteKey": cfg.Matrix.RecaptchaPublicKey, "SiteKey": cfg.Matrix.RecaptchaPrivateKey,
} }
ServeTemplate(w, RecaptchaTemplate, data) ServeTemplate(w, RecaptchaTemplate, data)
} }
@ -122,6 +128,11 @@ func AuthFallback(
if req.Method == "GET" { if req.Method == "GET" {
// Handle Recaptcha // Handle Recaptcha
if authType == authtypes.LoginTypeRecaptcha { if authType == authtypes.LoginTypeRecaptcha {
if cfg.Matrix.RecaptchaPrivateKey == "" {
w.Write([]byte("Homeserver doesn't have a recaptcha public key"))
return nil
}
ServeRecaptcha() ServeRecaptcha()
return nil return nil
} }