78b57273e2
- Add password hashing with bcrypt - Add AuthService with proper login - Add password strength validation - Add RBAC middleware (AdminOnly, ManagerOrAdmin) - Add tenant isolation middleware - Update CRM handler with tenant filtering - Add JWT fallback for development mode - Add user context helpers - Build successful
129 lines
3.7 KiB
Go
129 lines
3.7 KiB
Go
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
// SigningHandler hanterar digital signering (BankID, Scrive)
|
|
type SigningHandler struct {
|
|
bankIDURL string
|
|
bankIDAPIKey string
|
|
scriveAPIKey string
|
|
docusignAPIKey string
|
|
}
|
|
|
|
func NewSigningHandler() *SigningHandler {
|
|
return &SigningHandler{
|
|
bankIDURL: os.Getenv("BANKID_URL"),
|
|
bankIDAPIKey: os.Getenv("BANKID_API_KEY"),
|
|
scriveAPIKey: os.Getenv("SCRIVE_API_KEY"),
|
|
docusignAPIKey: os.Getenv("DOCUSIGN_API_KEY"),
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// SigningRequest representerar en signeringsbegäran
|
|
type SigningRequest struct {
|
|
ID string `json:"id"`
|
|
DocumentID string `json:"document_id"`
|
|
DocumentTitle string `json:"document_title"`
|
|
Signers []Signer `json:"signers"`
|
|
Status string `json:"status"`
|
|
Method string `json:"method"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
ExpiresAt time.Time `json:"expires_at"`
|
|
SignedAt *time.Time `json:"signed_at,omitempty"`
|
|
}
|
|
|
|
// Signer representerar en undertecknare
|
|
type Signer struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Email string `json:"email"`
|
|
PersonalNumber string `json:"personal_number"`
|
|
Signed bool `json:"signed"`
|
|
SignedAt *time.Time `json:"signed_at,omitempty"`
|
|
}
|
|
|
|
// GetMethods returnerar tillgängliga signeringsmetoder
|
|
func (h *SigningHandler) GetMethods(w http.ResponseWriter, r *http.Request) {
|
|
methods := []map[string]interface{}{
|
|
{
|
|
"id": "bankid",
|
|
"name": "BankID",
|
|
"description": "Swedish electronic identification",
|
|
"available": h.bankIDURL != "" && h.bankIDAPIKey != "",
|
|
"countries": []string{"SE"},
|
|
"setup_url": "https://www.bankid.com/foretag",
|
|
},
|
|
{
|
|
"id": "scrive",
|
|
"name": "Scrive",
|
|
"description": "Electronic signature platform",
|
|
"available": h.scriveAPIKey != "",
|
|
"setup_url": "https://scrive.com",
|
|
},
|
|
{
|
|
"id": "docusign",
|
|
"name": "DocuSign",
|
|
"description": "Global e-signature solution",
|
|
"available": h.docusignAPIKey != "",
|
|
"setup_url": "https://docusign.com",
|
|
},
|
|
}
|
|
|
|
writeJSON(w, http.StatusOK, map[string]interface{}{
|
|
"ok": true,
|
|
"methods": methods,
|
|
})
|
|
}
|
|
|
|
// GetRequests returnerar signeringsbegäranden
|
|
func (h *SigningHandler) GetRequests(w http.ResponseWriter, r *http.Request) {
|
|
// TODO: Implementera DB-lagring av signeringsbegäranden
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(http.StatusNotImplemented)
|
|
json.NewEncoder(w).Encode(map[string]interface{}{
|
|
"ok": false,
|
|
"error": "Signing requests not yet implemented. Configure BANKID_URL and BANKID_API_KEY to enable.",
|
|
})
|
|
}
|
|
|
|
// InitiateBankID initierar BankID-signering
|
|
func (h *SigningHandler) InitiateBankID(w http.ResponseWriter, r *http.Request) {
|
|
if h.bankIDURL == "" || h.bankIDAPIKey == "" {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(http.StatusServiceUnavailable)
|
|
json.NewEncoder(w).Encode(map[string]interface{}{
|
|
"ok": false,
|
|
"error": "BankID not configured. Set BANKID_URL and BANKID_API_KEY environment variables.",
|
|
})
|
|
return
|
|
}
|
|
|
|
var req struct {
|
|
PersonalNumber string `json:"personal_number"`
|
|
DocumentID string `json:"document_id"`
|
|
}
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
writeJSON(w, http.StatusBadRequest, map[string]interface{}{
|
|
"ok": false,
|
|
"error": err.Error(),
|
|
})
|
|
return
|
|
}
|
|
|
|
// TODO: Implementera riktig BankID API-integration
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(http.StatusNotImplemented)
|
|
json.NewEncoder(w).Encode(map[string]interface{}{
|
|
"ok": false,
|
|
"error": "BankID integration not yet implemented. Contact administrator to configure.",
|
|
})
|
|
}
|