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
|
// Package admin desrcibes the admin view containing references to
// various managers and editors
package admin
import (
"bytes"
"html/template"
"github.com/nilslice/cms/content"
"github.com/nilslice/cms/system/db"
)
var startAdminHTML = `<!doctype html>
<html lang="en">
<head>
<title>{{ .Logo }}</title>
<script type="text/javascript" src="/admin/static/common/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="/admin/static/common/js/util.js"></script>
<script type="text/javascript" src="/admin/static/dashboard/js/materialize.min.js"></script>
<script type="text/javascript" src="/admin/static/editor/js/materialNote.js"></script>
<script type="text/javascript" src="/admin/static/editor/js/ckMaterializeOverrides.js"></script>
<link rel="stylesheet" href="/admin/static/dashboard/css/material-icons.css" />
<link rel="stylesheet" href="/admin/static/dashboard/css/materialize.min.css" />
<link rel="stylesheet" href="/admin/static/editor/css/materialNote.css" />
<link rel="stylesheet" href="/admin/static/dashboard/css/admin.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<body class="grey lighten-4">
<div class="navbar-fixed">
<nav class="grey darken-2">
<div class="nav-wrapper">
<a class="brand-logo" href="/admin">{{ .Logo }}</a>
<ul class="right">
<li><a href="/admin/logout">Logout</a></li>
</ul>
</div>
</nav>
</div>
<div class="admin-ui row">`
var mainAdminHTML = `
<div class="left-nav col s3">
<div class="card">
<ul class="card-content collection">
<div class="card-title">Content</div>
{{ range $t, $f := .Types }}
<div class="row collection-item">
<li><a class="col s12" href="/admin/posts?type={{ $t }}"><i class="tiny left material-icons">playlist_add</i>{{ $t }}</a></li>
</div>
{{ end }}
<div class="card-title">System</div>
<div class="row collection-item">
<li><a class="col s12" href="/admin/configure"><i class="tiny left material-icons">settings</i>Configuration</a></li>
<li><a class="col s12" href="/admin/configure/users"><i class="tiny left material-icons">supervisor_account</i>Users</a></li>
</div>
</ul>
</div>
</div>
{{ if .Subview}}
<div class="subview col s9">
{{ .Subview }}
</div>
{{ end }}`
var endAdminHTML = `
</div>
</body>
</html>`
type admin struct {
Logo string
Types map[string]func() interface{}
Subview template.HTML
}
// Admin ...
func Admin(view []byte) ([]byte, error) {
cfg, err := db.Config("name")
if err != nil {
return nil, err
}
if cfg == nil {
cfg = []byte("")
}
a := admin{
Logo: string(cfg),
Types: content.Types,
Subview: template.HTML(view),
}
buf := &bytes.Buffer{}
html := startAdminHTML + mainAdminHTML + endAdminHTML
tmpl := template.Must(template.New("admin").Parse(html))
err = tmpl.Execute(buf, a)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
var initAdminHTML = `
<div class="init col s5">
<div class="card">
<div class="card-content">
<div class="card-title">Welcome!</div>
<blockquote>You need to initialize your system by filling out the form below. All of
this information can be updated later on, but you will not be able to start
without first completing this step.</blockquote>
<form method="post" action="/admin/init" class="row">
<div>Configuration</div>
<div class="input-field col s12">
<input placeholder="Enter the name of your site (interal use only)" class="validate required" type="text" id="name" name="name"/>
<label for="name" class="active">Site Name</label>
</div>
<div class="input-field col s12">
<input placeholder="Used for acquiring SSL certificate (e.g. www.example.com or example.com)" class="validate" type="text" id="domain" name="domain"/>
<label for="domain" class="active">Domain</label>
</div>
<div>Admin Details</div>
<div class="input-field col s12">
<input placeholder="Your email address e.g. you@example.com" class="validate required" type="email" id="email" name="email"/>
<label for="email" class="active">Email</label>
</div>
<div class="input-field col s12">
<input placeholder="Enter a strong password" class="validate required" type="password" id="password" name="password"/>
<label for="password" class="active">Password</label>
</div>
<button class="btn waves-effect waves-light right">Start</button>
</form>
</div>
</div>
</div>
<script>
$(function() {
$('.nav-wrapper ul.right').hide();
var logo = $('a.brand-logo');
var name = $('input#name');
name.on('change', function(e) {
logo.text(e.target.value);
});
});
</script>
`
// Init ...
func Init() ([]byte, error) {
html := startAdminHTML + initAdminHTML + endAdminHTML
cfg, err := db.Config("name")
if err != nil {
return nil, err
}
if cfg == nil {
cfg = []byte("")
}
a := admin{
Logo: string(cfg),
}
buf := &bytes.Buffer{}
tmpl := template.Must(template.New("init").Parse(html))
err = tmpl.Execute(buf, a)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
var loginAdminHTML = `
<div class="init col s5">
<div class="card">
<div class="card-content">
<div class="card-title">Welcome!</div>
<blockquote>Please log in to the system using your email address and password.</blockquote>
<form method="post" action="/admin/login" class="row">
<div class="input-field col s12">
<input placeholder="Enter your email address e.g. you@example.com" class="validate required" type="email" id="email" name="email"/>
<label for="email" class="active">Email</label>
</div>
<div class="input-field col s12">
<input placeholder="Enter your password" class="validate required" type="password" id="password" name="password"/>
<label for="password" class="active">Password</label>
</div>
<button class="btn waves-effect waves-light right">Log in</button>
</form>
</div>
</div>
</div>
<script>
$(function() {
$('.nav-wrapper ul.right').hide();
});
</script>
`
// Login ...
func Login() ([]byte, error) {
html := startAdminHTML + loginAdminHTML + endAdminHTML
cfg, err := db.Config("name")
if err != nil {
return nil, err
}
if cfg == nil {
cfg = []byte("")
}
a := admin{
Logo: string(cfg),
}
buf := &bytes.Buffer{}
tmpl := template.Must(template.New("login").Parse(html))
err = tmpl.Execute(buf, a)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
|