Use 4 spaces as tab and reformat
This commit is contained in:
parent
b541d33671
commit
70e48783b8
28 changed files with 382 additions and 328 deletions
6
.editorconfig
Normal file
6
.editorconfig
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[*]
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
charset = utf-8
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
18
README.md
18
README.md
|
@ -1,6 +1,7 @@
|
||||||
# README #
|
# README #
|
||||||
|
|
||||||
A simple webinterface for users. This app uses [`admin_rest`](https://github.com/snowblindroan/mod_admin_rest) module of prosody. So [prosody.im](http://prosody.im) and this module are hard dependencies. The interface allows users
|
A simple webinterface for users. This app uses [`admin_rest`](https://github.com/snowblindroan/mod_admin_rest) module of
|
||||||
|
prosody. So [prosody.im](http://prosody.im) and this module are hard dependencies. The interface allows users
|
||||||
|
|
||||||
* to have two step verification (as an alternative to the integrated `register_web` module),
|
* to have two step verification (as an alternative to the integrated `register_web` module),
|
||||||
* to delete of their accounts and
|
* to delete of their accounts and
|
||||||
|
@ -38,7 +39,8 @@ as dependencies.
|
||||||
|
|
||||||
## Deployment ##
|
## Deployment ##
|
||||||
|
|
||||||
* Set up a cron job using `php projectRootDir/bin/UsersAwaitingVerificationCleanUpCronJob.php` to clean up users who signed up but did not verify their account periodically.
|
* Set up a cron job using `php projectRootDir/bin/UsersAwaitingVerificationCleanUpCronJob.php` to clean up users who
|
||||||
|
signed up but did not verify their account periodically.
|
||||||
* Point your document root to `public/`.
|
* Point your document root to `public/`.
|
||||||
* Example nginx conf:
|
* Example nginx conf:
|
||||||
|
|
||||||
|
@ -75,13 +77,17 @@ You should be able to set a very strict Content-Security-Policy.
|
||||||
* look into Changelog for major changes
|
* look into Changelog for major changes
|
||||||
|
|
||||||
## Developers ##
|
## Developers ##
|
||||||
|
|
||||||
* start server with `php -S localhost:8080 -t public public/index.php`
|
* start server with `php -S localhost:8080 -t public public/index.php`
|
||||||
* point browser to [localhost:8080](http://localhost:8080) to have a preview
|
* point browser to [localhost:8080](http://localhost:8080) to have a preview
|
||||||
|
|
||||||
## Translations ##
|
## Translations ##
|
||||||
This app uses Symfony Translator. It's bootstraped in `Util\BootstrapHelper` and locales are placed under `data/locale/`. Adjust to your needs or help translating.
|
|
||||||
|
This app uses Symfony Translator. It's bootstraped in `Util\BootstrapHelper` and locales are placed under `data/locale/`
|
||||||
|
. Adjust to your needs or help translating.
|
||||||
|
|
||||||
## Changelog ##
|
## Changelog ##
|
||||||
|
|
||||||
- 0.3.0.1
|
- 0.3.0.1
|
||||||
- Remove cookie consent as session cookies should be allowed because they provide core functionality
|
- Remove cookie consent as session cookies should be allowed because they provide core functionality
|
||||||
- Adjust `legal.example.md` and add `PHPSESSID`
|
- Adjust `legal.example.md` and add `PHPSESSID`
|
||||||
|
@ -120,7 +126,9 @@ This app uses Symfony Translator. It's bootstraped in `Util\BootstrapHelper` and
|
||||||
- added admin notifications
|
- added admin notifications
|
||||||
- added possibility for users to delete their account
|
- added possibility for users to delete their account
|
||||||
- added back index page
|
- added back index page
|
||||||
- works with mod_admin_rest version [afc42d7](https://github.com/snowblindroan/mod_admin_rest/commit/afc42d70f0aceb2351a1bc786d61e3f4dbdfb948)
|
- works with mod_admin_rest
|
||||||
|
version [afc42d7](https://github.com/snowblindroan/mod_admin_rest/commit/afc42d70f0aceb2351a1bc786d61e3f4dbdfb948)
|
||||||
- 0.1:
|
- 0.1:
|
||||||
- initial release
|
- initial release
|
||||||
- works with mod_admin_rest version [afc42d7](https://github.com/snowblindroan/mod_admin_rest/commit/afc42d70f0aceb2351a1bc786d61e3f4dbdfb948)
|
- works with mod_admin_rest
|
||||||
|
version [afc42d7](https://github.com/snowblindroan/mod_admin_rest/commit/afc42d70f0aceb2351a1bc786d61e3f4dbdfb948)
|
||||||
|
|
|
@ -9,7 +9,7 @@ class Config
|
||||||
// no need to change anything here
|
// no need to change anything here
|
||||||
'db_settings' => [
|
'db_settings' => [
|
||||||
'driver' => 'sqlite',
|
'driver' => 'sqlite',
|
||||||
'database' => __DIR__ . DIRECTORY_SEPARATOR . '..'. DIRECTORY_SEPARATOR .'data'. DIRECTORY_SEPARATOR .'db.sqlite',
|
'database' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'db.sqlite',
|
||||||
'charset' => 'utf8',
|
'charset' => 'utf8',
|
||||||
'collation' => 'utf8_unicode_ci',
|
'collation' => 'utf8_unicode_ci',
|
||||||
'prefix' => '',
|
'prefix' => '',
|
||||||
|
@ -21,13 +21,13 @@ class Config
|
||||||
],
|
],
|
||||||
|
|
||||||
'twig_settings' => [
|
'twig_settings' => [
|
||||||
'twig_dir' => __DIR__ . DIRECTORY_SEPARATOR . '..'. DIRECTORY_SEPARATOR .'src'. DIRECTORY_SEPARATOR .'View',
|
'twig_dir' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'View',
|
||||||
'twig_cache_dir' => false,
|
'twig_cache_dir' => false,
|
||||||
//'twig_cache_dir' => __DIR__ . DIRECTORY_SEPARATOR . '..'. DIRECTORY_SEPARATOR .'src'. DIRECTORY_SEPARATOR .'cache',
|
//'twig_cache_dir' => __DIR__ . DIRECTORY_SEPARATOR . '..'. DIRECTORY_SEPARATOR .'src'. DIRECTORY_SEPARATOR .'cache',
|
||||||
],
|
],
|
||||||
|
|
||||||
'logger_settings' => [
|
'logger_settings' => [
|
||||||
'path' => __DIR__ . DIRECTORY_SEPARATOR . '..'. DIRECTORY_SEPARATOR .'log'. DIRECTORY_SEPARATOR .'application.log',
|
'path' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR . 'application.log',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
|
@ -13,19 +13,28 @@ Contact data
|
||||||
|
|
||||||
## Cookies
|
## Cookies
|
||||||
|
|
||||||
This website uses small files called cookies to help the operator customise your experience. Cookies are small text files that are stored by the browser on your device. They allow websites to store things like user preferences. Functionality might be affected if you disable cookies for this website.
|
This website uses small files called cookies to help the operator customise your experience. Cookies are small text
|
||||||
|
files that are stored by the browser on your device. They allow websites to store things like user preferences.
|
||||||
|
Functionality might be affected if you disable cookies for this website.
|
||||||
|
|
||||||
These cookies are essential to the proper functioning of our website and enable you to use its features, such as accessing secure areas of the site. Without these cookies, you will not be able to perform core site functions such as logging in.
|
These cookies are essential to the proper functioning of our website and enable you to use its features, such as
|
||||||
|
accessing secure areas of the site. Without these cookies, you will not be able to perform core site functions such as
|
||||||
|
logging in.
|
||||||
|
|
||||||
| Cookiename | Provider | Purpose |
|
| Cookiename | Provider | Purpose |
|
||||||
|:------------------:|:-----------:|:---------|
|
|:------------------:|:-----------:|:---------|
|
||||||
| `PHPSESSID` | Provider | Creates a unique session for your device, allowing a platform for login. No personal or device information is collected or stored. If you login, you will be given access to parts of the site for registered members. If you close your browser or end your browser session, this cookie will be deleted automatically. |
|
| `PHPSESSID` | Provider | Creates a unique session for your device, allowing a platform for login. No personal or device information is collected or stored. If you login, you will be given access to parts of the site for registered members. If you close your browser or end your browser session, this cookie will be deleted automatically. |
|
||||||
|
|
||||||
## Registration
|
## Registration
|
||||||
Registration: An email is stored (maximal: 7 days, typical: deleted after verification process is completed) and credentials (minimal: stored as long as the account exists, typical: check user JID against well-known spammer patterns) are stored.
|
|
||||||
|
Registration: An email is stored (maximal: 7 days, typical: deleted after verification process is completed) and
|
||||||
|
credentials (minimal: stored as long as the account exists, typical: check user JID against well-known spammer patterns)
|
||||||
|
are stored.
|
||||||
|
|
||||||
## Log
|
## Log
|
||||||
Access logs are not stored except for fixing bugs in case of an error or an attack on this service. Logs will be removed once the [log rotates](https://en.wikipedia.org/wiki/Log_rotation) within 7 days.
|
|
||||||
|
Access logs are not stored except for fixing bugs in case of an error or an attack on this service. Logs will be removed
|
||||||
|
once the [log rotates](https://en.wikipedia.org/wiki/Log_rotation) within 7 days.
|
||||||
|
|
||||||
# Service
|
# Service
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use \Phpmig\Adapter;
|
use Phpmig\Adapter;
|
||||||
|
|
||||||
$container = new ArrayObject();
|
$container = new ArrayObject();
|
||||||
$container['env'] = BootstrapHelper::bootEnvironment();
|
$container['env'] = BootstrapHelper::bootEnvironment();
|
||||||
|
@ -8,8 +8,8 @@ $container['db'] = BootstrapHelper::bootDatabase();
|
||||||
|
|
||||||
$container['phpmig.adapter'] = new Phpmig\Adapter\PDO\Sql($container['db']->getConnection()->getPdo(), 'migrations');
|
$container['phpmig.adapter'] = new Phpmig\Adapter\PDO\Sql($container['db']->getConnection()->getPdo(), 'migrations');
|
||||||
|
|
||||||
$container['phpmig.migrations_template_path'] = __DIR__ . DIRECTORY_SEPARATOR . '..'. DIRECTORY_SEPARATOR .'data'. DIRECTORY_SEPARATOR .'phpmig_template.php';
|
$container['phpmig.migrations_template_path'] = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'phpmig_template.php';
|
||||||
$container['phpmig.migrations_path'] = __DIR__ . DIRECTORY_SEPARATOR . '..'. DIRECTORY_SEPARATOR .'data'. DIRECTORY_SEPARATOR .'migrations';
|
$container['phpmig.migrations_path'] = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'migrations';
|
||||||
|
|
||||||
|
|
||||||
$container['schema'] = $container['db']->schema();
|
$container['schema'] = $container['db']->schema();
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Phpmig\Migration\Migration;
|
use Phpmig\Migration\Migration;
|
||||||
|
|
||||||
class UsersAwaitingVerificationTable extends Migration
|
class UsersAwaitingVerificationTable extends Migration
|
||||||
|
@ -11,7 +12,7 @@ class UsersAwaitingVerificationTable extends Migration
|
||||||
*/
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
$this->db->create($this->tableName, function($table) {
|
$this->db->create($this->tableName, function ($table) {
|
||||||
$table->increments('id');
|
$table->increments('id');
|
||||||
$table->string('username');
|
$table->string('username');
|
||||||
$table->string('email')->unique();
|
$table->string('email')->unique();
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Phpmig\Migration\Migration;
|
use Phpmig\Migration\Migration;
|
||||||
|
|
||||||
class UsersRegisteredTable extends Migration
|
class UsersRegisteredTable extends Migration
|
||||||
|
@ -11,7 +12,7 @@ class UsersRegisteredTable extends Migration
|
||||||
*/
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
$this->db->create($this->tableName, function($table) {
|
$this->db->create($this->tableName, function ($table) {
|
||||||
$table->string('username')->unique()->primary();
|
$table->string('username')->unique()->primary();
|
||||||
$table->string('delete_code', 64);
|
$table->string('delete_code', 64);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,35 +1,35 @@
|
||||||
<?= "<?php ";?>
|
<?= "<?php "; ?>
|
||||||
|
|
||||||
use Phpmig\Migration\Migration;
|
use Phpmig\Migration\Migration;
|
||||||
|
|
||||||
class <?= $className ?> extends Migration
|
class <?= $className ?> extends Migration
|
||||||
{
|
{
|
||||||
public $tableName = ''; // Table name
|
public $tableName = ''; // Table name
|
||||||
public $db;
|
public $db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do the migration
|
* Do the migration
|
||||||
*/
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
$this->db->create($this->tableName, function($table) {
|
$this->db->create($this->tableName, function($table) {
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undo the migration
|
* Undo the migration
|
||||||
*/
|
*/
|
||||||
public function down()
|
public function down()
|
||||||
{
|
{
|
||||||
$this->db->dropIfExists($this->tableName);
|
$this->db->dropIfExists($this->tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init the migration
|
* Init the migration
|
||||||
*/
|
*/
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
$this->db = $this->container['schema'];
|
$this->db = $this->container['schema'];
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,10 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Slim\Flash\Messages;
|
|
||||||
use Slim\Views\Twig;
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Slim\Flash\Messages;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
use Slim\Http\Response;
|
use Slim\Http\Response;
|
||||||
|
use Slim\Views\Twig;
|
||||||
use Symfony\Component\Translation\Translator;
|
use Symfony\Component\Translation\Translator;
|
||||||
|
|
||||||
final class ForbiddenAction
|
final class ForbiddenAction
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Slim\Flash\Messages;
|
|
||||||
use Slim\Views\Twig;
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Slim\Flash\Messages;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
use Slim\Http\Response;
|
use Slim\Http\Response;
|
||||||
|
use Slim\Views\Twig;
|
||||||
use Symfony\Component\Translation\Translator;
|
use Symfony\Component\Translation\Translator;
|
||||||
|
|
||||||
final class HomeAction
|
final class HomeAction
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Slim\Flash\Messages;
|
|
||||||
use Slim\Views\Twig;
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Slim\Flash\Messages;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
use Slim\Http\Response;
|
use Slim\Http\Response;
|
||||||
|
use Slim\Views\Twig;
|
||||||
use Symfony\Component\Translation\Translator;
|
use Symfony\Component\Translation\Translator;
|
||||||
|
|
||||||
final class InternalApplicationError
|
final class InternalApplicationError
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use JeremyKendall\Slim\Auth\Authenticator;
|
use JeremyKendall\Slim\Auth\Authenticator;
|
||||||
use Slim\Flash\Messages;
|
|
||||||
use Slim\Views\Twig;
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Slim\Flash\Messages;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
use Slim\Http\Response;
|
use Slim\Http\Response;
|
||||||
|
use Slim\Views\Twig;
|
||||||
use Symfony\Component\Translation\Translator;
|
use Symfony\Component\Translation\Translator;
|
||||||
|
|
||||||
final class LoginAction
|
final class LoginAction
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use JeremyKendall\Slim\Auth\Authenticator;
|
use JeremyKendall\Slim\Auth\Authenticator;
|
||||||
use Slim\Flash\Messages;
|
|
||||||
use Slim\Views\Twig;
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Slim\Flash\Messages;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
use Slim\Http\Response;
|
use Slim\Http\Response;
|
||||||
|
use Slim\Views\Twig;
|
||||||
use Symfony\Component\Translation\Translator;
|
use Symfony\Component\Translation\Translator;
|
||||||
|
|
||||||
final class LogoutAction
|
final class LogoutAction
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Slim\Flash\Messages;
|
|
||||||
use Slim\Views\Twig;
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Slim\Flash\Messages;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
use Slim\Http\Response;
|
use Slim\Http\Response;
|
||||||
|
use Slim\Views\Twig;
|
||||||
use Symfony\Component\Translation\Translator;
|
use Symfony\Component\Translation\Translator;
|
||||||
|
|
||||||
final class NotAuthorizedAction
|
final class NotAuthorizedAction
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Slim\Flash\Messages;
|
|
||||||
use Slim\Views\Twig;
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Slim\Flash\Messages;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
use Slim\Http\Response;
|
use Slim\Http\Response;
|
||||||
|
use Slim\Views\Twig;
|
||||||
use Symfony\Component\Translation\Translator;
|
use Symfony\Component\Translation\Translator;
|
||||||
|
|
||||||
final class NotFoundAction
|
final class NotFoundAction
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Curl\Curl;
|
use Curl\Curl;
|
||||||
use Slim\Flash\Messages;
|
|
||||||
use Slim\Interfaces\RouterInterface;
|
|
||||||
use Slim\Views\Twig;
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Slim\Flash\Messages;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
use Slim\Http\Response;
|
use Slim\Http\Response;
|
||||||
|
use Slim\Interfaces\RouterInterface;
|
||||||
|
use Slim\Views\Twig;
|
||||||
use Symfony\Component\Translation\Translator;
|
use Symfony\Component\Translation\Translator;
|
||||||
|
|
||||||
final class SignUpAction
|
final class SignUpAction
|
||||||
|
@ -109,7 +109,7 @@ final class SignUpAction
|
||||||
$verificationLink = $request->getUri()->getScheme();
|
$verificationLink = $request->getUri()->getScheme();
|
||||||
$verificationLink .= '://';
|
$verificationLink .= '://';
|
||||||
$verificationLink .= $request->getUri()->getHost();
|
$verificationLink .= $request->getUri()->getHost();
|
||||||
$verificationLink .= (!empty($p = $request->getUri()->getPort()) ? ':' .$p : '');
|
$verificationLink .= (!empty($p = $request->getUri()->getPort()) ? ':' . $p : '');
|
||||||
$verificationLink .= $this->router->pathFor('verification', ['verificationCode' => $userAwaiting->verification_code]);
|
$verificationLink .= $this->router->pathFor('verification', ['verificationCode' => $userAwaiting->verification_code]);
|
||||||
|
|
||||||
$mailer->Subject = $this->translator->trans('verification.mail.subject', ['%server%' => getenv('site_xmpp_server_displayname')]);
|
$mailer->Subject = $this->translator->trans('verification.mail.subject', ['%server%' => getenv('site_xmpp_server_displayname')]);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class UserAwaitingVerification extends Model
|
class UserAwaitingVerification extends Model
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class UserRegistered extends Model
|
class UserRegistered extends Model
|
||||||
|
|
|
@ -13,59 +13,110 @@ class ValidationHelper extends GUMP
|
||||||
$this->translator = BootstrapHelper::bootTranslator();
|
$this->translator = BootstrapHelper::bootTranslator();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Validates if $field content is equal to $param
|
/**
|
||||||
* @param $field
|
* Perform data validation against the provided ruleset
|
||||||
* @param $input
|
*
|
||||||
* @param $param
|
* Arrays as FIELDS are added here as a custom feature
|
||||||
* @return bool
|
*
|
||||||
|
* @access public
|
||||||
|
* @param mixed $input
|
||||||
|
* @param array $ruleset
|
||||||
|
* @return mixed
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
protected function validate_equals($field, $input, $param)
|
public function validate(array $input, array $ruleset)
|
||||||
{
|
{
|
||||||
$err = [
|
$this->errors = [];
|
||||||
'field' => $field,
|
|
||||||
'value' => $input[$field],
|
|
||||||
'rule' => __FUNCTION__,
|
|
||||||
'param' => $param,
|
|
||||||
];
|
|
||||||
|
|
||||||
if (!isset($input[$field]) || empty($input[$field]) || empty($param) || !isset($param)) {
|
foreach ($ruleset as $field => $rules) {
|
||||||
return $err;
|
#if(!array_key_exists($field, $input))
|
||||||
|
#{
|
||||||
|
# continue;
|
||||||
|
#}
|
||||||
|
|
||||||
|
$rules = explode('|', $rules);
|
||||||
|
|
||||||
|
if (in_array("required", $rules) || (isset($input[$field]) && (is_array($input[$field]) || trim($input[$field]) != ''))) {
|
||||||
|
|
||||||
|
foreach ($rules as $rule) {
|
||||||
|
$method = NULL;
|
||||||
|
$param = NULL;
|
||||||
|
|
||||||
|
if (strstr($rule, ',') !== false) // has params
|
||||||
|
{
|
||||||
|
$rule = explode(',', $rule);
|
||||||
|
$method = 'validate_' . $rule[0];
|
||||||
|
$param = $rule[1];
|
||||||
|
$rule = $rule[0];
|
||||||
|
} else {
|
||||||
|
$method = 'validate_' . $rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($input[$field] != $param || $input[$field] !== $param) {
|
// array required
|
||||||
return $err;
|
if ($rule === "required" && !isset($input[$field])) {
|
||||||
|
$result = $this->$method($field, $input, $param);
|
||||||
|
$this->errors[] = $result;
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
if (is_callable([$this, $method])) {
|
||||||
|
$result = $this->$method($field, $input, $param);
|
||||||
|
|
||||||
|
if (is_array($result)) // Validation Failed
|
||||||
|
{
|
||||||
|
$this->errors[] = $result;
|
||||||
|
|
||||||
|
return $this->errors;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (isset(self::$validation_methods[$rule])) {
|
||||||
|
if (isset($input[$field])) {
|
||||||
|
$result = call_user_func(self::$validation_methods[$rule], $field, $input, $param);
|
||||||
|
|
||||||
|
$result = $this->$method($field, $input, $param);
|
||||||
|
|
||||||
|
if (is_array($result)) // Validation Failed
|
||||||
|
{
|
||||||
|
$this->errors[] = $result;
|
||||||
|
|
||||||
|
return $this->errors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new \Exception("Validator method '$method' does not exist.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (count($this->errors) > 0) ? $this->errors : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function filter_upper($value, $param = NULL)
|
||||||
|
{
|
||||||
|
return strtoupper($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function filter_lower($value, $param = NULL)
|
||||||
|
{
|
||||||
|
return strtolower($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates if array has min size, defaults to size = 1
|
* Converts all error array into a single string
|
||||||
* @param $field
|
* @return void
|
||||||
* @param $input
|
|
||||||
* @param null $param
|
|
||||||
* @return array|bool
|
|
||||||
*/
|
*/
|
||||||
protected function validate_set_min_len($field, $input, $param = NULL)
|
public function addErrorsToFlashMessage($flash)
|
||||||
{
|
{
|
||||||
|
$errors = $this->get_errors_array(true);
|
||||||
|
|
||||||
$err = [
|
if (!empty($errors)) {
|
||||||
'field' => $field,
|
foreach ($errors as $error) {
|
||||||
'value' => $input[$field],
|
$flash->addMessage('error', $error);
|
||||||
'rule' => __FUNCTION__,
|
}
|
||||||
'param' => $param,
|
|
||||||
];
|
|
||||||
|
|
||||||
if (!is_array($input[$field])) {
|
|
||||||
return $err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// default value
|
|
||||||
if (empty($param)) $param = 1;
|
|
||||||
|
|
||||||
if (count($input[$field]) < $param) return $err;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -179,109 +230,58 @@ class ValidationHelper extends GUMP
|
||||||
return $resp;
|
return $resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Validates if $field content is equal to $param
|
||||||
* Perform data validation against the provided ruleset
|
* @param $field
|
||||||
*
|
* @param $input
|
||||||
* Arrays as FIELDS are added here as a custom feature
|
* @param $param
|
||||||
*
|
* @return bool
|
||||||
* @access public
|
|
||||||
* @param mixed $input
|
|
||||||
* @param array $ruleset
|
|
||||||
* @return mixed
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
*/
|
||||||
public function validate(array $input, array $ruleset)
|
protected function validate_equals($field, $input, $param)
|
||||||
{
|
{
|
||||||
$this->errors = [];
|
$err = [
|
||||||
|
'field' => $field,
|
||||||
|
'value' => $input[$field],
|
||||||
|
'rule' => __FUNCTION__,
|
||||||
|
'param' => $param,
|
||||||
|
];
|
||||||
|
|
||||||
foreach ($ruleset as $field => $rules) {
|
if (!isset($input[$field]) || empty($input[$field]) || empty($param) || !isset($param)) {
|
||||||
#if(!array_key_exists($field, $input))
|
return $err;
|
||||||
#{
|
|
||||||
# continue;
|
|
||||||
#}
|
|
||||||
|
|
||||||
$rules = explode('|', $rules);
|
|
||||||
|
|
||||||
if (in_array("required", $rules) || (isset($input[$field]) && (is_array($input[$field]) || trim($input[$field]) != ''))) {
|
|
||||||
|
|
||||||
foreach ($rules as $rule) {
|
|
||||||
$method = NULL;
|
|
||||||
$param = NULL;
|
|
||||||
|
|
||||||
if (strstr($rule, ',') !== false) // has params
|
|
||||||
{
|
|
||||||
$rule = explode(',', $rule);
|
|
||||||
$method = 'validate_' . $rule[0];
|
|
||||||
$param = $rule[1];
|
|
||||||
$rule = $rule[0];
|
|
||||||
} else {
|
|
||||||
$method = 'validate_' . $rule;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// array required
|
if ($input[$field] != $param || $input[$field] !== $param) {
|
||||||
if ($rule === "required" && !isset($input[$field])) {
|
return $err;
|
||||||
$result = $this->$method($field, $input, $param);
|
|
||||||
$this->errors[] = $result;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_callable([$this, $method])) {
|
return true;
|
||||||
$result = $this->$method($field, $input, $param);
|
|
||||||
|
|
||||||
if (is_array($result)) // Validation Failed
|
|
||||||
{
|
|
||||||
$this->errors[] = $result;
|
|
||||||
|
|
||||||
return $this->errors;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (isset(self::$validation_methods[$rule])) {
|
|
||||||
if (isset($input[$field])) {
|
|
||||||
$result = call_user_func(self::$validation_methods[$rule], $field, $input, $param);
|
|
||||||
|
|
||||||
$result = $this->$method($field, $input, $param);
|
|
||||||
|
|
||||||
if (is_array($result)) // Validation Failed
|
|
||||||
{
|
|
||||||
$this->errors[] = $result;
|
|
||||||
|
|
||||||
return $this->errors;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new \Exception("Validator method '$method' does not exist.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (count($this->errors) > 0) ? $this->errors : true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function filter_upper($value, $param = NULL)
|
|
||||||
{
|
|
||||||
return strtoupper($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function filter_lower($value, $param = NULL)
|
|
||||||
{
|
|
||||||
return strtolower($value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts all error array into a single string
|
* Validates if array has min size, defaults to size = 1
|
||||||
* @return void
|
* @param $field
|
||||||
|
* @param $input
|
||||||
|
* @param null $param
|
||||||
|
* @return array|bool
|
||||||
*/
|
*/
|
||||||
public function addErrorsToFlashMessage($flash)
|
protected function validate_set_min_len($field, $input, $param = NULL)
|
||||||
{
|
{
|
||||||
$errors = $this->get_errors_array(true);
|
|
||||||
|
|
||||||
if (!empty($errors)) {
|
$err = [
|
||||||
foreach ($errors as $error) {
|
'field' => $field,
|
||||||
$flash->addMessage('error', $error);
|
'value' => $input[$field],
|
||||||
}
|
'rule' => __FUNCTION__,
|
||||||
|
'param' => $param,
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!is_array($input[$field])) {
|
||||||
|
return $err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// default value
|
||||||
|
if (empty($param)) $param = 1;
|
||||||
|
|
||||||
|
if (count($input[$field]) < $param) return $err;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,7 +8,9 @@
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label class="col-2 col-form-label" for="username">{% trans %}delete.form.username{% endtrans %}</label>
|
<label class="col-2 col-form-label" for="username">{% trans %}delete.form.username{% endtrans %}</label>
|
||||||
<div class="col-7">
|
<div class="col-7">
|
||||||
<input type="text" id="username" name="username" class="form-control" placeholder="{% trans %}delete.form.username.placeholder{% endtrans %}" value="" autofocus required>
|
<input type="text" id="username" name="username" class="form-control"
|
||||||
|
placeholder="{% trans %}delete.form.username.placeholder{% endtrans %}" value="" autofocus
|
||||||
|
required>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-3">
|
<div class="col-3">
|
||||||
@{{ getenv('site_xmpp_server_displayname') }}
|
@{{ getenv('site_xmpp_server_displayname') }}
|
||||||
|
@ -16,14 +18,19 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label class="col-2 col-form-label" for="delete_code">{% trans %}delete.form.delete_code{% endtrans %}</label>
|
<label class="col-2 col-form-label"
|
||||||
|
for="delete_code">{% trans %}delete.form.delete_code{% endtrans %}</label>
|
||||||
<div class="col-10">
|
<div class="col-10">
|
||||||
<input aria-describedby="help" type="text" id="delete_code" name="delete_code" class="form-control" placeholder="{% trans %}delete.form.delete_code.placeholder{% endtrans %}" value="" autofocus required>
|
<input aria-describedby="help" type="text" id="delete_code" name="delete_code" class="form-control"
|
||||||
<small id="help" class="form-text text-muted">{% trans %}delete.form.delete_code.help{% endtrans %}</small>
|
placeholder="{% trans %}delete.form.delete_code.placeholder{% endtrans %}" value="" autofocus
|
||||||
|
required>
|
||||||
|
<small id="help"
|
||||||
|
class="form-text text-muted">{% trans %}delete.form.delete_code.help{% endtrans %}</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<br/>
|
<br/>
|
||||||
<input class="btn btn-primary" type="submit" name="delete_button" value="{% trans %}delete.form.button{% endtrans %}"/>
|
<input class="btn btn-primary" type="submit" name="delete_button"
|
||||||
|
value="{% trans %}delete.form.button{% endtrans %}"/>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -8,7 +8,9 @@
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label class="col-2 col-form-label" for="username">{% trans %}login.form.username{% endtrans %}</label>
|
<label class="col-2 col-form-label" for="username">{% trans %}login.form.username{% endtrans %}</label>
|
||||||
<div class="col-7">
|
<div class="col-7">
|
||||||
<input class="form-control" type="text" id="username" name="username" placeholder="{% trans %}login.form.username.placeholder{% endtrans %}" value="" autofocus required>
|
<input class="form-control" type="text" id="username" name="username"
|
||||||
|
placeholder="{% trans %}login.form.username.placeholder{% endtrans %}" value="" autofocus
|
||||||
|
required>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-3">
|
<div class="col-3">
|
||||||
@{{ getenv('site_xmpp_server_displayname') }}
|
@{{ getenv('site_xmpp_server_displayname') }}
|
||||||
|
@ -18,11 +20,13 @@
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label class="col-2 col-form-label" for="username">{% trans %}login.form.password{% endtrans %}</label>
|
<label class="col-2 col-form-label" for="username">{% trans %}login.form.password{% endtrans %}</label>
|
||||||
<div class="col-10">
|
<div class="col-10">
|
||||||
<input type="password" id="password" name="password" class="form-control" placeholder="{% trans %}login.form.password.placeholder{% endtrans %}" required>
|
<input type="password" id="password" name="password" class="form-control"
|
||||||
|
placeholder="{% trans %}login.form.password.placeholder{% endtrans %}" required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<br/>
|
<br/>
|
||||||
<input class="btn btn-primary" type="submit" name="login" value="{% trans %}login.form.button{% endtrans %}"/>
|
<input class="btn btn-primary" type="submit" name="login"
|
||||||
|
value="{% trans %}login.form.button{% endtrans %}"/>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -6,19 +6,25 @@
|
||||||
<h1>{{ title }}</h1>
|
<h1>{{ title }}</h1>
|
||||||
|
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label class="col-2 col-form-label" for="password">{% trans %}password.form.password{% endtrans %}</label>
|
<label class="col-2 col-form-label"
|
||||||
|
for="password">{% trans %}password.form.password{% endtrans %}</label>
|
||||||
<div class="col-10">
|
<div class="col-10">
|
||||||
<input type="password" id="password" name="password" class="form-control" placeholder="{% trans %}password.form.password.placeholder{% endtrans %}" required>
|
<input type="password" id="password" name="password" class="form-control"
|
||||||
|
placeholder="{% trans %}password.form.password.placeholder{% endtrans %}" required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label class="col-2 col-form-label" for="password_confirmation">{% trans %}password.form.password_confirmation{% endtrans %}</label>
|
<label class="col-2 col-form-label"
|
||||||
|
for="password_confirmation">{% trans %}password.form.password_confirmation{% endtrans %}</label>
|
||||||
<div class="col-10">
|
<div class="col-10">
|
||||||
<input type="password" id="password_confirmation" name="password_confirmation" class="form-control" placeholder="{% trans %}password.form.password_confirmation.placeholder{% endtrans %}" required>
|
<input type="password" id="password_confirmation" name="password_confirmation" class="form-control"
|
||||||
|
placeholder="{% trans %}password.form.password_confirmation.placeholder{% endtrans %}"
|
||||||
|
required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<br/>
|
<br/>
|
||||||
<input class="btn btn-primary" type="submit" name="password_change" value="{% trans %}password.form.button{% endtrans %}"/>
|
<input class="btn btn-primary" type="submit" name="password_change"
|
||||||
|
value="{% trans %}password.form.button{% endtrans %}"/>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -6,10 +6,13 @@
|
||||||
<h1>{{ title }}</h1>
|
<h1>{{ title }}</h1>
|
||||||
|
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label class="col-2 col-form-label" for="username">{% trans %}sign.up.form.username{% endtrans %}</label>
|
<label class="col-2 col-form-label"
|
||||||
|
for="username">{% trans %}sign.up.form.username{% endtrans %}</label>
|
||||||
|
|
||||||
<div class="col-7">
|
<div class="col-7">
|
||||||
<input type="text" id="username" name="username" class="form-control" placeholder="{% trans %}sign.up.form.username.placeholder{% endtrans %}" value="" autofocus required>
|
<input type="text" id="username" name="username" class="form-control"
|
||||||
|
placeholder="{% trans %}sign.up.form.username.placeholder{% endtrans %}" value="" autofocus
|
||||||
|
required>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-3">
|
<div class="col-3">
|
||||||
@{{ getenv('site_xmpp_server_displayname') }}
|
@{{ getenv('site_xmpp_server_displayname') }}
|
||||||
|
@ -20,25 +23,32 @@
|
||||||
<label class="col-2 col-form-label" for="email">{% trans %}sign.up.form.email{% endtrans %}</label>
|
<label class="col-2 col-form-label" for="email">{% trans %}sign.up.form.email{% endtrans %}</label>
|
||||||
|
|
||||||
<div class="col-10">
|
<div class="col-10">
|
||||||
<input aria-describedby="help" type="text" id="email" name="email" class="form-control" placeholder="{% trans %}sign.up.form.email.placeholder{% endtrans %}" value="" autofocus required>
|
<input aria-describedby="help" type="text" id="email" name="email" class="form-control"
|
||||||
<small id="help" class="form-text text-muted">{% trans %}sign.up.form.email.help{% endtrans %}</small>
|
placeholder="{% trans %}sign.up.form.email.placeholder{% endtrans %}" value="" autofocus
|
||||||
|
required>
|
||||||
|
<small id="help"
|
||||||
|
class="form-text text-muted">{% trans %}sign.up.form.email.help{% endtrans %}</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label class="col-2 col-form-label" for="password">{% trans %}sign.up.form.password{% endtrans %}</label>
|
<label class="col-2 col-form-label"
|
||||||
|
for="password">{% trans %}sign.up.form.password{% endtrans %}</label>
|
||||||
|
|
||||||
<div class="col-10">
|
<div class="col-10">
|
||||||
<input type="password" id="password" name="password" class="form-control" placeholder="{% trans %}sign.up.form.password.placeholder{% endtrans %}" required>
|
<input type="password" id="password" name="password" class="form-control"
|
||||||
|
placeholder="{% trans %}sign.up.form.password.placeholder{% endtrans %}" required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-check">
|
<div class="form-check">
|
||||||
<input type="checkbox" id="legal" name="legal" class="form-check-input" />
|
<input type="checkbox" id="legal" name="legal" class="form-check-input"/>
|
||||||
<label class="form-check-label" for="legal"><a href="#" data-target="#legalModal" data-toggle="modal">{% trans %}legalmodal.open{% endtrans %}</a></label>
|
<label class="form-check-label" for="legal"><a href="#" data-target="#legalModal"
|
||||||
|
data-toggle="modal">{% trans %}legalmodal.open{% endtrans %}</a></label>
|
||||||
</div>
|
</div>
|
||||||
<br />
|
<br/>
|
||||||
<input class="btn btn-primary" type="submit" name="signup_button" value="{% trans %}sign.up.form.button{% endtrans %}"/>
|
<input class="btn btn-primary" type="submit" name="signup_button"
|
||||||
|
value="{% trans %}sign.up.form.button{% endtrans %}"/>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
Reference in a new issue