Git Product home page Git Product logo

dotkernel / frontend Goto Github PK

View Code? Open in Web Editor NEW
17.0 8.0 5.0 3.53 MB

DotKernel Frontend Application. Based on Zend namespace for branch 1. Based on Laminas and Mezzio for branch 2 and above.

Home Page: https://v3.dotkernel.net

License: MIT License

PHP 60.49% JavaScript 17.56% SCSS 3.78% Twig 12.11% CSS 6.05%
psr-7 middleware frontend-application php jquery bootstrap3 psr-11 psr-4 frontend-applications dotkernel

frontend's Introduction

frontend

Dotkernel web starter package suitable for frontend applications.

OSS Lifecycle PHP from Packagist (specify version)

GitHub issues GitHub forks GitHub stars GitHub license

Build Static Build Static codecov

SymfonyInsight

Installing DotKernel frontend

Tools

DotKernel can be installed through a single command that utilizes Composer. Because of that, Composer is required to install DotKernel frontend.

DotKernel has been tested with npm v10.0.4 and Node.js v20.11.0.

Composer

Installation instructions:

If you have never used composer before make sure you read the Composer Basic Usage section in Composer's documentation

Choosing an installation path for DotKernel frontend

Example:

  • absolute path /var/www/dk
  • or relative path dk (equivalent with ./dk)

Installing DotKernel frontend

After choosing the path for DotKernel (dk will be used for the remainder of this example) it must be installed. There are two installation methods.

Note

The installation uses the PHP extension ext-intl that may not be enabled by default in your web server. If the installation returns a similar error to the below, check the extension=intl extension in your php.ini.

Your requirements could not be resolved to an installable set of packages.

Problem 1
 - laminas/laminas-i18n 2.10.3 requires ext-intl * -> the requested PHP extension intl is missing from your system.

To enable an extension, remove the semicolon (;) in front of it.

I. Installing DotKernel frontend using composer

The advantage of using this command is that it runs through the whole installation process. Run the following command:

composer create-project dotkernel/frontend -s dev dk

The above command downloads the frontend package, then downloads and installs the dependencies.

The setup script prompts for some configuration settings, for example the lines below:

Please select which config file you wish to inject 'Laminas\Diactoros\ConfigProvider' into:
  [0] Do not inject
  [1] config/config.php
  Make your selection (default is 0):

Simply select [0] Do not inject, because DotKernel includes its own configProvider which already contains the prompted configurations. If you choose [1] config/config.php Laminas's ConfigProvider from session will be injected.

The next question is:

Remember this option for other packages of the same type? (y/N)

Type y here, and hit enter

II. Installing DotKernel frontend using git clone

This method requires more manual input, but it ensures that the default branch is installed, even if it is not released. Run the following command:

git clone https://github.com/dotkernel/frontend.git .

The dependencies have to be installed separately, by running this command:

composer install

Just like for II Installing DotKernel frontend using composer (see above), the setup asks for configuration settings regarding injections (type 0 and hit enter) and a confirmation to use this setting for other packages (type y and hit enter)

Configuration - First Run

  • Remove the .dist extension from the files config/autoload/local.php.dist and config/autoload/mail.local.php.dist
  • Edit config/autoload/local.php according to your dev machine and fill in the database configuration

Configuration - Mail

If you want your application to send mails on registration, contact... please provide valid credentials to the following keys in config/autoload/mail.local.php

Under message_options key:

  • from - email address from whom users will receive emails (required)
  • from_name - organization name from whom users will receive emails (optional)

Under smtp_options key:

  • host - hostname or IP address of the mail server (required)
  • connection_config - please complete the username and password keys (required)

In config/autoload/local.php add under contact => message_receivers => to key string values with the emails that should receive contact messages

Note: Please add at least 1 email address in order for contact message to reach someone

Also feel free to add as many cc as you want under contact => message_receivers => cc key

Configuration - reCAPTCHA

reCAPTCHA is used to prevent abusive activities on your website. DotKernel frontend uses the Google reCAPTCHA for its contact us form. You must first generate a siteKey and secretKey in your Google account - Google reCAPTCHA

Update the recaptcha array in config/autoload/local.php with the siteKey and secretKey from Google reCAPTCHA.

Note: you need to whitelist localhost in the reCAPTCHA settings page during development. When in production do not forget to either remove localhost from the reCAPTCHA whitelist, or have a separate reCAPTCHA

Migrations

Out of the box, we use Doctrine Migrations like detailed below to populate the database. An example file is included in /data/doctrine/migrations. To generate a new migration file, use this command:

php vendor/bin/doctrine-migrations migrations:generate

It creates a PHP file like this one /data/doctrine/migrations/Version20220606131835.php that can then be edited in the IDE. You can add new queries to be executed when the migration is run (in public function up) and optionally queries that undo those changes (in public function down).

Here is an example you can add in public function up

$this->addSql('ALTER TABLE users ADD test VARCHAR(255) NOT NULL');

and its opposite in public function down

$this->addSql('ALTER TABLE users DROP test');

Running the migrations is done with this command

php vendor/bin/doctrine-migrations migrate

Note: if you have already run the phinx migrations, you may get this message

WARNING! You have x previously executed migrations in the database that are not registered migrations.
  {migration list}
Are you sure you wish to continue? (y/n)

After submitting y, you will get this confirmation message.

WARNING! You are about to execute a database migration that could result in schema changes and data loss. Are you sure you wish to continue? (y/n)

Again, submit y to run all of the migrations in chronological order. Each migration will be logged in the migrations table to prevent running the same migration more than once, which is often not desirable.

You can opt to run a single migration

php vendor/bin/doctrine-migrations migrations:execute --up 20220606131835

and you can revert its changes with

php vendor/bin/doctrine-migrations migrations:execute --down 20220606131835

This will also remove the log for that migration in the database, allowing the migration to run again with php vendor/bin/doctrine-migrations migrate. Note the 20220606131835 is taken from the migration filename, e.g. Version20220606131835.php

Seeding the database (Fixtures)

Seeding the database is done with the help of our custom package dotkernel/dot-data-fixtures built on top of doctrine/data-fixtures. See below on how to use our CLI command for listing and executing Doctrine data fixtures.

An example of a fixtures class is data/doctrine/fixtures/RoleLoader.php

To list all the available fixtures, by order of execution, run:

php bin/doctrine fixtures:list

To execute all fixtures, run:

php bin/doctrine fixtures:execute

To execute a specific fixtures, run:

php bin/doctrine fixtures:execute --class=RoleLoader

Fixtures can and should be ordered to ensure database consistency, more on ordering fixtures can be found here : https://www.doctrine-project.org/projects/doctrine-data-fixtures/en/latest/how-to/fixture-ordering.html#fixture-ordering

Development mode

  • If you use composer create-project, the project will go into development mode automatically after installing. The development mode status can be checked and toggled by using these composer commands
composer development-status
composer development-enable
composer development-disable
  • If not already done on installation, remove the .dist extension from config/autoload/development.global.php.dist. This will enable dev mode by turning debug flag to true and turning configuration caching to off. It will also make sure that any existing config cache is cleared.

Charset recommendation: utf8mb4_general_ci

Using DebugBar

DotKernel comes with its own DebugBar already installed and configured, but disabled by default.

In order to enable it, you need to clone the config file config/autoload/debugbar.local.php.dist as config/autoload/debugbar.local.php.

More about DebugBar here.

Email Templates

These are the email templates provided on a fresh installation, all present in the User module

  • activate.html.twig used for the activation email
  • reset-password-requested.html.twig used when the user requests a password reset
  • reset-password-completed.html.twig used when the password has reset successfully

NPM Commands

To install dependencies into the node_modules directory run this command.

npm install
  • If npm install fails, this could be caused by user permissions of npm. Recommendation is to install npm through Node Version Manager.

The watch command compiles the components then watches the files and recompiles when one of them changes.

npm run watch

After all updates are done, this command compiles the assets locally, minifies them and makes them ready for production.

npm run prod

Authorization Guards

The packages responsible for restricting access to certain parts of the application are dot-rbac-guard and dot-rbac. These packages work together to create an infrastructure that is customizable and diversified to manage user access to the platform by specifying the type of role the user has.

The authorization.global.php file provides multiple configurations specifying multiple roles as well as the types of permissions to which these roles have access.

//example of a flat RBAC model that specifies two types of roles as well as their permission
    'roles' => [
                'admin' => [
                    'permissions' => [
                        'authenticated',
                        'edit',
                        'delete',
                        //etc..
                    ]
                ],
                'user' => [
                    'permissions' => [
                        'authenticated',
                        //etc..
                    ]
                ]
            ]

The authorization-guards.global.php file provides configuration to restrict access to certain actions based on the permissions defined in authorization.global.php so basically we have to add the permissions in the dot-rbac configuration file first to specify the action restriction permissions.

// configuration example to restrict certain actions of some routes based on the permissions specified in the dot-rbac configuration file
    'rules' => [
                    [
                        'route' => 'account',
                        'actions' => [//list of actions to apply , or empty array for all actions
                            'unregister',
                            'avatar',
                            'details',
                            'changePassword'
                        ],
                        'permissions' => ['authenticated']
                    ],
                    [
                        'route' => 'admin',
                        'actions' => [
                            'deleteAccount'
                        ],
                         'permissions' => [
                            'delete'
                            //list of roles to allow
                        ]
                    ]
                ]

Languages

The local.php.dist file provides an example for working with multiple languages. The translator variable can be expanded to other languages using Poedit which can edit .po files like the example in data/language/da_DK/LC_MESSAGES/messages.po. The compiled file will have the extension .mo

To apply the translations

  • the twig templates need either {% trans 'translateText' %} or {{ translateText|trans }}
  • then the js file needs translateText("translateText")

NOTE: In order to have a proper behaviour of language selector , you need the language pack installed at Operating System level.

dnf install glibc-all-langpacks

Then restart PHP-FPM.

Running the application

We recommend running your applications in WSL:

  • make sure you have WSL installed on your system
  • currently we provide 2 distro implementations: AlmaLinux9 and Ubuntu20
  • install the application in a virtualhost as recommended by the chosen distro
  • set $baseUrl in config/autoload/local.php to the address of the virtualhost
  • run the application by opening the virtualhost address in your browser

You should see the DotKernel Frontend welcome page.

NOTE:

  • If you are getting exceptions or errors regarding some missing services, try running the following command:

    php bin/clear-config-cache.php

If config-cache.php is present that config will be loaded regardless of the ConfigAggregator::ENABLE_CACHE in config/autoload/mezzio.global.php

  • Development only: session.cookie_secure does not work locally so make sure you modify your local.php, as per the following:
# other code

return [
    # other configurations...
    'session_config' => [
        'cookie_secure' => false,
    ],
];

Do not change this in local.php.dist as well because this value should remain true on production.

frontend's People

Contributors

alexmerlin avatar alinaclaudia avatar arhimede avatar bidi47 avatar calin23 avatar dependabot[bot] avatar jurj-bogdan avatar mada27 avatar marioradu avatar mstyle21 avatar sergiubota1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

frontend's Issues

Your requirements could not be resolved to an installable set of packages.

Problems with frontend installation. Related to packages versions.

Problem 1
- dotkernel/dot-event v0.2.1 requires zendframework/zend-eventmanager ^3.2 -> satisfiable by zendframework/zend-eventmanager[3.2.0, 3.2.1, 3.3.x-dev, 3.2.x-dev] but these conflict with your requirements or minimum-stability.
- dotkernel/dot-mail 1.0.0 requires dotkernel/dot-event ^0.2.1 -> satisfiable by dotkernel/dot-event[v0.2.1].
- Installation request for dotkernel/dot-mail 1.0 -> satisfiable by dotkernel/dot-mail[1.0.0].

Update migration guide

public/index.php - adaptation is missing

the file should look like the one below

<?php

declare(strict_types=1);

// Delegate static file requests back to the PHP built-in webserver
if (PHP_SAPI === 'cli-server' && $_SERVER['SCRIPT_FILENAME'] !== __FILE__) {
    return false;
}

chdir(dirname(__DIR__));
require 'vendor/autoload.php';

/**
 * Self-called anonymous function that creates its own scope and keep the global namespace clean.
 */
(function () {
    /** @var \Psr\Container\ContainerInterface $container */
    $container = require 'config/container.php';

    /** @var \Zend\Expressive\Application $app */
    $app = $container->get(\Zend\Expressive\Application::class);
    $factory = $container->get(\Zend\Expressive\MiddlewareFactory::class);

    // Execute programmatic/declarative middleware pipeline and routing
    // configuration statements
    (require 'config/pipeline.php')($app, $factory, $container);
    (require 'config/routes.php')($app, $factory, $container);

    $app->run();
})();

Checks for incomplete database

I just installed DK3 from scratch and got some errors in phpmyadmin when I tried to import data/frontend.sql into the database. Strangely, the site still works, I logged in, but the account icon on the top-right isn't displaying any more and I'm not redirected to the account page. I had to log out manually and rerun the queries between lock and unlock.

I'm thinking there should be a check at some point in the code, to verify the integrity of the database out-of-the-box. An error in the login page would really help figure out the issue.

phinx package update

the phinx package has this setup in composer.json
"robmorgan/phinx": "^0.11",
so it installs version 0.11.6

the latest version is 0.12.1, but a manual update has conflicts with cakephp packages

consider doctrine alternative

User Module simplification

Can the entire user module / handler be simplified by registering a single UserHandler that extends AbstractHandler ?

add error handler

please add as default package the error handler package
to be sure all systems are ready to log the errors

recaptcha key

the installation asks for setting up a recaptcha key, but it's not clear where to use it in the local.php file

twig > 2.10

issue with twig > 2.10
when isntalling navigation partial

Requirements missing

Requirements should be added to the readme file.

For example, it should specify that PHP7.1 is the minimum supported version.

In addition to that, I also had to install the following packages:

  • xml
  • mbstring

On ubuntu, the following steps should install everything needed, not sure about other OSes:

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.1 php7.1-xml php7.1-mbstring

Small issue with the accordion element

When toggling an element(the same element), the arrow indicating the status remains unchanged when collapsing. It changes when another element is expanded, though.

Unable to resolve 'dot-mail' services

On a fresh install

Service Manager is unable to resolve services due to missing configuration keys and aliases:

  • "dot-mail.mail-service.default"
  • "dot-mail.options." (with the dot)

The options. dot is there reflects that the names might have been generated automatically. The absence of alias or key name generation leads to unresolved services as Service Manager cannot "guess" the key's purpose.

Fix proposal:

In /config/autoload/mail.global.php add the key 'dependencies' as follows

<?php

return [
	'dependencies' => [
		'factories' => [
			Dot\Mail\Service\MailServiceInterface::class =>
                             Dot\Mail\Factory\MailServiceAbstractFactory::class,
			Dot\Mail\Options\MailOptions::class =>
                             Dot\Mail\Factory\MailOptionsAbstractFactory::class
		],
		'aliases' => [
			'dot-mail.mail-service.default' => Dot\Mail\Service\MailServiceInterface::class,
			'dot-mail.options.' => Dot\Mail\Service\MailServiceInterface::class
		],
	],
    // ... the rest of mail.global.php config
];

As the dependencies are strictly related to the mail service, they can be kept within mail.global.php
The key=>value pairs within factories and aliases can also be merged with the ones in dependencies.global.php

Resolutions ZIP package

update diactoros

Instead of
"laminas/laminas-diactoros": "^1.7.1 || ^2.0",

use

"laminas/laminas-diactoros": "^2.3",

documentation related only to Frontend

in readme.md i don't think there is necessary to talk about "admin"
in the Installing the frontend Composer package section.

This document must relates only to Frontend

migration files

add files in data folder for migration
add instructions about migrations

Url helper plugin error

It seems that the url controller plugin is not called urlHelper anymore. Please update controllers.

test INSTALL

Please test installation of DK v3 frontend
on your local machine
follwoing step by step the installation instructions
and let us know if the documentation is complete and if went smooth

Check composer dependencis for fixed version

why the below are fixed version ?
Let's check if is working properly the newest , or maybe a diffrent approach

"zendframework/zend-component-installer": "2.0",
"zendframework/zend-eventmanager": "3.2",
"zendframework/zend-expressive-fastroute": "3.0",
"zendframework/zend-expressive-helpers": "5.0",
"zendframework/zend-stratigility": "3.0",

Route request methods

The following routes don't need POST access :

  • /logout
  • /account/activate[/{hash}]
  • /account/unregister[/{hash}]

This route doesn't need the optional parameter uuid :

  • /profile[/{action}[/{uuid}]]

relase 1.0.3

please make resealse 1.0.3
from the latest master

and the one with error handler ncluded will be 1.0.3 ? gen

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.