mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-10-30 03:36:16 +00:00
Initial user panel draft
This commit is contained in:
parent
16861bd3d4
commit
477c449a05
@ -2,14 +2,14 @@ package user
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
|
||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||
"github.com/bouncepaw/mycorrhiza/util"
|
||||
"github.com/bouncepaw/mycorrhiza/files"
|
||||
"github.com/bouncepaw/mycorrhiza/util"
|
||||
)
|
||||
|
||||
// InitUserDatabase checks the configuration for auth methods and loads users
|
||||
|
@ -58,6 +58,7 @@ func Register(username, password string) error {
|
||||
Name: username,
|
||||
Group: "editor",
|
||||
HashedPassword: string(hash),
|
||||
RegisteredAt: time.Now(),
|
||||
Source: SourceRegistration,
|
||||
}
|
||||
users.Store(username, &u)
|
||||
|
@ -2,6 +2,7 @@ package user
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
@ -24,6 +25,7 @@ type User struct {
|
||||
Group string `json:"group"`
|
||||
Password string `json:"password"` // for fixed
|
||||
HashedPassword string `json:"hashed_password"` // for registered
|
||||
RegisteredAt time.Time `json:"registered_on"`
|
||||
Source UserSource `json:"-"`
|
||||
sync.RWMutex
|
||||
|
||||
|
34
views/admin.qtpl
Normal file
34
views/admin.qtpl
Normal file
@ -0,0 +1,34 @@
|
||||
{% import "github.com/bouncepaw/mycorrhiza/user" %}
|
||||
|
||||
{% func AdminUsersPanelHTML(userList []*user.User) %}
|
||||
<div class="layout">
|
||||
<main class="main-width">
|
||||
<h1>Manage users</h1>
|
||||
|
||||
<form action="/admin/reindex-users" method="get">
|
||||
<button class="btn btn_accent" type="submit">Reindex users</button>
|
||||
</form>
|
||||
|
||||
<h2>Users list</h2>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Group</th>
|
||||
<th>Registered at</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for _, u := range userList %}
|
||||
<tr>
|
||||
<td>{%s= u.Name %}</td>
|
||||
<td>{%s= u.Group %}</td>
|
||||
<td>{%s= u.RegisteredAt.Format("2006-01-02 15:04:05-0700") %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</main>
|
||||
</div>
|
||||
{% endfunc %}
|
105
views/admin.qtpl.go
Normal file
105
views/admin.qtpl.go
Normal file
@ -0,0 +1,105 @@
|
||||
// Code generated by qtc from "admin.qtpl". DO NOT EDIT.
|
||||
// See https://github.com/valyala/quicktemplate for details.
|
||||
|
||||
//line views/admin.qtpl:1
|
||||
package views
|
||||
|
||||
//line views/admin.qtpl:1
|
||||
import "github.com/bouncepaw/mycorrhiza/user"
|
||||
|
||||
//line views/admin.qtpl:3
|
||||
import (
|
||||
qtio422016 "io"
|
||||
|
||||
qt422016 "github.com/valyala/quicktemplate"
|
||||
)
|
||||
|
||||
//line views/admin.qtpl:3
|
||||
var (
|
||||
_ = qtio422016.Copy
|
||||
_ = qt422016.AcquireByteBuffer
|
||||
)
|
||||
|
||||
//line views/admin.qtpl:3
|
||||
func StreamAdminUsersPanelHTML(qw422016 *qt422016.Writer, userList []*user.User) {
|
||||
//line views/admin.qtpl:3
|
||||
qw422016.N().S(`
|
||||
<div class="layout">
|
||||
<main class="main-width">
|
||||
<h1>Manage users</h1>
|
||||
|
||||
<form action="/admin/reindex-users" method="get">
|
||||
<button class="btn btn_accent" type="submit">Reindex users</button>
|
||||
</form>
|
||||
|
||||
<h2>Users list</h2>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Group</th>
|
||||
<th>Registered at</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
`)
|
||||
//line views/admin.qtpl:23
|
||||
for _, u := range userList {
|
||||
//line views/admin.qtpl:23
|
||||
qw422016.N().S(`
|
||||
<tr>
|
||||
<td>`)
|
||||
//line views/admin.qtpl:25
|
||||
qw422016.N().S(u.Name)
|
||||
//line views/admin.qtpl:25
|
||||
qw422016.N().S(`</td>
|
||||
<td>`)
|
||||
//line views/admin.qtpl:26
|
||||
qw422016.N().S(u.Group)
|
||||
//line views/admin.qtpl:26
|
||||
qw422016.N().S(`</td>
|
||||
<td>`)
|
||||
//line views/admin.qtpl:27
|
||||
qw422016.N().S(u.RegisteredAt.Format("2006-01-02 15:04:05-0700"))
|
||||
//line views/admin.qtpl:27
|
||||
qw422016.N().S(`</td>
|
||||
</tr>
|
||||
`)
|
||||
//line views/admin.qtpl:29
|
||||
}
|
||||
//line views/admin.qtpl:29
|
||||
qw422016.N().S(`
|
||||
</tbody>
|
||||
</table>
|
||||
</main>
|
||||
</div>
|
||||
`)
|
||||
//line views/admin.qtpl:34
|
||||
}
|
||||
|
||||
//line views/admin.qtpl:34
|
||||
func WriteAdminUsersPanelHTML(qq422016 qtio422016.Writer, userList []*user.User) {
|
||||
//line views/admin.qtpl:34
|
||||
qw422016 := qt422016.AcquireWriter(qq422016)
|
||||
//line views/admin.qtpl:34
|
||||
StreamAdminUsersPanelHTML(qw422016, userList)
|
||||
//line views/admin.qtpl:34
|
||||
qt422016.ReleaseWriter(qw422016)
|
||||
//line views/admin.qtpl:34
|
||||
}
|
||||
|
||||
//line views/admin.qtpl:34
|
||||
func AdminUsersPanelHTML(userList []*user.User) string {
|
||||
//line views/admin.qtpl:34
|
||||
qb422016 := qt422016.AcquireByteBuffer()
|
||||
//line views/admin.qtpl:34
|
||||
WriteAdminUsersPanelHTML(qb422016, userList)
|
||||
//line views/admin.qtpl:34
|
||||
qs422016 := string(qb422016.B)
|
||||
//line views/admin.qtpl:34
|
||||
qt422016.ReleaseByteBuffer(qb422016)
|
||||
//line views/admin.qtpl:34
|
||||
return qs422016
|
||||
//line views/admin.qtpl:34
|
||||
}
|
@ -137,7 +137,7 @@ for u := range user.YieldUsers() {
|
||||
<section>
|
||||
<h2>Safe things</h2>
|
||||
<ul>
|
||||
<li><a href="/about">About this wiki<a></li>
|
||||
<li><a href="/about">About this wiki</a></li>
|
||||
<li><a href="/user-list">User list</a></li>
|
||||
<li><a href="/update-header-links">Update header links</a></li>
|
||||
</ul>
|
||||
|
@ -470,7 +470,7 @@ func StreamAdminPanelHTML(qw422016 *qt422016.Writer) {
|
||||
<section>
|
||||
<h2>Safe things</h2>
|
||||
<ul>
|
||||
<li><a href="/about">About this wiki<a></li>
|
||||
<li><a href="/about">About this wiki</a></li>
|
||||
<li><a href="/user-list">User list</a></li>
|
||||
<li><a href="/update-header-links">Update header links</a></li>
|
||||
</ul>
|
||||
|
28
web/admin.go
28
web/admin.go
@ -4,6 +4,7 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"sort"
|
||||
|
||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||
"github.com/bouncepaw/mycorrhiza/user"
|
||||
@ -17,6 +18,8 @@ func initAdmin() {
|
||||
http.HandleFunc("/admin", handlerAdmin)
|
||||
http.HandleFunc("/admin/shutdown", handlerAdminShutdown)
|
||||
http.HandleFunc("/admin/reindex-users", handlerAdminReindexUsers)
|
||||
|
||||
http.HandleFunc("/admin/users", handlerAdminUsers)
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,3 +52,28 @@ func handlerAdminReindexUsers(w http.ResponseWriter, rq *http.Request) {
|
||||
http.Redirect(w, rq, "/hypha/"+cfg.UserHypha, http.StatusSeeOther)
|
||||
}
|
||||
}
|
||||
|
||||
func handlerAdminUsers(w http.ResponseWriter, r *http.Request) {
|
||||
util.PrepareRq(r)
|
||||
if user.CanProceed(r, "admin") {
|
||||
// Get a sorted list of users
|
||||
var userList []*user.User
|
||||
for u := range user.YieldUsers() {
|
||||
userList = append(userList, u)
|
||||
}
|
||||
|
||||
sort.Slice(userList, func(i, j int) bool {
|
||||
less := userList[i].RegisteredAt.Before(userList[j].RegisteredAt)
|
||||
return less
|
||||
})
|
||||
|
||||
html := views.AdminUsersPanelHTML(userList)
|
||||
html = views.BaseHTML("Manage users", html, user.FromRequest(r))
|
||||
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
_, err := io.WriteString(w, html)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user