This commit is contained in:
cangui 2025-07-15 17:30:41 +02:00
parent c0694cbc56
commit c3b14bcf7e

View File

@ -8,8 +8,8 @@ import (
"app/shelfly/internal/users"
"app/shelfly/renders"
"encoding/base64"
"encoding/json"
"fmt"
"golang.org/x/crypto/bcrypt"
"log"
"net/http"
"os"
@ -17,10 +17,22 @@ import (
"strings"
"time"
"golang.org/x/crypto/bcrypt"
"github.com/gorilla/mux"
"golang.org/x/net/webdav"
"gorm.io/gorm"
)
func PingHandler() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]string{
"message": "pong",
"service": "shelfy",
"version": "1.0.0", // optionnel
})
}
}
func checkUserCredentials(db *gorm.DB, email string, password string) bool {
var user models.User
@ -68,6 +80,7 @@ func RoutesPublic(r *mux.Router, bd *gorm.DB) {
http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
// Page de login
r.HandleFunc("/api/ping", PingHandler()).Methods("GET")
r.HandleFunc("/login", renders.Login)
r.HandleFunc("/api/login", login.LoginHandler(bd)).Methods("POST")
r.HandleFunc("/apiV2/login", login.LoginHandlerApi(bd)).Methods("POST")