Login Action is unauthorized

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
john.higgin
Posts: 2
Joined: 09 Mar 2017, 20:38

Login Action is unauthorized

Post by john.higgin » 10 Mar 2017, 00:01

I'm really stuck. I'm trying to get Aimeos working on a subdirectory of my website (all just for development).

I'm in windows 10, but using shared hosting, using putty as my command line interface, Laravel version 5.4.15, mysql version 10.1.18-MariaDB-cll-lve. I use Netbeans for the development environment.

I managed to get it to work on March 3rd, but haven't managed to duplicate my success since.

My most recent try included:
1. Creating a new subdomain
2. Create a new instance of Laravel using the cPanel softaculous 1-click apps installer into the new subdomain
3. Create my project in Netbeans
4. Rename index.php to index-old.php, rename server.php to index.php and copy the .htaccess file from the public folder into the root folder

Code: Select all

Copy over the following below "RewriteEngine On"
    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !^/public/
    RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]
    #<Files ~ "\.env$"> Order allow,deny Deny from all </Files>
    RewriteRule ^.env - [F,L,NC]
    RewriteRule ^(public/) - [F,L,NC]
    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
5. Create a new mysql database
6. get app key from config/app
7. put database and app key into .env.example and saveas .env
8. update the composer.json file to be like:

Code: Select all

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "prefer-stable": true,
    "minimum-stability": "dev",
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.4.*",
        "laravel/tinker": "~1.0",
        "aimeos/aimeos-laravel": "~2017.01",
        "laravelcollective/html": "^5.3.0"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.7"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-root-package-install": [
            "/usr/local/bin/php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "/usr/local/bin/php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall",
            "/usr/local/bin/php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "/usr/local/bin/php artisan optimize",
            "php artisan vendor:publish --tag=public --force",
            "php artisan vendor:publish",
            "php artisan migrate"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
	"cache-dir": "/home/earthhis/ts5.earthhistory.ca/cache"
    }
}
9. remove the mb4 from config/database.php mysql entries (even though I would have thought my mysql version should have been able to handle the longer entries), it never works when I don't do this.
10. composer dump-autoload
11. composer update
12. add the following to config/app.php

Code: Select all

return array(
    'providers' => array(
        ...
        Aimeos\Shop\ShopServiceProvider::class,
	Collective\Html\HtmlServiceProvider::class,
    ),
);

'aliases' => [
    // ...
      'Form' => Collective\Html\FormFacade::class,
      'Html' => Collective\Html\HtmlFacade::class,
    // ...
  ],
13. php artisan config:cache
14. php artisan vendor:publish
15. php artisan migrate (always says "nothing to migrate")
16. I tried to not have to do this step, but I always get database errors when I don't
Just uncomment all the commented-out entries in my shop.php (after syncronizing my config folder in Netbeans) and replace the host, port, database, user and password values like:

Code: Select all

			 'adapter' => env('DB_CONNECTION', 'mysql'),
			 'host' => env('DB_HOST', '127.0.0.1'),
			 'port' => env('DB_PORT', '3306'),
			 'socket' => '',
			 'database' => env('DB_DATABASE', 'dbname'),
			 'username' => env('DB_USERNAME', 'user'),
			 'password' => env('DB_PASSWORD', 'secret'),
17. php artisan aimeos:setup --option=setup/default/demo:1 1>setup.log
18. php artisan aimeos:cache
19. php artisan aimeos:account --admin adminuser[at]gm.com 2>setup.err

After getting my app.blade.php file into my views folder I was hoping to see my list page work, but it had the issue that the Login view wasn't available (I can't recall exactly what this was saying, I can reproduce if I have to)

I read that we are supposed to do the php artisan make:auth command, so I did that and now, list brings up a blank page, admin makes me login and just takes me back to home and when I put the "jqadm/search/dashboard?site=default&lang=en" URL in I get the following error:
HttpException in Handler.php line 133: This action is unauthorized.
Please let me know where I went wrong.

User avatar
aimeos
Administrator
Posts: 7835
Joined: 01 Jan 1970, 00:00

Re: Login Action is unauthorized

Post by aimeos » 11 Mar 2017, 14:09

Your list of steps doesn't contain any hint that you've created the Laravel auth infrastructure by execting

Code: Select all

./artisan make:auth
and added the code for the AuthServiceProvider like documented:
https://github.com/aimeos/aimeos-laravel#admin

Afterwards a login form should be shown if you browse to .../subdirectory/index.php/admin/
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

john.higgin
Posts: 2
Joined: 09 Mar 2017, 20:38

Re: Login Action is unauthorized

Post by john.higgin » 11 Mar 2017, 14:37

Thank you, I didn't follow the instructions very well.

I figured this out.

After setting up my server and Laravel .env file I followed the steps below and was successful:
1. add the following to composer.json
"prefer-stable": true,
"minimum-stability": "dev",
"require": {
"aimeos/aimeos-laravel": "~2017.01",
"laravelcollective/html": "^5.3.0"
...
},
"scripts": {
...
"post-update-cmd": [
"php artisan vendor:publish --tag=public --force",
"php artisan vendor:publish",
"php artisan migrate",
...
]
}
2. remove mb4 from config/database.php in mysql area
3. composer dump-autoload
4. composer update
5. add the following to the providers array of the config/app.php file
return array(
'providers' => array(
...
Aimeos\Shop\ShopServiceProvider::class,
Collective\Html\HtmlServiceProvider::class,
),
);

'aliases' => [
// ...
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
// ...
],
6. php artisan vendor:publish
7. update the database information in config/shop.php to match the .env file (refresh to see config/shop.php)
8. php artisan migrate
9. php artisan aimeos:setup --option=setup/default/demo:1 1>setup.log
10. php artisan aimeos:cache
11. Create app.blade.php template
12. php artisan cache:clear

test list page - still no CSS working for this page though :(

13. php artisan make:auth
14. php artisan aimeos:account --admin email 2>setup.err
15. extend the boot() method of App\Providers\AuthServiceProvider class add the following lines:
public function boot()
{
// Keep the lines before

Gate::define('admin', function($user, $class, $roles) {
return app( '\Aimeos\Shop\Base\Support' )->checkGroup( $user->id, $roles );
});
}
16. mkdir public/files public/preview public/uploads
17. chmod 777 public/files public/preview public/uploads

test admin page - perfect!

18. add the following lines into the existin madmin portion of config/shop.php

'madmin' => array(
'cache' => array(
'manager' => array(
'name' => 'None',
),
),
),

User avatar
aimeos
Administrator
Posts: 7835
Joined: 01 Jan 1970, 00:00

Re: Login Action is unauthorized

Post by aimeos » 11 Mar 2017, 15:30

john.higgin wrote: test list page - still no CSS working for this page though :(
This is probably due to installing your application in a subdirectory. Maybe the "asset()" function in Blade templates don't care about subdirectories:
https://github.com/aimeos/aimeos-larave ... ade.php#L4
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply