// If creds are correct the user is logged in, otherwise he's redirected to the landing page func LoginHandler(response http.ResponseWriter, request *http.Request) { username := request.FormValue("username") password := request.FormValue("password") redirect_target := "/index" if username != "" && password != "" && account.Login(username, password, response) { redirect_target = "/config" } http.Redirect(response, request, redirect_target, http.StatusFound) }
// The user is registered and redirected to the landing page func SignupHandler(response http.ResponseWriter, request *http.Request) { username := request.FormValue("username") password := request.FormValue("password") redirect_target := "/index" if username != "" && password != "" { user := models.NewUser() user.Fields = make(map[string]string) user.Fields["username"] = username user.Fields["password"] = password if _, err := account.Register(user); err == nil { account.Login(username, password, response) redirect_target = "/config" } } http.Redirect(response, request, redirect_target, http.StatusFound) }