High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.
JavaScript campaigncampaign-managementemail-marketingemail-subscriptionlistmonkmailing-listnewsletternewsletter-managementnewsletter-softwareself-hostedsms-gatewaysmtptransactional-emails
{{ define "admin-user" -}}
{{ template "admin-header" . }}
{{- $crumbTitle := .L.T "users.newUser" -}}
{{- if not .Data.IsNew }}{{ $crumbTitle = (or .Data.User.Name .Data.User.Username) }}{{ end -}}
{{ template "breadcrumbs" dict "Root" . "Current" $crumbTitle "Parents" (list (dict "Label" (.L.T "globals.terms.users") "URL" (URI "/admin/users") "CanLink" (.Data.Can "users:get"))) }}
{{- $d := .Data -}}
{{- $canSave := $d.Can "users:manage" -}}
<script>
window._user = {{ ToJSON $d.User }};
window._userRoles = {{ ToJSON $d.UserRoles }};
</script>
<section class="users" x-data="userForm({ isNew: {{ $d.IsNew }}, canSave: {{ $canSave }} })">
<header class="page-header">
<div class="hstack gap-1">
<div class="avatar avatar-title{{ if eq $d.User.Status "disabled" }} disabled{{ end }}">
{{- if not $d.IsNew }}{{ template "avatar-icon" dict "Kind" "user" "Name" (or $d.User.Name $d.User.Username) "URL" $d.User.Avatar.String "Href" (printf "%s/%d" (URI "/admin/users") $d.User.ID) "Title" (printf "%s %s" ($.L.T "globals.buttons.view") (or $d.User.Name $d.User.Username)) }}{{ end }}
<h1 class="page-title avatar-label">
{{- if not $d.IsNew }}{{ or $d.User.Name $d.User.Username }}{{ else }}{{ .L.T "users.newUser" }}{{ end -}}
</h1>
</div>
{{- if and (not $d.IsNew) (eq $d.User.Status "disabled") }}{{ Badge (list (Dot) ($.L.T "globals.terms.disabled")) "enum status-disabled" }}{{ end }}
</div>
</header>
<form method="post" @submit.prevent="onSubmit">
<div class="page-content content">
<section>
<fieldset class="card">
<legend>{{ .L.T "globals.terms.profile" }}</legend>
<div data-field>
<label for="user-type">{{ .L.T "globals.fields.type" }}</label>
<select name="type" id="user-type" autofocus x-model="form.type" :disabled="!isNew">
<option value="user">{{ .L.T "users.type.user" }}</option>
<option value="api">{{ .L.T "users.type.api" }}</option>
</select>
</div>
<label data-field>
{{ .L.T "globals.fields.username" }}
<input name="username" maxlength="200" required autocomplete="off" pattern="[a-zA-Z0-9_\-\.@]+$" autofocus x-model="form.username" />
<small data-hint>{{ .L.T "users.usernameHelp" }}</small>
</label>
<label data-field>
{{ .L.T "globals.fields.name" }}
<input name="name" maxlength="200" x-model="form.name" />
</label>
<template x-if="form.type !== 'api'">
<label data-field>
{{ .L.T "globals.fields.email" }}
<input name="email" type="email" maxlength="200" required x-model="form.email" />
</label>
</template>
<div data-field>
<label for="user-status">{{ .L.T "globals.fields.status" }}</label>
<select name="status" id="user-status" required x-model="form.status">
<option value="enabled">{{ .L.T "globals.terms.enabled" }}</option>
<option value="disabled">{{ .L.T "globals.terms.disabled" }}</option>
</select>
</div>
</fieldset>
<template x-if="form.type !== 'api'">
<fieldset class="card">
<legend>{{ .L.T "globals.fields.password" }}</legend>
<label data-field>
<input type="checkbox" x-model="form.password_login" data-testid="password-login" /> {{ .L.T "users.passwordEnable" }}
</label>
<label data-field>
{{ .L.T "globals.fields.password" }}
<input type="password" name="password" minlength="8" maxlength="200" autocomplete="new-password" :disabled="!form.password_login" :required="form.password_login && isNew" x-model="form.password" />
</label>
<label data-field>
{{ .L.T "globals.fields.passwordRepeat" }}
<input type="password" name="password2" minlength="8" maxlength="200" autocomplete="new-password" :disabled="!form.password_login" :required="form.password_login && isNew && form.password" x-model="form.password2" />
</label>
</fieldset>
</template>
<fieldset class="card">
<legend>{{ .L.Tc "globals.terms.roles" 2 }}</legend>
<div data-field>
<label for="user-role">{{ .L.Tc "users.userRole" 1 }}</label>
<select name="user_role" id="user-role" required x-model.number="form.user_role_id">
{{- range $d.UserRoles }}
<option value="{{ .ID }}">{{ .Name.String }}</option>
{{- end }}
</select>
</div>
<div data-field>
<label for="list-role">{{ .L.Tc "users.listRole" 2 }}</label>
<select name="list_role" id="list-role" x-model="form.list_role_id">
<option value="">— {{ .L.T "globals.terms.none" }} —</option>
{{- range $d.ListRoles }}
<option value="{{ .ID }}">{{ .Name.String }}</option>
{{- end }}
</select>
</div>
</fieldset>
</section>
<footer class="hstack justify-between mt-6">
<div class="hstack gap-1">
{{- if not $d.IsNew }}
<button type="button" class="small" data-variant="secondary" title="{{ .L.T "globals.messages.clickToCopy" }}" aria-label="{{ .L.T "globals.fields.id" }}" @click="copyToClipboard(form.id)">
<strong>{{ .L.T "globals.fields.id" }}</strong> <span x-text="form.id"></span>
</button>
{{- end }}
</div>
<div class="hstack gap-3 justify-end">
{{- if $canSave }}
<button type="submit" data-variant="primary" data-testid="btn-save" :disabled="isLoading('users.save')" :aria-busy="isLoading('users.save')">{{ .L.T "globals.buttons.save" }}</button>
{{- end }}
</div>
</footer>
</div>
</form>
{{- if $canSave }}
<dialog x-ref="tokenDialog" @close="onTokenDialogClose">
<div class="dialog-card content">
<header class="dialog-head">
<h4 class="dialog-title">{{ .L.T "users.type.api" }}</h4>
</header>
<section class="dialog-body">
<p class="text-light">{{ .L.T "users.apiOneTimeToken" }}</p>
<button type="button" class="w-100" data-variant="secondary" title="{{ .L.T "globals.messages.clickToCopy" }}" @click="copyToClipboard(apiToken)">
<span x-text="apiToken"></span> {{ Icon "copy" }}
</button>
</section>
<footer class="dialog-foot align-right">
<button type="button" data-variant="primary" @click="$refs.tokenDialog.close()">{{ .L.T "globals.buttons.close" }}</button>
</footer>
</div>
</dialog>
{{- end }}
</section>
<script type="module" src="{{ URI "/admin/static/js/views/users.js" }}?v={{ .AssetVersion }}" defer></script>
{{ template "admin-footer" . -}}
{{ end }}