From 6abeb1bed445da3a8a84cc4b22343265397e8907 Mon Sep 17 00:00:00 2001 From: soukainna Date: Mon, 31 Oct 2022 10:38:05 +0100 Subject: [PATCH 1/2] support code --- go.mod | 1 + go.sum | 2 ++ main.go | 5 +++++ renderer/renderer.go | 13 +++++++++++++ themes/default/config.yaml | 11 +++++++++++ utils/identification/oidc.go | 2 +- 6 files changed, 33 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 9ac3353..0788960 100644 --- a/go.mod +++ b/go.mod @@ -38,6 +38,7 @@ require ( github.com/coreos/go-semver v0.3.0 // indirect github.com/coreos/go-systemd/v22 v22.3.2 // indirect github.com/fsnotify/fsnotify v1.5.4 // indirect + github.com/go-mail/mail v2.3.1+incompatible // indirect github.com/go-playground/locales v0.14.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect diff --git a/go.sum b/go.sum index f27538e..013de35 100644 --- a/go.sum +++ b/go.sum @@ -110,6 +110,8 @@ github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vb github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= +github.com/go-mail/mail v2.3.1+incompatible h1:UzNOn0k5lpfVtO31cK3hn6I4VEVGhe3lX8AJBAxXExM= +github.com/go-mail/mail v2.3.1+incompatible/go.mod h1:VPWjmmNyRsWXQZHVHT3g0YbIINUkSmuKOiLIDkWbL6M= github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU= diff --git a/main.go b/main.go index 5f4d0fc..3f57525 100644 --- a/main.go +++ b/main.go @@ -95,6 +95,11 @@ func main() { application.HandleFunc("/group/settings", applicationHandler.GroupSettingsDisplay) application.HandleFunc("/group/settings/invite-member", applicationHandler.GroupSettingsInviteMember) + + /********************Code Supprt Emailing************************/ + application.HandleFunc("/support/", applicationHandler.SupportSend) + /****************************************************************/ + //TODO Subrouters with middlewares checking security for each module ? application.Use(idp.Middleware) application.Use(idp.GroupsMiddleware) diff --git a/renderer/renderer.go b/renderer/renderer.go index b1c06e3..f0d44b1 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -58,6 +58,7 @@ func (renderer *Renderer) Render(name string, w http.ResponseWriter, r *http.Req }, ) t = template.Must(t.ParseFiles(prefixed_files...)) + err := t.ExecuteTemplate(w, "main", state) if err != nil { fmt.Println(err) @@ -186,6 +187,18 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende }) } + /*************************** my code ******************************/ + if modules["support"] != nil && modules["support"].(bool) { + ls.MenuItems = append(ls.MenuItems, MenuItem{ + Title: "Support", + Link: "/app/support/", + Active: menuState == commentMenu, + Icon: "hero:outline/support", + }) + + } + /*************************** my code ******************************/ + if modules["directory"] != nil && modules["directory"].(bool) { ls.MenuItems = append(ls.MenuItems, MenuItem{ Title: "Répertoire solutions", diff --git a/themes/default/config.yaml b/themes/default/config.yaml index 5fc9839..a35f3be 100644 --- a/themes/default/config.yaml +++ b/themes/default/config.yaml @@ -32,6 +32,7 @@ views: files: - web/layouts/_partials/address_autocomplete.html - web/layouts/beneficiaries/update.html + vehicles: search: files: @@ -92,6 +93,10 @@ views: - web/layouts/journeys/_partials/journeys-carpool.html - web/layouts/journeys/_partials/journeys-public-transit.html - web/layouts/journeys/search.html + support: + search: + files: + - web/layouts/support/support.html administration: home: files: @@ -122,6 +127,7 @@ icons: svg: coopgo:parcoursmob/monogram: hero:outline/briefcase: + hero:outline/support: hero:outline/calendar: hero:outline/chevron-right: hero:outline/cog: @@ -164,4 +170,9 @@ emails: files: - emails/layout.html - emails/onboarding/existing-member.html + support_email: + subject: PARCOURMOB - Vous avez reçu un commentaire + files: + - emails/layout.html + - emails/onboarding/support_emailing.html \ No newline at end of file diff --git a/utils/identification/oidc.go b/utils/identification/oidc.go index 5e60c9a..2fc578f 100644 --- a/utils/identification/oidc.go +++ b/utils/identification/oidc.go @@ -51,7 +51,7 @@ func NewIdentificationProvider(cfg *viper.Viper, services *services.ServicesHand Endpoint: provider.Endpoint(), // "openid" is a required scope for OpenID Connect flows. - Scopes: []string{oidc.ScopeOpenID, "groups", "first_name", "last_name", "display_name"}, + Scopes: []string{oidc.ScopeOpenID, "groups", "first_name", "last_name", "display_name", "email"}, } var store = sessions.NewCookieStore([]byte(sessionsSecret)) -- 2.40.1 From d557ffe6b305c0f55c7552ca83bc49f7a3e06956 Mon Sep 17 00:00:00 2001 From: soukainna Date: Mon, 31 Oct 2022 10:39:43 +0100 Subject: [PATCH 2/2] support code emailing --- handlers/application/support.go | 45 +++++++++++++++++++ renderer/support.go | 19 ++++++++ .../emails/onboarding/support_emailing.html | 4 ++ .../default/web/layouts/support/support.html | 24 ++++++++++ 4 files changed, 92 insertions(+) create mode 100644 handlers/application/support.go create mode 100644 renderer/support.go create mode 100644 themes/default/emails/onboarding/support_emailing.html create mode 100644 themes/default/web/layouts/support/support.html diff --git a/handlers/application/support.go b/handlers/application/support.go new file mode 100644 index 0000000..e842b72 --- /dev/null +++ b/handlers/application/support.go @@ -0,0 +1,45 @@ +package application + +import ( + "fmt" + "net/http" + + "git.coopgo.io/coopgo-apps/parcoursmob/utils/identification" +) + +type Message struct { + Content string +} + +func (h *ApplicationHandler) SupportSend(w http.ResponseWriter, r *http.Request) { + + c := r.Context().Value(identification.ClaimsKey) + if c == nil { + fmt.Println("no current user claims") + w.WriteHeader(http.StatusInternalServerError) + return + } + current_user_claims := c.(map[string]any) + + comment := r.PostFormValue(("comment")) + + if r.Method == "POST" { + data := map[string]any{ + "key": comment, + "user": current_user_claims["email"], + } + + if err := h.emailing.Send("onboarding.Support_email", "support@parcoursmob.fr", data); err != nil { + fmt.Println(err) + fmt.Println("error") + } + fmt.Println("success") + http.Redirect(w, r, "/app/", http.StatusFound) + return + } + + fmt.Println("comment page!") + fmt.Println(comment) + fmt.Print(current_user_claims["email"]) + h.Renderer.SupportSend(w, r, comment, current_user_claims) +} diff --git a/renderer/support.go b/renderer/support.go new file mode 100644 index 0000000..e4dd151 --- /dev/null +++ b/renderer/support.go @@ -0,0 +1,19 @@ +package renderer + +import ( + "net/http" +) + +const commentMenu = "comment" +const commentsend = "sendComment" + +func (renderer *Renderer) SupportSend(w http.ResponseWriter, r *http.Request, comment any, admins any) { + + files := renderer.ThemeConfig.GetStringSlice("views.support.search.files") + state := NewState(r, renderer.ThemeConfig, commentMenu) + state.ViewState = map[string]any{ + "comment": comment, + "admins": admins, + } + renderer.Render("comment", w, r, files, state) +} diff --git a/themes/default/emails/onboarding/support_emailing.html b/themes/default/emails/onboarding/support_emailing.html new file mode 100644 index 0000000..40ea8c7 --- /dev/null +++ b/themes/default/emails/onboarding/support_emailing.html @@ -0,0 +1,4 @@ +{{define "content"}} +

Vous avez reçu un commentaire sur PARCOURSMOB de la part de {{.user}}

+

{{.key}}

+{{end}} \ No newline at end of file diff --git a/themes/default/web/layouts/support/support.html b/themes/default/web/layouts/support/support.html new file mode 100644 index 0000000..0eae295 --- /dev/null +++ b/themes/default/web/layouts/support/support.html @@ -0,0 +1,24 @@ +{{define "content"}} + +
+

Contact

+
+
+ +
+
+ + + +
+
+ +
+
+ +
+
+
+ {{end}} -- 2.40.1