package server import ( "github.com/ospokemon/ospokemon/save" "net/http" ) var SignupHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Method != "POST" { w.WriteHeader(404) return } account := save.MakeAccount(r.FormValue("username")) account.Password = hashpassword(r.FormValue("password")) if err := account.Insert(); err != nil { w.Write([]byte(err.Error())) return } http.Redirect(w, r, "/login/", http.StatusMovedPermanently) })
username := r.FormValue("username") password := hashpassword(r.FormValue("password")) if account := save.Accounts[username]; account != nil { if account.Password == password { session := Sessions[account.SessionId] session.WriteSessionId(w) http.Redirect(w, r, "/play/", http.StatusMovedPermanently) return } http.Redirect(w, r, "/login/?password", http.StatusMovedPermanently) return } account := save.MakeAccount(username) if err := account.Query(); err != nil { logrus.WithFields(logrus.Fields{ "Username": username, }).Error("server.Login: "******"/login/?account", http.StatusMovedPermanently) return } if account.Password == password { session := NewSession(username) account.SessionId = session.SessionId session.WriteSessionId(w) save.Accounts[username] = account