aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2018-12-28 05:57:39 -0500
committerThibaut Horel <thibaut.horel@gmail.com>2018-12-28 05:57:39 -0500
commit2c3ab103355b616815756f1f3ba74b147a02a857 (patch)
treec3833d02d8e2e47e93734c4b894d4f1016f93cb4 /main.go
parent08a5afd311e918f89d0d6ef955a3b1dbbe38713a (diff)
downloadid-2c3ab103355b616815756f1f3ba74b147a02a857.tar.gz
Add redirect logic to login flow
Diffstat (limited to 'main.go')
-rw-r--r--main.go31
1 files changed, 16 insertions, 15 deletions
diff --git a/main.go b/main.go
index b459324..998791a 100644
--- a/main.go
+++ b/main.go
@@ -43,25 +43,26 @@ func (app *App) validateHandler(w http.ResponseWriter, r *http.Request) {
func (app *App) loginHandler(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodPost {
- if err := r.ParseForm(); err != nil {
- panic(err)
+ username := r.FormValue("username")
+ password := r.FormValue("password")
+ hash := md5.Sum([]byte(password))
+ dst := make([]byte, hex.EncodedLen(md5.Size))
+ hex.Encode(dst, hash[:])
+ u, ok := app.GetUser(username)
+ next := r.FormValue("next")
+ if ok && subtle.ConstantTimeCompare(u.Password, dst) == 1 {
+ http.Redirect(w, r, next, http.StatusSeeOther)
} else {
- username := r.Form.Get("username")
- password := r.Form.Get("password")
- hash := md5.Sum([]byte(password))
- dst := make([]byte, hex.EncodedLen(md5.Size))
- hex.Encode(dst, hash[:])
- u, ok := app.GetUser(username)
- if ok && subtle.ConstantTimeCompare(u.Password, dst) == 1 {
-
- } else {
-
- }
+ app.Template.ExecuteTemplate(w, "login.tmpl", struct {
+ Next string
+ }{next})
}
} else if r.Method == http.MethodGet {
- app.Template.ExecuteTemplate(w, "login.tmpl", nil)
+ next := r.FormValue("next")
+ app.Template.ExecuteTemplate(w, "login.tmpl", struct {
+ Next string
+ }{next})
}
-
}
func main() {