-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
97 lines (83 loc) · 2.11 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
//go:generate go run generate.go
package main
import (
"log"
"math/rand"
"time"
"vpub/config"
"vpub/model"
"vpub/storage"
"vpub/web"
)
func main() {
rand.Seed(time.Now().UTC().UnixNano())
cfg := config.New()
if cfg.SessionKey == "your32byteslongsessionkeyhere" {
log.Println("[Warning] You forgot to change your Session Key. Make sure to not expose this instance publicly.")
}
if cfg.CSRFKey == "your32byteslongcsrfkeyhere" {
log.Println("[Warning] Remember to change the CSRF key, you're using the default one.")
}
db, err := storage.InitDB(cfg)
if err != nil {
log.Fatal(err)
}
data := storage.New(db)
adminExists, err := data.HasAdmin()
if err != nil {
log.Fatal(err)
}
if !adminExists {
userID, err := data.CreateUser("admin", model.UserCreationRequest{
Name: "admin",
Password: "admin",
IsAdmin: true,
})
if err != nil {
log.Fatal(err)
}
forumID, err := data.CreateForum(model.ForumRequest{
Name: "Getting started",
Position: 0,
IsLocked: false,
})
if err != nil {
log.Fatal(err)
}
boardID, err := data.CreateBoard(model.BoardRequest{
Name: "Your first board",
Description: "This is a sample board.",
Position: 0,
IsLocked: false,
ForumId: forumID,
})
if err != nil {
log.Fatal(err)
}
_, err = data.CreateTopic(userID, model.TopicRequest{
Subject: "Change your admin account password",
Content: `It might be a good idea to change your default Admin password!
## To change the password.
Navigate to [/admin/users](/admin/users). Find the **admin** user and change the password.`,
BoardId: boardID,
IsLocked: true,
IsSticky: true,
})
if err != nil {
log.Fatal(err)
}
_, err = data.CreateTopic(userID, model.TopicRequest{
Subject: "What to do?",
Content: `Navigate to the [/admin](/admin) route and see what you can change in there. Just make sure you do not delete yourself, okay? Otherwise you will be locked in a weird state.`,
BoardId: boardID,
IsLocked: false,
IsSticky: false,
})
if err != nil {
log.Fatal(err)
}
}
log.Fatal(
web.Serve(cfg, data),
)
}