2022-10-31 09:39:43 +00:00
|
|
|
package application
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
2024-11-19 14:21:31 +00:00
|
|
|
"git.coopgo.io/coopgo-platform/emailing"
|
2024-11-11 18:50:17 +00:00
|
|
|
"github.com/rs/zerolog/log"
|
2022-10-31 09:39:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Message struct {
|
|
|
|
Content string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *ApplicationHandler) SupportSend(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
c := r.Context().Value(identification.ClaimsKey)
|
|
|
|
if c == nil {
|
2024-11-11 18:50:17 +00:00
|
|
|
log.Error().Msg("no current user claims")
|
2022-10-31 09:39:43 +00:00
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
current_user_claims := c.(map[string]any)
|
|
|
|
|
|
|
|
comment := r.PostFormValue(("comment"))
|
2024-11-19 14:21:31 +00:00
|
|
|
|
2022-10-31 09:39:43 +00:00
|
|
|
|
|
|
|
if r.Method == "POST" {
|
2024-11-19 14:21:31 +00:00
|
|
|
user_email := current_user_claims["email"].(string)
|
|
|
|
|
2022-10-31 09:39:43 +00:00
|
|
|
data := map[string]any{
|
|
|
|
"key": comment,
|
2024-11-19 14:21:31 +00:00
|
|
|
"user": user_email,
|
2022-10-31 09:39:43 +00:00
|
|
|
}
|
|
|
|
|
2024-11-19 14:21:31 +00:00
|
|
|
log.Debug().Str("user_email", user_email).Msg("Sending message")
|
|
|
|
|
|
|
|
if err := h.emailing.Send("support.request", "support@parcoursmob.fr", data, emailing.WithReplyTo(user_email), emailing.WithTLSOpportunistic()); err != nil {
|
|
|
|
log.Error().Err(err).Msg("error sending email")
|
2022-11-01 10:54:59 +00:00
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
2024-11-19 14:21:31 +00:00
|
|
|
return
|
2022-10-31 09:39:43 +00:00
|
|
|
}
|
|
|
|
http.Redirect(w, r, "/app/", http.StatusFound)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
h.Renderer.SupportSend(w, r, comment, current_user_claims)
|
|
|
|
}
|