github.com/benoitkugler/goacve@v0.0.0-20201217100549-151ce6e55dc8/server/shared/redirects.go (about) 1 package shared 2 3 import ( 4 "fmt" 5 6 "github.com/avct/uasurfer" 7 "github.com/labstack/echo" 8 ) 9 10 func RedirectIE11(next echo.HandlerFunc) echo.HandlerFunc { 11 return func(c echo.Context) error { 12 ua := uasurfer.Parse(c.Request().UserAgent()) 13 isIE := ua.Browser.Name == uasurfer.BrowserIE && ua.Browser.Version.Major < 11 14 if isIE { 15 return RedirectError(c, fmt.Errorf(`Ce portail ne supporte pas votre version (%d) d'Internet Explorer. 16 <br/> Veuillez nous excuser pour le désagrement occasioné. <br/><br/> 17 Vous pouvez mettre à jour votre navigateur vers la version <b>11</b>. <br/> 18 Sinon, plusieurs très bons navigateurs libres et gratuits sont disponibles (Mozilla Firefox, Google Chrome, ...). 19 `, ua.Browser.Version.Major)) 20 } 21 return next(c) 22 } 23 } 24 25 type NotificationError struct { 26 Content string `json:"content"` 27 } 28 29 type NotificationSuccess struct { 30 Title string `json:"title"` 31 SubTitle string `json:"sub_title"` 32 Content string `json:"content"` 33 } 34 35 func sertNotification(c echo.Context, notif NotificationContent) error { 36 return HtmlWithPayload(c, "server/static/bv/notification.html", notif) 37 } 38 39 func RedirectError(c echo.Context, err error) error { 40 notif := NotificationContent{ 41 IsError: true, 42 Error: NotificationError{ 43 Content: err.Error(), 44 }, 45 } 46 return sertNotification(c, notif) 47 } 48 49 func RedirectSuccess(c echo.Context, pageTitle, title, content string) error { 50 notif := NotificationContent{ 51 IsError: false, 52 Success: NotificationSuccess{ 53 Title: pageTitle, 54 SubTitle: title, 55 Content: content, 56 }, 57 } 58 return sertNotification(c, notif) 59 }