aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2018-12-28 20:12:34 -0500
committerThibaut Horel <thibaut.horel@gmail.com>2018-12-28 20:12:34 -0500
commit3345ce304365a577aa7d3f86e1b136b906610f1f (patch)
treee2301390e11c3b89ceaab8aae7551094178d94d6 /main.go
parent33389b0719c78de5fc5694a173f951b3666c183b (diff)
downloadid-3345ce304365a577aa7d3f86e1b136b906610f1f.tar.gz
First working commit
Diffstat (limited to 'main.go')
-rw-r--r--main.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/main.go b/main.go
index a8afe72..a9e3ab6 100644
--- a/main.go
+++ b/main.go
@@ -46,12 +46,15 @@ func (app *App) loginHandler(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodPost {
username := r.FormValue("username")
password := r.FormValue("password")
+ next := r.FormValue("next")
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 {
+ s := app.NewSession(u.Id)
+ c := http.Cookie{Name: "id", Value: s.Id, Domain: ".horel.test"}
+ http.SetCookie(w, &c)
http.Redirect(w, r, next, http.StatusSeeOther)
} else {
app.Template.ExecuteTemplate(w, "login.tmpl", struct {