-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
255 lines (221 loc) · 8.83 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
package main
import (
"fmt"
"html/template"
"net/http"
"os"
"strconv"
lg "github.com/GolangToolKits/go-level-logger"
gss "github.com/GolangToolKits/go-secure-sessions"
mux "github.com/GolangToolKits/grrt"
mcd "github.com/Ulbora/go-micro-blog-ui/delegates"
hd "github.com/Ulbora/go-micro-blog-ui/handlers"
s "github.com/Ulbora/go-micro-blog-ui/signins"
)
/*
Copyright (C) 2023 Ulbora Labs LLC. (www.ulboralabs.com)
All rights reserved.
Copyright (C) 2023 Ken Williamson
All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
func main() {
var secretSessionKey string
var siteTitle string
var siteDesc string
var siteKeyWords string
var restURL string
var apiKey string
var apiAdminKey string
var siteURL string
var siteName string
// var linkedInSigninRedirectURL string
// var googleSigninRedirectURL string
if os.Getenv("SECRET_SESSION_KEY") != "" {
secretSessionKey = os.Getenv("SECRET_SESSION_KEY")
} else {
secretSessionKey = "dsdfsadfs61dsscfsdfdsdsfsdsdllsdfgggg"
}
if os.Getenv("SITE_TITLE") != "" {
siteTitle = os.Getenv("SITE_TITLE")
} else {
siteTitle = "Go Micro Blog"
}
if os.Getenv("SITE_DESC") != "" {
siteDesc = os.Getenv("SITE_DESC")
} else {
siteDesc = "A Micro Blog written in Golang by Ulbora Labs LLC"
}
if os.Getenv("SITE_KEY_WORDS") != "" {
siteKeyWords = os.Getenv("SITE_KEY_WORDS")
} else {
siteKeyWords = "Golang, Micro, Blog, Ulbora, Labs"
}
if os.Getenv("REST_URL") != "" {
restURL = os.Getenv("REST_URL")
} else {
restURL = "http://localhost:3000"
}
if os.Getenv("API_KEY") != "" {
apiKey = os.Getenv("API_KEY")
} else {
apiKey = "557444414141"
}
if os.Getenv("API_ADMIN_KEY") != "" {
apiAdminKey = os.Getenv("API_ADMIN_KEY")
} else {
apiAdminKey = "54211789991515"
}
if os.Getenv("SITE_URL") != "" {
siteURL = os.Getenv("SITE_URL")
} else {
siteURL = "http://localhost:8080"
}
if os.Getenv("SITE_NAME") != "" {
siteName = os.Getenv("SITE_NAME")
} else {
siteName = "Go Micro Blog"
}
var l lg.Logger
log := l.New()
log.SetLogLevel(lg.AllLevel)
var cf gss.ConfigOptions
cf.MaxAge = 3600
cf.Path = "/"
sessionManager, err := gss.NewSessionManager(secretSessionKey, cf)
if err != nil {
log.Info(err)
log.Info("Session err: ", err)
}
var signinMap = make(map[string]s.Signin)
var del mcd.MCDelegate
del.Log = log
del.RestURL = restURL
del.APIAdminKey = apiAdminKey
del.APIKey = apiKey
dd := del.New()
var sh hd.MCHandler
sh.SiteName = siteName
sh.Title = siteTitle
sh.Desc = siteDesc
sh.KeyWords = siteKeyWords
sh.SiteURL = siteURL
sh.Log = log
sh.SessionManager = sessionManager
sh.Delegate = dd
// sh.Signins = signinMap
//var linkedInClientID string
//var linkedInClientSecret string
//add signins here
if os.Getenv("LINKED_IN_CLIENT_ID") != "" {
linkedInClientID := os.Getenv("LINKED_IN_CLIENT_ID")
linkedInClientSecret := os.Getenv("LINKED_IN_CLIENT_SECRET")
linkedInRedirectURL := os.Getenv("LINKED_IN_SIGNIN_REDIRECT_URL")
var lsgn s.LinkedInSignin
lsgn.Log = log
lsgn.ClientID = linkedInClientID
lsgn.ClientSecret = linkedInClientSecret
if linkedInRedirectURL != "" {
lsgn.RedirectURI = linkedInRedirectURL
}
signinMap["linkedIn"] = lsgn.New()
sh.Log.Info("clientId: ", linkedInClientID)
}
if os.Getenv("GOOGLE_CLIENT_ID") != "" {
googleOAuth2ClientID := os.Getenv("GOOGLE_CLIENT_ID")
googleOAuth2ClientSecret := os.Getenv("GOOGLE_CLIENT_SECRET")
googleRedirectURL := os.Getenv("GOOGLE_SIGNIN_REDIRECT_URL")
var glsgn s.GoogleSignin
glsgn.Log = log
glsgn.ClientID = googleOAuth2ClientID
glsgn.ClientSecret = googleOAuth2ClientSecret
if googleRedirectURL != "" {
glsgn.RedirectURI = googleRedirectURL
}
signinMap["googleOAuth2"] = glsgn.New()
sh.Log.Info("clientId: ", googleOAuth2ClientID)
}
sh.Signins = signinMap
sh.Templates = template.Must(template.ParseFiles("./static/#.html",
"./static/blogList.html", "./static/header.html", "./static/user-nav.html",
"./static/addBlog.html", "./static/blog.html", "./static/editBlog.html",
"./static/user-admin-nav.html", "./static/rules.html", "./static/terms.html",
"./static/about.html", "./static/home.html", "./static/privacyPolicy.html"))
sh.AdminTemplates = template.Must(template.ParseFiles("./static/admin/index.html",
"./static/header.html", "./static/admin/adminBlogList.html",
"./static/user-admin-nav.html", "./static/admin/adminBlog.html",
"./static/admin/adminUser.html", "./static/admin/adminUnactivatedUser.html",
"./static/admin/adminBannedUser.html", "./static/admin/adminConfig.html",
"./static/admin/adminAddRule.html", "./static/admin/adminAddTerms.html",
"./static/admin/adminAddAbout.html", "./static/admin/adminAddHome.html",
"./static/admin/adminAddPrivacyPolicy.html"))
router := mux.NewRouter()
h := sh.New()
port := "8080"
envPort := os.Getenv("PORT")
if envPort != "" {
portInt, _ := strconv.Atoi(envPort)
if portInt != 0 {
port = envPort
}
}
router.HandleFunc("/", h.GetHome).Methods("GET")
router.HandleFunc("/auth/linkedin/callback", h.LinkedInCallback).Methods("GET")
router.HandleFunc("/signin-google/callback", h.GoogleSigninCallback).Methods("GET")
router.HandleFunc("/#", h.LoginUserPage).Methods("GET")
router.HandleFunc("/#User/{signingSystem}", h.LoginUser).Methods("GET")
router.HandleFunc("/app", h.GetBlogList).Methods("GET")
router.HandleFunc("/newPost", h.AddBlogPage).Methods("GET")
router.HandleFunc("/addPost", h.AddBlog).Methods("POST")
router.HandleFunc("/addLike/{bid}", h.AddLike).Methods("GET")
router.HandleFunc("/viewPost/{bid}", h.GetBlog).Methods("GET")
router.HandleFunc("/addComment", h.AddComment).Methods("POST")
router.HandleFunc("/editPost/{bid}", h.UpdateBlogPage).Methods("GET")
router.HandleFunc("/updatePost", h.UpdateBlog).Methods("POST")
router.HandleFunc("/searchPost", h.SearchBlogList).Methods("POST")
router.HandleFunc("/rules", h.GetRules).Methods("GET")
router.HandleFunc("/terms", h.GetTerms).Methods("GET")
router.HandleFunc("/about", h.GetAbout).Methods("GET")
router.HandleFunc("/privacyPolicy", h.GetPrivacyPolicy).Methods("GET")
router.HandleFunc("/adminPostList", h.GetAdminBlogList).Methods("GET")
router.HandleFunc("/searchAdminPost", h.SearchAdminBlogList).Methods("POST")
router.HandleFunc("/activateBlog/{bid}", h.ActivateBlog).Methods("GET")
router.HandleFunc("/deactivateBlog/{bid}", h.DeactivateBlog).Methods("GET")
router.HandleFunc("/deleteBlog/{bid}", h.DeleteBlog).Methods("GET")
router.HandleFunc("/adminViewPost/{bid}", h.GetAdminCommentList).Methods("GET")
router.HandleFunc("/activateComment/{cid}/{bid}", h.ActivateComment).Methods("GET")
router.HandleFunc("/deactivateComment/{cid}/{bid}", h.DeactivateComment).Methods("GET")
router.HandleFunc("/adminUser/{uid}", h.GetUserByIDPage).Methods("GET")
router.HandleFunc("/adminInactiveUserList", h.GetUnactivatedUserList).Methods("GET")
router.HandleFunc("/adminBannedUserList", h.GetBannedUserList).Methods("GET")
router.HandleFunc("/activateUser/{uid}", h.EnableUser).Methods("GET")
router.HandleFunc("/disableUser/{uid}", h.DisableUser).Methods("GET")
router.HandleFunc("/deactivateUser/{uid}", h.DisableUserForCause).Methods("GET")
router.HandleFunc("/reactivateUser/{uid}", h.ReinstateBannedUser).Methods("GET")
router.HandleFunc("/adminConfig", h.GetConfig).Methods("GET")
router.HandleFunc("/updateConfig", h.UpdateConfig).Methods("POST")
router.HandleFunc("/adminSetRules", h.SetRulesPage).Methods("GET")
router.HandleFunc("/adminUpdateRules", h.SetRules).Methods("POST")
router.HandleFunc("/adminSetTerms", h.SetTermsPage).Methods("GET")
router.HandleFunc("/adminUpdateTerms", h.SetTerms).Methods("POST")
router.HandleFunc("/adminSetAbout", h.SetAboutPage).Methods("GET")
router.HandleFunc("/adminUpdateAbout", h.SetAbout).Methods("POST")
router.HandleFunc("/adminSetHome", h.SetHomePage).Methods("GET")
router.HandleFunc("/adminUpdateHome", h.SetHome).Methods("POST")
router.HandleFunc("/adminSetPrivacyPolicy", h.SetPrivacyPolicyPage).Methods("GET")
router.HandleFunc("/adminUpdatePrivacyPolicy", h.SetPrivacyPolicy).Methods("POST")
router.HandleFunc("/rs/loglevel", h.SetLogLevel).Methods("POST")
router.PathPrefix("/").Handler(http.FileServer(http.Dir("./static/")))
fmt.Println("Web UI is running on port 8080!")
http.ListenAndServe(":"+port, (router))
}
// go mod init github.com/Ulbora/go-micro-blog-ui