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/internal/users"
"app/shelfly/renders" "app/shelfly/renders"
"encoding/base64" "encoding/base64"
"encoding/json"
"fmt" "fmt"
"golang.org/x/crypto/bcrypt"
"log" "log"
"net/http" "net/http"
"os" "os"
@ -17,10 +17,22 @@ import (
"strings" "strings"
"time" "time"
"golang.org/x/crypto/bcrypt"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"golang.org/x/net/webdav" "golang.org/x/net/webdav"
"gorm.io/gorm" "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 { func checkUserCredentials(db *gorm.DB, email string, password string) bool {
var user models.User var user models.User
@ -68,6 +80,7 @@ func RoutesPublic(r *mux.Router, bd *gorm.DB) {
http.StripPrefix("/static/", http.FileServer(http.Dir("./static")))) http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
// Page de login // Page de login
r.HandleFunc("/api/ping", PingHandler()).Methods("GET")
r.HandleFunc("/login", renders.Login) r.HandleFunc("/login", renders.Login)
r.HandleFunc("/api/login", login.LoginHandler(bd)).Methods("POST") r.HandleFunc("/api/login", login.LoginHandler(bd)).Methods("POST")
r.HandleFunc("/apiV2/login", login.LoginHandlerApi(bd)).Methods("POST") r.HandleFunc("/apiV2/login", login.LoginHandlerApi(bd)).Methods("POST")