mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-03 03:46:30 +01:00
started work on admin registration logic
This commit is contained in:
15
admin.php
15
admin.php
@@ -153,13 +153,6 @@ class AdminPlugin extends Plugin
|
||||
$this->session->expert = false;
|
||||
}
|
||||
|
||||
// check for existence of a user account
|
||||
$account_dir = $file_path = $this->grav['locator']->findResource('account://');
|
||||
$user_check = (array) glob($account_dir . '/*.yaml');
|
||||
if (!count($user_check) > 0) {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.NO_USER_ACCOUNTS'), 'info');
|
||||
}
|
||||
|
||||
/** @var Pages $pages */
|
||||
$pages = $this->grav['pages'];
|
||||
|
||||
@@ -402,6 +395,14 @@ class AdminPlugin extends Plugin
|
||||
$path = trim(substr($this->uri->route(), strlen($this->base)), '/');
|
||||
$this->template = 'dashboard';
|
||||
|
||||
// check for existence of a user account
|
||||
$account_dir = $file_path = $this->grav['locator']->findResource('account://');
|
||||
$user_check = (array) glob($account_dir . '/*.yaml');
|
||||
if (!count($user_check) > 0) {
|
||||
// $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.NO_USER_ACCOUNTS'), 'info');
|
||||
$this->template = 'register';
|
||||
}
|
||||
|
||||
if ($path) {
|
||||
$array = explode('/', $path, 2);
|
||||
$this->template = array_shift($array);
|
||||
|
||||
58
pages/admin/register.md
Normal file
58
pages/admin/register.md
Normal file
@@ -0,0 +1,58 @@
|
||||
---
|
||||
form:
|
||||
fields:
|
||||
-
|
||||
name: username
|
||||
type: text
|
||||
placeholder: "Choose a username"
|
||||
validate:
|
||||
required: true
|
||||
|
||||
-
|
||||
name: title
|
||||
type: text
|
||||
placeholder: "Enter a title"
|
||||
|
||||
-
|
||||
name: email
|
||||
type: text
|
||||
placeholder: "Enter your email"
|
||||
validate:
|
||||
required: true
|
||||
|
||||
-
|
||||
name: password1
|
||||
type: password
|
||||
placeholder: Enter password
|
||||
validate:
|
||||
required: true
|
||||
|
||||
-
|
||||
name: password2
|
||||
type: password
|
||||
placeholder: Confirm password
|
||||
validate:
|
||||
required: true
|
||||
|
||||
|
||||
buttons:
|
||||
-
|
||||
type: submit
|
||||
value: Submit
|
||||
-
|
||||
type: reset
|
||||
value: Reset
|
||||
|
||||
process:
|
||||
register_user:
|
||||
fields:
|
||||
access: ['site.login']
|
||||
state: 'enabled'
|
||||
options:
|
||||
validate_password1_and_password2: true
|
||||
login_after_registration: true
|
||||
|
||||
message: "You are logged in"
|
||||
---
|
||||
|
||||
# Register
|
||||
@@ -1,4 +1,4 @@
|
||||
{% embed 'partials/login.html.twig' with {title:'Grav Login'} %}
|
||||
{% embed 'partials/login.html.twig' with {title:'Grav Admin Login'} %}
|
||||
|
||||
{% block form %}
|
||||
{% for field in page.header.form.fields %}
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
{% include 'partials/messages.html.twig' %}
|
||||
|
||||
{% block instructions %}{% endblock %}
|
||||
|
||||
<form method="post" action="{{ base_url_relative }}">
|
||||
{% block form %}{% endblock %}
|
||||
|
||||
|
||||
31
themes/grav/templates/register.html.twig
Normal file
31
themes/grav/templates/register.html.twig
Normal file
@@ -0,0 +1,31 @@
|
||||
{% embed 'partials/login.html.twig' with {title:'Grav Register Admin User'} %}
|
||||
|
||||
{% block instructions %}
|
||||
<p>No users found, you will need to register an account...</p>
|
||||
{% endblock %}
|
||||
|
||||
{% block form %}
|
||||
{% for field in page.header.form.fields %}
|
||||
{% if field.type %}
|
||||
<div>
|
||||
{% include ["forms/fields/#{field.type}/#{field.type}.html.twig", 'forms/fields/text/text.html.twig'] %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
<div class="form-actions secondary-accent">
|
||||
{% if notAuthorized %}
|
||||
<a class="button secondary" onclick="window.history.back()"><i class="fa fa-reply"></i> {{ 'PLUGIN_ADMIN.BACK'|tu }}</a>
|
||||
{% else %}
|
||||
{% if not authenticated %}
|
||||
<a class="button secondary" href="{{ base_url_relative }}/forgot"><i class="fa fa-exclamation-circle"></i> {{ 'PLUGIN_ADMIN.LOGIN_BTN_FORGOT'|tu }}</a>
|
||||
<button type="submit" class="button primary" name="task" value="login"><i class="fa fa-sign-in"></i> {{ 'PLUGIN_ADMIN.LOGIN_BTN'|tu }}</button>
|
||||
{% else %}
|
||||
<button type="submit" class="button primary" name="task" value="logout"><i class="fa fa-sign-in"></i> {{ 'PLUGIN_ADMIN.LOGOUT'|tu }}</button>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% endembed %}
|
||||
Reference in New Issue
Block a user