-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
133 lines (105 loc) · 4.09 KB
/
main.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package main
import (
"flag"
"log"
"os"
"github.com/Maekes/planer/handler"
"github.com/gin-contrib/cors"
"github.com/joho/godotenv"
jwtsession "github.com/ScottHuangZL/gin-jwt-session"
"github.com/gin-gonic/autotls"
"github.com/gin-gonic/gin"
)
func main() {
godotenv.Load()
//flag.StringVar(&handler.MailPW, "pw", "", "Password for MailServer")
//flag.StringVar(&handler.KaplanHost, "host", "", "Host for Kaplan Server")
//flag.StringVar(&handler.KaplanSecret, "kaplan", "", "Secret RefID from Kaplan")
local := flag.Bool("local", false, "Run Server on Local Machine")
update := flag.Bool("update", false, "Run Update Function")
noTLS := flag.Bool("notls", false, "Disable TLS for Webserver")
flag.Parse()
if *local {
handler.InitHandler(":27017")
} else {
handler.InitHandler("mongo:27017")
gin.SetMode(gin.ReleaseMode)
}
if *update {
handler.Update()
}
r := gin.Default()
jwtsession.JwtTokenName = "Token" //string without blank
jwtsession.DefaultSessionName = "Session" //string without blank
jwtsession.DefaultFlashSessionName = "FlashSession" //string without blank
jwtsession.NewStore()
r.Use(jwtsession.ClearMiddleware())
r.Use(cors.Default())
//new template engine
r.HTMLRender = handler.GetTemplateConfig()
r.Static("/assets", "assets")
r.Static("/demo", "demo")
r.GET("/login", handler.LoginHandler)
r.POST("/login", handler.ValidateJwtLoginHandler)
r.GET("/register", handler.RegisterHandler)
r.POST("/register", handler.RegisterPostHandler)
r.GET("/rueckmeldung", handler.RueckmeldungFormHandler)
r.POST("/rueckmeldung", handler.RueckmeldungPostFormHandler)
auth := r.Group("/")
auth.Use(handler.ValidationMiddleware)
{
auth.GET("/", handler.MessdienerplanHandler)
auth.GET("/minis", handler.MinisHandler)
auth.POST("/logout", handler.LogoutHandler)
auth.GET("/messen", handler.MessenHandler)
auth.GET("/zuordnen/:id", handler.ZuordnenHandler)
auth.GET("/messdienerplan", handler.MessdienerplanHandler)
auth.GET("/messdienerplan/pdf/:id", handler.MessdienerplanPdfHandler)
auth.GET("/messdienerplan/xlsx/:id", handler.MessdienerplanXlsxHandler)
auth.GET("/messdienerplan/delete/:id", handler.MessdienerplanDeleteHandler)
auth.POST("/zuordnen/draged", handler.ZuordnenDragedHandler)
auth.POST("/zuordnen/editInfoForPlan", handler.ZuordnenEditInfoForPlandHandler)
auth.POST("/zuordnen/delete", handler.ZuordnenDeleteHandler)
auth.POST("/zuordnen/finish", handler.ZuordnenFinishHandler)
auth.POST("/messen", handler.AddMessenHandler)
auth.GET("/messen/delete/:id", handler.MessenDeleteHandler)
auth.POST("/messen/deleteAll", handler.MessenDeleteAllHandler)
auth.POST("/messen/updateRelevantState", handler.MessenUpdateStateHandler)
auth.POST("/messen/importFromExcel", handler.AddMessenFromExcelHandler)
auth.POST("/messen/importFromKaplan", handler.AddMessenFromKaplanHandler)
auth.POST("/messdienerplan/changehinweis", handler.MessdienerplanChangeHinweisHandler)
auth.POST("/messdienerplan/create", handler.MessdienerplanCreateHandler)
auth.GET("/minis/delete/:id", handler.MinisDeleteHandler)
auth.POST("/minis", handler.AddMiniHandler)
auth.POST("/minis/importFromExcel", handler.AddMiniFromExcelHandler)
auth.GET("/einstellungen", handler.EinstellungenHandler)
auth.POST("/einstellungen", handler.EinstellungenChangeHandler)
auth.POST("/einstellungen/changepassword", handler.PasswordChangeHandler)
admin := auth.Group("adminArea")
admin.Use(handler.AdminMiddleware)
{
admin.GET("/", handler.AdminHandler)
admin.GET("/user/delete/:id", handler.UserDeleteHandler)
admin.GET("/user/resetPassword/:id", handler.UserResetPassword)
}
}
r.NoRoute(handler.Error404Handler)
if *local {
r.Run("127.0.0.1:8080")
//r.RunTLS("localhost:8080", "localhost.crt", "localhost.key")
//log.Fatal(autotls.Run(r, "localhost"))
} else if *noTLS {
r.Run("0.0.0.0:80")
} else {
log.Fatal(autotls.Run(r, os.Getenv("Host"), "www."+os.Getenv("Host")))
}
}
func isFlagPassed(name string) bool {
found := false
flag.Visit(func(f *flag.Flag) {
if f.Name == name {
found = true
}
})
return found
}