Keine Beschreibung

logon.go 869B

    package handlers import ( "log" "net/http" "code.revolvingcow.com/revolvingcow/loop/account" "code.revolvingcow.com/revolvingcow/loop/security" ) // LogonHandler is responsible for the initial log on procedures. func LogonHandler(w http.ResponseWriter, r *http.Request) { log.Println("Logon handler") login := r.FormValue("login") passphrase := r.FormValue("passphrase") a := account.Account{ Username: login, Passphrase: security.GeneratePassphrase(login, passphrase), } err := a.Create() if err != nil { if err.Error() != "Account already exists" { http.Error(w, err.Error(), http.StatusInternalServerError) return } } session, _ := store.Get(r, "session-account") session.Values["username"] = login session.Values["passphrase"] = passphrase store.Save(r, w, session) http.Redirect(w, r, "/"+a.Username, http.StatusSeeOther) }