ingeniasoftware / luthier-ci

Improved routing, middleware support, authentication tools and more for CodeIgniter 3 framework
https://luthier.ingenia.me/ci/en/
MIT License
151 stars 39 forks source link

SimpleAuth login #18

Closed hostekevin closed 6 years ago

hostekevin commented 6 years ago

Hello :),

I'm very interesting about Auth features. It's seems that the SimpleAuth login function has not been implemented. It does not store anything in session and i can't use it.

Is this a feature in progress or planned for the future ? Or i make a mistake about usage ?

Thanks :)

andersonsalas commented 6 years ago

Hi @Kevkehz !

The auth features are ready-to-use. Maybe there is a mistake in your app, or maybe a bug. If you provide some information to review it maybe I can help you :smiley:

  1. Your application/config/hooks.php file
  2. Your application/routes/web.php file
  3. Any code that you think is causing the issue.
  4. PHP version and OS version

Cheers.

hostekevin commented 6 years ago

Thank for your help :)

I'm running a server with laragon on Windows, PHP 5.6. I start a new project from scratch and follow instructions from this page https://luthier.ingenia.me/ci/en/docs/authentication/simpleauth

hooks.php

$hook = Luthier\Hook::getHooks([
    'modules' => ['Auth']
]);

routes/web.php

Route::auth();
Route::get('/', 'welcome@index')->name('homepage');

I can successfully signup, but when i try to login i get back on login page each time.

I get an empty response when running this function after login

$userObject = $this->simple_auth->user();
var_dump($userObject); // = null

I didn't get a flash message or anything. In cookies i only have the ci_session cookie. I supposed that the login feature was in this file luthier/src/Auth/SimpleAuth/Controller, login

public function login()
    {
        $messages = Auth::messages();

        $this->loadView('login', compact('messages'));
    }

but I think the logic is somewhere else

andersonsalas commented 6 years ago

I think that some configuration or routes are missing.

Please check the default value of auth_login_route_redirect option in application/config/auth.php:

$config['auth_login_route_redirect'] = 'dashboard';

In your routes, the dashboard route is not defined, so the auth module maybe is redirecting you to the base_url because that.

Try to clear all your cookies to delete any active session, and then update your web.php route file with this test routing:

<?php
# application/routes/web.php

Route::auth(false);

Route::get('/', function(){
   luthier_info();
})->name('homepage');

Route::group('secure', ['middleware' => 'SimpleAuthMiddleware'], function(){

    Route::get('/', function(){
        echo "Login succes!!";
    })->name('dashboard');

});

Route::set('404_override', function(){
    show_404();
});

Route::set('translate_uri_dashes',FALSE);

You should be redirected to the dashboard route after log in. Let me know if that solves the issue.

abmcr commented 6 years ago

After set Route::auth(); in the web.php route file i try to login, but another error.

INFO - 2018-07-20 08:33:43 --> Config Class Initialized INFO - 2018-07-20 08:33:43 --> Hooks Class Initialized DEBUG - 2018-07-20 08:33:43 --> UTF-8 Support Enabled INFO - 2018-07-20 08:33:43 --> Utf8 Class Initialized INFO - 2018-07-20 08:33:43 --> URI Class Initialized DEBUG - 2018-07-20 08:33:43 --> No URI present. Default controller set. INFO - 2018-07-20 08:33:43 --> Router Class Initialized INFO - 2018-07-20 08:33:43 --> Output Class Initialized INFO - 2018-07-20 08:33:43 --> Security Class Initialized DEBUG - 2018-07-20 08:33:43 --> Global POST, GET and COOKIE data sanitized INFO - 2018-07-20 08:33:43 --> Input Class Initialized INFO - 2018-07-20 08:33:43 --> Language Class Initialized INFO - 2018-07-20 08:33:43 --> Loader Class Initialized INFO - 2018-07-20 08:33:43 --> Database Driver Class Initialized INFO - 2018-07-20 08:33:43 --> Email Class Initialized INFO - 2018-07-20 08:33:43 --> Session: Class initialized using 'files' driver. INFO - 2018-07-20 08:33:43 --> Controller Class Initialized INFO - 2018-07-20 08:33:43 --> Helper loaded: url_helper ERROR - 2018-07-20 08:33:43 --> Severity: error --> Exception: Class 'Auth' not found /Users/andrea/projects/ci3/vendor/luthier/luthier/src/Resources/About.php 62 Also in the root route (http://ci3.test)

An uncaught Exception was encountered Type: Error

Message: Class 'Auth' not found

Filename: /Users/andrea/projects/ci3/vendor/luthier/luthier/src/Resources/About.php

Line Number: 62

Backtrace:

File: /Users/andrea/projects/ci3/vendor/luthier/luthier/src/Functions.php Line: 67 Function: require

File: /Users/andrea/projects/ci3/application/routes/web.php Line: 22 Function: luthier_info

File: /Users/andrea/projects/ci3/vendor/luthier/luthier/src/Hook.php Line: 422 Function: call_user_func_array

File: /Users/andrea/projects/ci3/vendor/luthier/luthier/src/Hook.php Line: 59 Function: postControllerConstructorHook

File: /Users/andrea/projects/ci3/index.php Line: 315 Function: require_once

Thank you

andersonsalas commented 6 years ago

@abmcr make sure that you have enabled the Auth module in the Luthier CI hooks:

# application/config/hooks.php

$hook = Luthier\Hook::getHooks([
    'modules' => [ 'auth' , 'debug' ]
]);
abmcr commented 6 years ago

in the doc there is an error https://luthier.ingenia.me/ci/en/docs/authentication/authentication

The correct syntax is lowercase

$hook = Luthier\Hook::getHooks([ 'modules' => [ 'auth' ] ]);

but in the doc ther is $hook = Luthier\Hook::getHooks([ 'modules' => [ 'Auth' ] ]);

thank you

andersonsalas commented 6 years ago

Our apologies for the syntax error in the documentation, we will update the website soon. Thank you very much for letting us know @abmcr

andersonsalas commented 6 years ago

Updated website documentation :+1: