Authorization & login

Install the database tables with the MakePHP cli. The installation will be more streamlined in the future and the will be more functionality.

1. Install the database:

Install the bellow database tables in order.

php cli migrate create --table=organizations
php cli migrate create --table=users
php cli migrate create --table=login
php cli migrate create --table=usersToken

2. Add organization

Insert a organization into the database by executing the command bellow and follow the instructions.

php cli database insertOrg

3. Add user

Insert a user into the database by executing the command bellow and follow the instructions.

php cli database insertUser

4. Router

You can copy and paste the boilerplate code bellow to get you quickly started. The bellow boilerplate example might already exist if your project/app is newly installed.

$routes->group(function ($routes) {
    // Public login area

    // Regular page with form
    $routes->get("/{page:login}", ['Http\Controllers\Private\Login', "form"]);

    // Open form in a modal with ajax call
    $routes->get("/{page:login}/{model:model}", ['Http\Controllers\Private\Login', "formModel"]);

    // Login request
    $routes->post("/{page:login}", ['Http\Controllers\Private\Login', "login"]);

    // Forgot password
    $routes->get("/{page:login}/{type:forgot}", ['Http\Controllers\Private\Login', 'forgotPasswordForm']);
    $routes->post("/{page:login}/{type:forgot}", ['Http\Controllers\Private\Login', 'forgotPasswordPost']);

    // Change password
    $routes->get("/{page:login}/{type:reset}/{token:[^/]+}", ['Http\Controllers\Private\Login', "resetPasswordForm"]);
    $routes->post("/{page:login}/{type:reset}/{token:[^/]+}", ['Http\Controllers\Private\Login', "resetPasswordPost"]);

}, [
    [MaplePHP\Foundation\Auth\Middleware\LoggedIn::class, "publicZone"],
]);

$routes->group(function ($routes) {
    // Private area (The user is logged in)

    // Profile page
    $routes->get("/{profile:profile}", ['Http\Controllers\Private\Pages', "profile"]);

    // Logout the user
    $routes->get("/{page:logout}", ['Http\Controllers\Private\Pages', "logout"]);

}, [
    [MaplePHP\Foundation\Auth\Middleware\LoggedIn::class, "privateZone"]
]);

Now visit the "example.se/login" to login with the user you have added.

Last updated