Remove all fmr.Println and add zerolog logging
Some checks failed
Build and Push Docker Image / build_and_push (push) Failing after 1m52s

This commit is contained in:
2024-11-11 19:50:17 +01:00
parent a51f077358
commit a8acc9950a
30 changed files with 333 additions and 325 deletions

View File

@@ -2,10 +2,10 @@ package auth
import (
"context"
"fmt"
"net/http"
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
"github.com/rs/zerolog/log"
)
func (h *AuthHandler) Groups(w http.ResponseWriter, r *http.Request) {
@@ -42,7 +42,7 @@ func (h *AuthHandler) Groups(w http.ResponseWriter, r *http.Request) {
err = idtoken.Claims(&claims)
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
}
g := claims["groups"]
@@ -65,7 +65,7 @@ func (h *AuthHandler) Groups(w http.ResponseWriter, r *http.Request) {
resp, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), request)
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
w.WriteHeader(http.StatusInternalServerError)
return
}

View File

@@ -4,12 +4,12 @@ import (
"context"
"crypto/rand"
"encoding/base64"
"fmt"
"io"
"net/http"
"time"
"git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
"github.com/rs/zerolog/log"
)
func (h *AuthHandler) LostPasswordInit(w http.ResponseWriter, r *http.Request) {
@@ -22,14 +22,14 @@ func (h *AuthHandler) LostPasswordInit(w http.ResponseWriter, r *http.Request) {
Namespace: "parcoursmob",
})
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
http.Redirect(w, r, "/app/", http.StatusFound)
return
}
b := make([]byte, 16)
if _, err := io.ReadFull(rand.Reader, b); err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
w.WriteHeader(http.StatusInternalServerError)
return
}
@@ -44,7 +44,7 @@ func (h *AuthHandler) LostPasswordInit(w http.ResponseWriter, r *http.Request) {
h.cache.PutWithTTL("retrieve-password/"+key, passwordretrieval, 72*time.Hour)
if err := h.emailing.Send("auth.retrieve_password", email, passwordretrieval); err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
w.WriteHeader(http.StatusInternalServerError)
return
}
@@ -62,7 +62,7 @@ func (h *AuthHandler) LostPasswordRecover(w http.ResponseWriter, r *http.Request
key := r.FormValue("key")
recover, err := h.cache.Get("retrieve-password/" + key)
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
h.Renderer.LostPasswordRecoverKO(w, r, key)
return
}
@@ -81,13 +81,13 @@ func (h *AuthHandler) LostPasswordRecover(w http.ResponseWriter, r *http.Request
})
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
w.WriteHeader(http.StatusInternalServerError)
}
err = h.cache.Delete("retrieve-password/" + key)
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
}
http.Redirect(w, r, "/app/", http.StatusFound)

View File

@@ -7,6 +7,7 @@ import (
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
ma "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
"github.com/rs/zerolog/log"
)
func (h *AuthHandler) Onboarding(w http.ResponseWriter, r *http.Request) {
@@ -15,7 +16,7 @@ func (h *AuthHandler) Onboarding(w http.ResponseWriter, r *http.Request) {
key := r.FormValue("key")
onboarding, err := h.cache.Get("onboarding/" + key)
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
h.Renderer.AuthOnboardingKO(w, r, key)
return
}
@@ -24,7 +25,7 @@ func (h *AuthHandler) Onboarding(w http.ResponseWriter, r *http.Request) {
if r.Method == "POST" {
if r.FormValue("password") == "" {
fmt.Println("password is empty !")
log.Error().Msg("Password is empty")
w.WriteHeader(http.StatusInternalServerError)
return
}
@@ -58,7 +59,7 @@ func (h *AuthHandler) Onboarding(w http.ResponseWriter, r *http.Request) {
acc, err := mobilityaccounts.AccountFromStorageType(account)
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
w.WriteHeader(http.StatusInternalServerError)
return
}
@@ -70,14 +71,14 @@ func (h *AuthHandler) Onboarding(w http.ResponseWriter, r *http.Request) {
_, err = h.services.GRPC.MobilityAccounts.Register(context.TODO(), request)
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
w.WriteHeader(http.StatusInternalServerError)
return
}
err = h.cache.Delete("onboarding/" + key)
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
}
http.Redirect(w, r, "/app/", http.StatusFound)