rentease/internal/server/handle_auth.go
2024-05-10 12:45:08 +02:00

32 lines
766 B
Go

package server
import (
"fmt"
"net/http"
"github.com/labstack/echo/v4"
)
func handleLoginPage() echo.HandlerFunc {
return func(c echo.Context) error {
return c.String(http.StatusOK, "ok")
}
}
func handleLogin() echo.HandlerFunc {
return func(c echo.Context) error {
email := c.FormValue("email")
_ = c.FormValue("password")
//user, err := s.us.SignIn(email, pwd)
user := struct{ Id int }{Id: 1}
var err error = nil
if err != nil {
return c.Redirect(http.StatusSeeOther, fmt.Sprintf("%s?err=invalid+credentials", "/login"))
}
if err = writeCookie(c, user.Id, email); err != nil {
return c.Redirect(http.StatusSeeOther, fmt.Sprintf("%s?err=invalid+credentials", "/login"))
}
return c.Redirect(http.StatusFound, "/bookings")
}
}