mirror of
https://github.com/1f349/lavender.git
synced 2024-12-22 07:34:06 +00:00
Move manage apps and users forms into separate templates
This commit is contained in:
parent
befccd861f
commit
08096a4b98
72
pages/manage-apps-create.go.html
Normal file
72
pages/manage-apps-create.go.html
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>{{.ServiceName}}</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<link rel="stylesheet" href="/assets/style.css">
|
||||||
|
<script>
|
||||||
|
window.addEventListener("load", function () {
|
||||||
|
selectText("app-secret");
|
||||||
|
});
|
||||||
|
|
||||||
|
// Thanks again: https://stackoverflow.com/a/987376
|
||||||
|
function selectText(nodeId) {
|
||||||
|
const node = document.getElementById(nodeId);
|
||||||
|
|
||||||
|
if (document.body.createTextRange) {
|
||||||
|
const range = document.body.createTextRange();
|
||||||
|
range.moveToElementText(node);
|
||||||
|
range.select();
|
||||||
|
} else if (window.getSelection) {
|
||||||
|
const selection = window.getSelection();
|
||||||
|
const range = document.createRange();
|
||||||
|
range.selectNodeContents(node);
|
||||||
|
selection.removeAllRanges();
|
||||||
|
selection.addRange(range);
|
||||||
|
} else {
|
||||||
|
console.warn("Could not select text in node: Unsupported browser.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{{template "header.go.html" .}}
|
||||||
|
<main>
|
||||||
|
<form method="GET" action="/">
|
||||||
|
<button type="submit">Home</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<h2>Create Client Application</h2>
|
||||||
|
<form method="POST" action="/manage/apps">
|
||||||
|
<input type="hidden" name="action" value="create"/>
|
||||||
|
<input type="hidden" name="offset" value="{{.Offset}}"/>
|
||||||
|
<div>
|
||||||
|
<label for="field_name">Name:</label>
|
||||||
|
<input type="text" name="name" id="field_name" required/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="field_domain">Domain:</label>
|
||||||
|
<input type="text" name="domain" id="field_domain" required/>
|
||||||
|
</div>
|
||||||
|
{{if .IsAdmin}}
|
||||||
|
<div>
|
||||||
|
<label for="field_perms">Perms:</label>
|
||||||
|
<input type="text" name="perms" id="field_perms"/>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
<div>
|
||||||
|
<label for="field_public">Public: <input type="checkbox" name="public" id="field_public"/></label>
|
||||||
|
</div>
|
||||||
|
{{if .IsAdmin}}
|
||||||
|
<div>
|
||||||
|
<label for="field_sso">SSO: <input type="checkbox" name="sso" id="field_sso"/></label>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
<div>
|
||||||
|
<label for="field_active">Active: <input type="checkbox" name="active" id="field_active" checked/></label>
|
||||||
|
</div>
|
||||||
|
<button type="submit">Create</button>
|
||||||
|
</form>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
80
pages/manage-apps-edit.go.html
Normal file
80
pages/manage-apps-edit.go.html
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>{{.ServiceName}}</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<link rel="stylesheet" href="/assets/style.css">
|
||||||
|
<script>
|
||||||
|
window.addEventListener("load", function () {
|
||||||
|
selectText("app-secret");
|
||||||
|
});
|
||||||
|
|
||||||
|
// Thanks again: https://stackoverflow.com/a/987376
|
||||||
|
function selectText(nodeId) {
|
||||||
|
const node = document.getElementById(nodeId);
|
||||||
|
|
||||||
|
if (document.body.createTextRange) {
|
||||||
|
const range = document.body.createTextRange();
|
||||||
|
range.moveToElementText(node);
|
||||||
|
range.select();
|
||||||
|
} else if (window.getSelection) {
|
||||||
|
const selection = window.getSelection();
|
||||||
|
const range = document.createRange();
|
||||||
|
range.selectNodeContents(node);
|
||||||
|
selection.removeAllRanges();
|
||||||
|
selection.addRange(range);
|
||||||
|
} else {
|
||||||
|
console.warn("Could not select text in node: Unsupported browser.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{{template "header.go.html" .}}
|
||||||
|
<main>
|
||||||
|
<form method="GET" action="/">
|
||||||
|
<button type="submit">Home</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<h2>Edit Client Application</h2>
|
||||||
|
<form method="POST" action="/manage/apps">
|
||||||
|
<input type="hidden" name="action" value="edit"/>
|
||||||
|
<input type="hidden" name="offset" value="{{.Offset}}"/>
|
||||||
|
<input type="hidden" name="subject" value="{{.EditApp.Subject}}"/>
|
||||||
|
<div>
|
||||||
|
<label>ID: {{.EditApp.Subject}}</label>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="field_name">Name:</label>
|
||||||
|
<input type="text" name="name" id="field_name" value="{{.EditApp.Name}}" required/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="field_domain">Domain:</label>
|
||||||
|
<input type="text" name="domain" id="field_domain" value="{{.EditApp.Domain}}" required/>
|
||||||
|
</div>
|
||||||
|
{{if .IsAdmin}}
|
||||||
|
<div>
|
||||||
|
<label for="field_perms">Perms:</label>
|
||||||
|
<input type="text" name="perms" id="field_perms" value="{{.EditApp.Perms}}" size="100"/>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
<div>
|
||||||
|
<label for="field_public">Public: <input type="checkbox" name="public" id="field_public" {{if .EditApp.Public}}checked{{end}}/></label>
|
||||||
|
</div>
|
||||||
|
{{if .IsAdmin}}
|
||||||
|
<div>
|
||||||
|
<label for="field_sso">SSO: <input type="checkbox" name="sso" id="field_sso" {{if .EditApp.Sso}}checked{{end}}/></label>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
<div>
|
||||||
|
<label for="field_active">Active: <input type="checkbox" name="active" id="field_active" {{if .EditApp.Active}}checked{{end}}/></label>
|
||||||
|
</div>
|
||||||
|
<button type="submit">Edit</button>
|
||||||
|
</form>
|
||||||
|
<form method="GET" action="/manage/apps">
|
||||||
|
<input type="hidden" name="offset" value="{{.Offset}}"/>
|
||||||
|
<button type="submit">Cancel</button>
|
||||||
|
</form>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -40,48 +40,10 @@
|
|||||||
<div>New application secret: <span id="app-secret">{{.NewAppSecret}}</span> for {{.NewAppName}}</div>
|
<div>New application secret: <span id="app-secret">{{.NewAppSecret}}</span> for {{.NewAppName}}</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{if .EditApp}}
|
|
||||||
<h2>Edit Client Application</h2>
|
|
||||||
<form method="POST" action="/manage/apps">
|
|
||||||
<input type="hidden" name="action" value="edit"/>
|
|
||||||
<input type="hidden" name="offset" value="{{.Offset}}"/>
|
|
||||||
<input type="hidden" name="subject" value="{{.EditApp.Subject}}"/>
|
|
||||||
<div>
|
|
||||||
<label>ID: {{.EditApp.Subject}}</label>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label for="field_name">Name:</label>
|
|
||||||
<input type="text" name="name" id="field_name" value="{{.EditApp.Name}}" required/>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label for="field_domain">Domain:</label>
|
|
||||||
<input type="text" name="domain" id="field_domain" value="{{.EditApp.Domain}}" required/>
|
|
||||||
</div>
|
|
||||||
{{if .IsAdmin}}
|
|
||||||
<div>
|
|
||||||
<label for="field_perms">Perms:</label>
|
|
||||||
<input type="text" name="perms" id="field_perms" value="{{.EditApp.Perms}}" size="100"/>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
<div>
|
|
||||||
<label for="field_public">Public: <input type="checkbox" name="public" id="field_public" {{if .EditApp.Public}}checked{{end}}/></label>
|
|
||||||
</div>
|
|
||||||
{{if .IsAdmin}}
|
|
||||||
<div>
|
|
||||||
<label for="field_sso">SSO: <input type="checkbox" name="sso" id="field_sso" {{if .EditApp.SSO}}checked{{end}}/></label>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
<div>
|
|
||||||
<label for="field_active">Active: <input type="checkbox" name="active" id="field_active" {{if .EditApp.Active}}checked{{end}}/></label>
|
|
||||||
</div>
|
|
||||||
<button type="submit">Edit</button>
|
|
||||||
</form>
|
|
||||||
<form method="GET" action="/manage/apps">
|
|
||||||
<input type="hidden" name="offset" value="{{.Offset}}"/>
|
|
||||||
<button type="submit">Cancel</button>
|
|
||||||
</form>
|
|
||||||
{{else}}
|
|
||||||
<h2>Manage Client Applications</h2>
|
<h2>Manage Client Applications</h2>
|
||||||
|
<form method="GET" action="/manage/apps/create">
|
||||||
|
<button type="submit">New Client Application</button>
|
||||||
|
</form>
|
||||||
{{if eq (len .Apps) 0}}
|
{{if eq (len .Apps) 0}}
|
||||||
<div>No client applications found</div>
|
<div>No client applications found</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
@ -105,7 +67,7 @@
|
|||||||
<td>{{.Name}}</td>
|
<td>{{.Name}}</td>
|
||||||
<td>{{.Domain}}</td>
|
<td>{{.Domain}}</td>
|
||||||
<td>{{.Perms}}</td>
|
<td>{{.Perms}}</td>
|
||||||
<td>{{.SSO}}</td>
|
<td>{{.Sso}}</td>
|
||||||
<td>{{.Active}}</td>
|
<td>{{.Active}}</td>
|
||||||
<td>{{.Owner}}</td>
|
<td>{{.Owner}}</td>
|
||||||
<td>
|
<td>
|
||||||
@ -126,39 +88,6 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
<h2>Create Client Application</h2>
|
|
||||||
<form method="POST" action="/manage/apps">
|
|
||||||
<input type="hidden" name="action" value="create"/>
|
|
||||||
<input type="hidden" name="offset" value="{{.Offset}}"/>
|
|
||||||
<div>
|
|
||||||
<label for="field_name">Name:</label>
|
|
||||||
<input type="text" name="name" id="field_name" required/>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label for="field_domain">Domain:</label>
|
|
||||||
<input type="text" name="domain" id="field_domain" required/>
|
|
||||||
</div>
|
|
||||||
{{if .IsAdmin}}
|
|
||||||
<div>
|
|
||||||
<label for="field_perms">Perms:</label>
|
|
||||||
<input type="text" name="perms" id="field_perms"/>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
<div>
|
|
||||||
<label for="field_public">Public: <input type="checkbox" name="public" id="field_public"/></label>
|
|
||||||
</div>
|
|
||||||
{{if .IsAdmin}}
|
|
||||||
<div>
|
|
||||||
<label for="field_sso">SSO: <input type="checkbox" name="sso" id="field_sso"/></label>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
<div>
|
|
||||||
<label for="field_active">Active: <input type="checkbox" name="active" id="field_active" checked/></label>
|
|
||||||
</div>
|
|
||||||
<button type="submit">Create</button>
|
|
||||||
</form>
|
|
||||||
{{end}}
|
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
38
pages/manage-users-edit.go.html
Normal file
38
pages/manage-users-edit.go.html
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>{{.ServiceName}}</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<link rel="stylesheet" href="/assets/style.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{{template "header.go.html" .}}
|
||||||
|
<main>
|
||||||
|
<form method="GET" action="/">
|
||||||
|
<button type="submit">Home</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<h2>Edit User</h2>
|
||||||
|
<form method="POST" action="/manage/users">
|
||||||
|
<input type="hidden" name="action" value="edit"/>
|
||||||
|
<input type="hidden" name="offset" value="{{.Offset}}"/>
|
||||||
|
<div>
|
||||||
|
<label for="field_subject">Subject:</label>
|
||||||
|
<input type="text" name="subject" id="field_subject" value="{{.EditUser.Subject}}" required/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="field_roles">Roles:</label>
|
||||||
|
<input type="text" name="roles" id="field_roles" value="{{.EditUser.Roles}}" size="100"/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="field_active">Active: <input type="checkbox" name="active" id="field_active" checked/></label>
|
||||||
|
</div>
|
||||||
|
<button type="submit">Edit</button>
|
||||||
|
</form>
|
||||||
|
<form method="GET" action="/manage/users">
|
||||||
|
<input type="hidden" name="offset" value="{{.Offset}}"/>
|
||||||
|
<button type="submit">Cancel</button>
|
||||||
|
</form>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -12,29 +12,6 @@
|
|||||||
<button type="submit">Home</button>
|
<button type="submit">Home</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{{if .EditUser}}
|
|
||||||
<h2>Edit User</h2>
|
|
||||||
<form method="POST" action="/manage/users">
|
|
||||||
<input type="hidden" name="action" value="edit"/>
|
|
||||||
<input type="hidden" name="offset" value="{{.Offset}}"/>
|
|
||||||
<div>
|
|
||||||
<label for="field_subject">Subject:</label>
|
|
||||||
<input type="text" name="subject" id="field_subject" value="{{.EditUser.Subject}}" required/>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label for="field_roles">Roles:</label>
|
|
||||||
<input type="text" name="roles" id="field_roles" value="{{.EditUser.Roles}}" size="100"/>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label for="field_active">Active: <input type="checkbox" name="active" id="field_active" checked/></label>
|
|
||||||
</div>
|
|
||||||
<button type="submit">Edit</button>
|
|
||||||
</form>
|
|
||||||
<form method="GET" action="/manage/users">
|
|
||||||
<input type="hidden" name="offset" value="{{.Offset}}"/>
|
|
||||||
<button type="submit">Cancel</button>
|
|
||||||
</form>
|
|
||||||
{{else}}
|
|
||||||
<h2>Manage Users</h2>
|
<h2>Manage Users</h2>
|
||||||
{{if eq (len .Users) 0}}
|
{{if eq (len .Users) 0}}
|
||||||
<div>No users found, this is definitely a bug.</div>
|
<div>No users found, this is definitely a bug.</div>
|
||||||
@ -89,7 +66,6 @@
|
|||||||
<button type="submit">{{if .EmailShow}}Hide Email Addresses{{else}}Show email addresses{{end}}</button>
|
<button type="submit">{{if .EmailShow}}Hide Email Addresses{{else}}Show email addresses{{end}}</button>
|
||||||
</form>
|
</form>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -63,6 +63,25 @@ func (h *HttpServer) ManageAppsGet(rw http.ResponseWriter, req *http.Request, _
|
|||||||
pages.RenderPageTemplate(rw, "manage-apps", m)
|
pages.RenderPageTemplate(rw, "manage-apps", m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *HttpServer) ManageAppsCreateGet(rw http.ResponseWriter, _ *http.Request, _ httprouter.Params, auth UserAuth) {
|
||||||
|
var roles string
|
||||||
|
if h.DbTx(rw, func(tx *database.Tx) (err error) {
|
||||||
|
roles, err = tx.GetUserRoles(auth.Subject)
|
||||||
|
return
|
||||||
|
}) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
m := map[string]any{
|
||||||
|
"ServiceName": h.conf.ServiceName,
|
||||||
|
"IsAdmin": HasRole(roles, "lavender:admin"),
|
||||||
|
}
|
||||||
|
|
||||||
|
rw.Header().Set("Content-Type", "text/html")
|
||||||
|
rw.WriteHeader(http.StatusOK)
|
||||||
|
pages.RenderPageTemplate(rw, "manage-apps-create", m)
|
||||||
|
}
|
||||||
|
|
||||||
func (h *HttpServer) ManageAppsPost(rw http.ResponseWriter, req *http.Request, _ httprouter.Params, auth UserAuth) {
|
func (h *HttpServer) ManageAppsPost(rw http.ResponseWriter, req *http.Request, _ httprouter.Params, auth UserAuth) {
|
||||||
err := req.ParseForm()
|
err := req.ParseForm()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -152,6 +152,7 @@ func NewHttpServer(conf Conf, db *database.DB, signingKey mjwt.Signer) *http.Ser
|
|||||||
|
|
||||||
// management pages
|
// management pages
|
||||||
r.GET("/manage/apps", hs.RequireAuthentication(hs.ManageAppsGet))
|
r.GET("/manage/apps", hs.RequireAuthentication(hs.ManageAppsGet))
|
||||||
|
r.GET("/manage/apps/create", hs.RequireAuthentication(hs.ManageAppsCreateGet))
|
||||||
r.POST("/manage/apps", hs.RequireAuthentication(hs.ManageAppsPost))
|
r.POST("/manage/apps", hs.RequireAuthentication(hs.ManageAppsPost))
|
||||||
r.GET("/manage/users", hs.RequireAdminAuthentication(hs.ManageUsersGet))
|
r.GET("/manage/users", hs.RequireAdminAuthentication(hs.ManageUsersGet))
|
||||||
r.POST("/manage/users", hs.RequireAdminAuthentication(hs.ManageUsersPost))
|
r.POST("/manage/users", hs.RequireAdminAuthentication(hs.ManageUsersPost))
|
||||||
|
Loading…
Reference in New Issue
Block a user