Login function now authenticates and redirects

This commit is contained in:
Maximilian 2022-11-01 16:14:49 -05:00
parent e6b08266ac
commit 601b3d2cb0

View File

@ -18,11 +18,19 @@ func (postController *PostController) Login(w http.ResponseWriter, r *http.Reque
password := r.FormValue("password") password := r.FormValue("password")
if username == "" || password == "" { if username == "" || password == "" {
log.Println("Tried to create user with empty username or password") log.Println("Tried to login user with empty username or password")
http.Redirect(w, r, "/register", http.StatusFound) http.Redirect(w, r, "/login", http.StatusFound)
} }
_, err := models.AuthenticateUser(postController.App, w, username, password)
if err != nil {
log.Println("Error authenticating user")
log.Println(err)
http.Redirect(w, r, "/login", http.StatusFound) http.Redirect(w, r, "/login", http.StatusFound)
return
}
http.Redirect(w, r, "/", http.StatusFound)
} }
func (postController *PostController) Register(w http.ResponseWriter, r *http.Request) { func (postController *PostController) Register(w http.ResponseWriter, r *http.Request) {