PHP code example of baka / auth

1. Go to this page and download the library: Download baka/auth library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

baka / auth example snippets


'jwt' => [
    'secretKey' => getenv('JWT_SECURITY_HASH'),
    'expirationTime' => '1 hour', #strtotime
    'payload' => [
        'exp' => 1440,
        'iss' => 'phalcon-jwt-auth',
    ],
    'ignoreUri' => [
        'regex:auth',
        'regex:webhook',
        'regex:/users',
    ],
],

/**
* UserData dependency injection for the system
*
* @return Session
*/
$di->set('userData', function () use ($config, $auth) {
    $data = $auth->data();

    $session = new Baka\Auth\Models\Sessions();
    $request = new Phalcon\Http\Request();

    if (!empty($data) && !empty($data['sessionId'])) {
        //user
        if (!$user = Baka\Auth\Models\Users::getByEmail($data['email'])) {
            throw new Exception('User not found');
        }

        return $session->check($user, $data['sessionId'], $request->getClientAddress(), 1);
    } else {
        throw new Exception('User not found');
    }
});

$router->post('/auth', [
    '\Your\NameSpace\AuthController',
    'login',
]);

$router->post('/auth/signup', [
    '\Your\NameSpace\AuthController',
    'signup',
]);

$router->post('/auth/logout', [
    '\Your\NameSpace\AuthController',
    'logout',
]);

# get email for new password
$router->post('/auth/recover', [
    '\Your\NameSpace\AuthController',
    'recover',
]);

# update new password
$router->put('/auth/{key}/reset', [
    '\Your\NameSpace\AuthController',
    'reset',
]);

# active the account
$router->put('/auth/{key}/activate', [
    '\Your\NameSpace\AuthController',
    'activate',
]);



'social_config' => [
    // CONNECT_URL'),
    //   "enabled" => true,
            "callback" => getenv('SOCIAL_CONNECT_URL').'/Facebook',
            "keys" => ["id" => getenv('FB_ID'), "secret" => getenv('FB_SECRET')], //production
        ]
    ],
],



return [
    'paths' => [
        'migrations' => [
            getenv('PHINX_CONFIG_DIR') . '/db/migrations',
            '/home/baka/auth/db/migrations',
        ],