Implement Totp authentication

This commit is contained in:
2024-06-19 16:23:28 +07:00
parent c3948bb1c1
commit cdc365e89b
9 changed files with 210 additions and 10 deletions

View File

@ -16,6 +16,7 @@ import (
uploadHandler "github.com/fossyy/filekeeper/handler/upload"
"github.com/fossyy/filekeeper/handler/upload/initialisation"
userHandler "github.com/fossyy/filekeeper/handler/user"
userHandlerTotpSetup "github.com/fossyy/filekeeper/handler/user/totp"
"github.com/fossyy/filekeeper/middleware"
"net/http"
)
@ -129,6 +130,17 @@ func SetupRoutes() *http.ServeMux {
}
})
handler.HandleFunc("/user/totp/setup", func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
middleware.Auth(userHandlerTotpSetup.GET, w, r)
case http.MethodPost:
middleware.Auth(userHandlerTotpSetup.POST, w, r)
default:
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
}
})
// Upload router
uploadRouter := http.NewServeMux()
handler.Handle("/upload/", http.StripPrefix("/upload", uploadRouter))