-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroutes.go
96 lines (83 loc) · 2.53 KB
/
routes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"net/http"
"weber-insight/controllers"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin"
)
func loginMiddleware(ctrl *controllers.Controller) gin.HandlerFunc {
return func(c *gin.Context) {
if c.Request.URL.String() != "/#" {
if !ctrl.CheckLoggedIn(c) {
c.Redirect(http.StatusTemporaryRedirect, "/#")
}
}
}
}
func setupRouter(ctrl *controllers.Controller) *gin.Engine {
r := gin.Default()
store := cookie.NewStore([]byte("secret"))
r.Use(sessions.Sessions("mysession", store))
r.Static("/assets", "./views/assets")
r.Static("/node_modules", "./views/node_modules")
r.LoadHTMLGlob("views/pages/*")
r.Use(loginMiddleware(ctrl))
// Authentication
r.POST("/#", ctrl.Login)
r.GET("/logout", ctrl.Logout)
// Services
r.GET("/services", ctrl.GetServices)
r.GET("/delete-service/:id", ctrl.DeleteService)
r.GET("/update-service/:id", ctrl.UpdateServiceView)
r.POST("/update-service", ctrl.UpdateService)
r.GET("/create-service", ctrl.CreateServiceView)
r.POST("/create-service", ctrl.CreateService)
// User List
r.GET("/user-list", ctrl.GetVisitors)
r.GET("/aml-pep-user-list", ctrl.GetAMLPEPVisitors)
r.GET("/user-list-export", ctrl.ExportVisitors)
// User Activities
r.GET("/user-activities", ctrl.GetVisitorActivities)
r.GET("/user-activities-export", ctrl.ExportUserActivities)
// User Feedback
r.GET("/user-feedback", ctrl.GetFeedback)
r.GET("/user-feedback-export", ctrl.ExportFeedback)
// Others
r.GET("/", ctrl.Index)
r.GET("/error", func(c *gin.Context) {
c.HTML(http.StatusOK, "error.tmpl", gin.H{
"title": "Weber Insight - Error",
})
})
r.GET("/#", func(c *gin.Context) {
c.HTML(http.StatusOK, "login.html", gin.H{
"title": "Weber Insight - Login",
})
})
r.GET("/dashboard", func(c *gin.Context) {
session := sessions.Default(c)
c.HTML(http.StatusOK, "dashboard.tmpl", gin.H{
"name": session.Get("name"),
"title": "Weber Insight - Dashboard",
"dashboard": true,
})
})
r.GET("/notification", func(c *gin.Context) {
session := sessions.Default(c)
c.HTML(http.StatusOK, "notification.tmpl", gin.H{
"name": session.Get("name"),
"title": "Weber Insight - Notification",
"emailnotification": true,
})
})
r.GET("/export-data", func(c *gin.Context) {
session := sessions.Default(c)
c.HTML(http.StatusOK, "export.tmpl", gin.H{
"name": session.Get("name"),
"title": "Weber Insight - Export Data",
"exportdata": true,
})
})
return r
}