diff --git a/main.go b/main.go index c4893c4..9a70ebd 100644 --- a/main.go +++ b/main.go @@ -33,12 +33,12 @@ func main() { router.HandleFunc("/minecraft/link", minecraftLink).Methods("POST") router.HandleFunc("/minecraft/link/success", minecraftLinkSuccessPage).Methods("GET") router.HandleFunc("/minecraft/link/error", minecraftLinkErrorPage).Methods("GET") - router.HandleFunc("/passwordreset", resetPageFront).Methods("GET") - router.HandleFunc("/passwordreset", resetLookup).Methods("POST") - router.HandleFunc("/passwordresetform", resetPageBack).Methods("GET") - router.HandleFunc("/passwordresetform", reset).Methods("POST") - router.HandleFunc("/resetsuccess", resetSuccessPage).Methods("GET") - router.HandleFunc("/reseterror", resetErrorPage).Methods("GET") + router.HandleFunc("/reset", resetPageFront).Methods("GET") + router.HandleFunc("/reset", resetLookup).Methods("POST") + router.HandleFunc("/reset/form", resetPageBack).Methods("GET") + router.HandleFunc("/reset/form", reset).Methods("POST") + router.HandleFunc("/reset/success", resetSuccessPage).Methods("GET") + router.HandleFunc("/reset/error", resetErrorPage).Methods("GET") log.Printf("Registering templates from %v/\n", Conf.TplPath) tpl = template.Must(template.ParseGlob(Conf.TplPath + "/*")) log.Println("Performing LDAP checks") diff --git a/reset.go b/reset.go index 4e7174c..21f8674 100644 --- a/reset.go +++ b/reset.go @@ -10,12 +10,12 @@ import ( ) func resetLookup(res http.ResponseWriter, req *http.Request) { - log.Println("POST /passwordreset") + log.Println("POST /reset") email := req.FormValue("email") uname, err := findLDAPAccountByEmail(email) if err != nil { log.Printf("Error while looking up account to email password reset to: %v\n. Account may not exist", err) - http.Redirect(res, req, "/passwordresetform", 303) + http.Redirect(res, req, "/reset/form", 303) } if uname == "" { log.Printf("Error while looking up account to email password reset to: %v\n", err) @@ -38,7 +38,7 @@ func resetLookup(res http.ResponseWriter, req *http.Request) { } }()*/ log.Println("Redirecting to next part of password reset") - http.Redirect(res, req, "/passwordresetform", 303) + http.Redirect(res, req, "/reset/form", 303) } func reset(res http.ResponseWriter, req *http.Request) { token := req.FormValue("token") @@ -47,7 +47,7 @@ func reset(res http.ResponseWriter, req *http.Request) { user, err := validateToken(token) if err != nil { log.Printf("Error validing password reset token: %v\n", err) - http.Redirect(res, req, "/reseterror", 302) + http.Redirect(res, req, "/reset/error", 302) return } if user == "" { @@ -59,11 +59,11 @@ func reset(res http.ResponseWriter, req *http.Request) { err = resetLDAPAccountPassword(user, newPass) if err == nil { log.Printf("reset password for %v\n", user) - http.Redirect(res, req, "/resetsuccess", 302) + http.Redirect(res, req, "/reset/success", 302) return } else { log.Printf("failed to reset password for %v:%v\n", user, err) - http.Redirect(res, req, "/reseterror", 302) + http.Redirect(res, req, "/reset/error", 302) return } diff --git a/session.go b/session.go index fd2a608..8d9db32 100644 --- a/session.go +++ b/session.go @@ -50,7 +50,8 @@ func signup(res http.ResponseWriter, req *http.Request) { _, err := validateToken(secret) if err != nil { log.Printf("Bad secret entered: %v\n", err) - res.Write([]byte("Get a load of this guy, not knowing the secret code")) + genericErrorPage(res, "User Creation Failure", "Unregistered", false, "Invalid Secret Token.", "to create account") + return } } @@ -58,10 +59,10 @@ func signup(res http.ResponseWriter, req *http.Request) { log.Printf("Attempting to create account for %v", username) err := createLDAPAccount(username, password, email) if err == nil { - res.Write([]byte("User created!")) + genericSuccessPage(res, "User Created", "Unregistered", false, "User created") return } else { - res.Write([]byte("Failure to create account")) + genericErrorPage(res, "User Creation Failure", "Unregistered", false, err.Error(), "to create account") return } } @@ -73,7 +74,7 @@ func login(res http.ResponseWriter, req *http.Request) { err := loginLDAPAccount(username, password) if err != nil { log.Printf("Error logging in user %v: %v\n", username, err) - res.Write([]byte("Error logging in. Incorrect password?")) + genericErrorPage(res, "Login Failure", "Unregistered", false, err.Error(), "to login") return } else { setSession(username, res) diff --git a/templates/error.html b/templates/error.html index a3be7e4..ae78847 100644 --- a/templates/error.html +++ b/templates/error.html @@ -1,5 +1,8 @@ -{{ define "error" }} +{{ define "generic_error" }} {{ template "header" .}} -An error occured. Please let the admin know. +
Unable to {{.Action}} due to the following error:
+{{.Error}}
+Please try again or let the admin know.
+ {{template "footer" .}} {{ end }} diff --git a/templates/index.html b/templates/index.html index 8b295c9..45c88c6 100644 --- a/templates/index.html +++ b/templates/index.html @@ -6,7 +6,7 @@ {{else}} - + {{end}} {{template "footer" .}} {{ end }} diff --git a/templates/minecraft_error.html b/templates/minecraft_error.html deleted file mode 100644 index bb47697..0000000 --- a/templates/minecraft_error.html +++ /dev/null @@ -1,8 +0,0 @@ -{{ define "minecraft_error" }} -{{ template "header" .}} -Unable to link your Minecraft account due to the following error:
-{{.Error}}
-Please try again or let the admin know.
- -{{template "footer" .}} -{{ end }} diff --git a/templates/minecraft_success.html b/templates/minecraft_success.html deleted file mode 100644 index d774db1..0000000 --- a/templates/minecraft_success.html +++ /dev/null @@ -1,6 +0,0 @@ -{{ define "minecraft_success" }} -{{ template "header" .}} -Your Minecraft account has been linked
- -{{template "footer" .}} -{{ end }} diff --git a/templates/reset_error.html b/templates/reset_error.html deleted file mode 100644 index 5065baf..0000000 --- a/templates/reset_error.html +++ /dev/null @@ -1,8 +0,0 @@ -{{ define "reset_error" }} -{{ template "header" .}} -Unable to reset your password due to the following error:
-{{.Error}}
-Please try again or let the admin know.
- -{{template "footer" .}} -{{ end }} diff --git a/templates/reset_password_back.html b/templates/reset_password_back.html index 3bffc9d..a700039 100644 --- a/templates/reset_password_back.html +++ b/templates/reset_password_back.html @@ -3,7 +3,7 @@You should receive a Password Recovery token momentarily in your email inbox
Please enter it, and your new password, into the form below to reset your password
-