summaryrefslogtreecommitdiff
path: root/system/admin/admin.go
diff options
context:
space:
mode:
Diffstat (limited to 'system/admin/admin.go')
-rw-r--r--system/admin/admin.go160
1 files changed, 152 insertions, 8 deletions
diff --git a/system/admin/admin.go b/system/admin/admin.go
index 410c9f4..1c04bce 100644
--- a/system/admin/admin.go
+++ b/system/admin/admin.go
@@ -7,12 +7,13 @@ import (
"html/template"
"github.com/nilslice/cms/content"
+ "github.com/nilslice/cms/system/db"
)
-const adminHTML = `<!doctype html>
+var startAdminHTML = `<!doctype html>
<html lang="en">
<head>
- <title>CMS</title>
+ <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>
@@ -32,7 +33,7 @@ const adminHTML = `<!doctype html>
<div class="navbar-fixed">
<nav class="grey darken-2">
<div class="nav-wrapper">
- <a class="brand-logo" href="/admin">CMS</a>
+ <a class="brand-logo" href="/admin">{{ .Logo }}</a>
<ul class="right">
<li><a href="/admin/logout">Logout</a></li>
@@ -41,8 +42,9 @@ const adminHTML = `<!doctype html>
</nav>
</div>
- <div class="admin-ui row">
-
+ <div class="admin-ui row">`
+
+var mainAdminHTML = `
<div class="left-nav col s3">
<div class="card">
<ul class="card-content collection">
@@ -57,6 +59,7 @@ const adminHTML = `<!doctype html>
<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>
@@ -65,26 +68,167 @@ const adminHTML = `<!doctype html>
<div class="subview col s9">
{{ .Subview }}
</div>
- {{ end }}
+ {{ 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{}
- tmpl := template.Must(template.New("admin").Parse(adminHTML))
- err := tmpl.Execute(buf, a)
+ 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
}