Repository navigation
Expand file tree
/
Copy pathauth.go
More file actions
executable file
·101 lines (81 loc) · 2.83 KB
/
Copy pathauth.go
File metadata and controls
executable file
·101 lines (81 loc) · 2.83 KB
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
package main
import (
"fmt"
"time"
"github.com/fatih/color"
)
func doAuth() error {
// migrations
dbType := gho.DB.DataType
fileName := fmt.Sprintf("%d_create_auth_tables", time.Now().UnixMicro())
upFile := gho.RootPath + "/migrations/" + fileName + ".up.sql"
downFile := gho.RootPath + "/migrations/" + fileName + ".down.sql"
err := copyFilefromTemplate("templates/migrations/auth_tables."+dbType+".sql", upFile)
if err != nil {
exitGracefully(err)
}
err = copyDataToFile([]byte("drop table if exists users cascade; drop table if exists tokens cascade; drop table if exists remember_tokens;"), downFile)
if err != nil {
exitGracefully(err)
}
// run migrations
err = doMigrate("up", "")
if err != nil {
exitGracefully(err)
}
err = copyFilefromTemplate("templates/data/user.go.txt", gho.RootPath+"/data/user.go")
if err != nil {
exitGracefully(err)
}
err = copyFilefromTemplate("templates/data/token.go.txt", gho.RootPath+"/data/token.go")
if err != nil {
exitGracefully(err)
}
err = copyFilefromTemplate("templates/data/remember_token.go.txt", gho.RootPath+"/data/remember_token.go")
if err != nil {
exitGracefully(err)
}
// copy over middleware
err = copyFilefromTemplate("templates/middleware/auth.go.txt", gho.RootPath+"/middleware/auth.go")
if err != nil {
exitGracefully(err)
}
err = copyFilefromTemplate("templates/middleware/auth-token.go.txt", gho.RootPath+"/middleware/auth-token.go")
if err != nil {
exitGracefully(err)
}
err = copyFilefromTemplate("templates/middleware/remember.go.txt", gho.RootPath+"/middleware/remember.go")
if err != nil {
exitGracefully(err)
}
err = copyFilefromTemplate("templates/handlers/auth-handlers.go.txt", gho.RootPath+"/handlers/auth-handlers.go")
if err != nil {
exitGracefully(err)
}
err = copyFilefromTemplate("templates/mailer/password-reset.html.tmpl", gho.RootPath+"/mail/password-reset.html.tmpl")
if err != nil {
exitGracefully(err)
}
err = copyFilefromTemplate("templates/mailer/password-reset.plain.tmpl", gho.RootPath+"/mail/password-reset.plain.tmpl")
if err != nil {
exitGracefully(err)
}
err = copyFilefromTemplate("templates/views/login.jet", gho.RootPath+"/views/login.jet")
if err != nil {
exitGracefully(err)
}
err = copyFilefromTemplate("templates/views/forgot.jet", gho.RootPath+"/views/forgot.jet")
if err != nil {
exitGracefully(err)
}
err = copyFilefromTemplate("templates/views/reset-password.jet", gho.RootPath+"/views/reset-password.jet")
if err != nil {
exitGracefully(err)
}
color.Yellow(" - users, tokens, and remember_tokens migrations created and executed")
color.Yellow(" - user and token models created")
color.Yellow(" - auth middleware created")
color.Yellow("")
color.Yellow("Don't forget to add user and token models in data/models.go, and to add appropriate middleware to your routes!")
return nil
}