lishwist/auth/login_get.go

29 lines
685 B
Go

package auth
import (
"lishwist/templates"
"log"
"net/http"
)
type LoginGetProps struct {
SuccessfulRegistration bool
}
func (auth *AuthMiddleware) Login(w http.ResponseWriter, r *http.Request) {
session, _ := auth.Store.Get(r, "lishwist_user")
successfulReg, ok := session.Values["successful_registration"].(bool)
if ok {
delete(session.Values, "successful_registration")
if err := session.Save(r, w); err != nil {
log.Println("Couldn't save session:", err)
http.Error(w, "Something went wrong. Error code: Zuko", http.StatusInternalServerError)
return
}
}
templates.Execute(w, "login.gotmpl", LoginGetProps{
SuccessfulRegistration: successfulReg,
})
}