integration Laravel 5.4 File Manager

3

I've been integrating as it says on this page link . What I do not understand is that I get an error:

(1/1) InvalidArgumentException
View [auth.login] not found.

I am integrating it with TinyMCE that this configuration comes out:

 <textarea id="ddd" class="form-control my-editor" name="ddd">{!! old('content', 'texto') !!}</textarea>

var cmsURL = editor_config.path_absolute + 'laravel-filemanager?field_name=' + field_name;
      if (type == 'image') {
        cmsURL = cmsURL + "&type=Images";
      } else {
        cmsURL = cmsURL + "&type=Files";
      }

routes / web.php

 Route::get('/', function () {
  return view('home');
 });

 Route::get('/admin', function (){
   return view('administrador/home');
 });

 Route::post('/adminlogin', [
   'uses' => '[email protected]',
   'as' => 'loginadmin'
 ]);

 Route::group(['middleware' => 'admin'], function (){
    Route::get('/admin/home', '[email protected]');

    Route::get('/laravel-filemanager', '\Unisharp\Laravelfilemanager\controllers\[email protected]');
    Route::post('/laravel-filemanager/upload', '\Unisharp\Laravelfilemanager\controllers\[email protected]');
 });

 Route::resource('files', 'FileManagerTestController');

 Auth::routes();

app / Http / Controllers / AdminController.php

 namespace App\Http\Controllers;

 use Illuminate\Http\Request;
 use Illuminate\Foundation\Auth\AuthenticatesUsers;

 use App\Member;

 class AdminController extends Controller{
    use AuthenticatesUsers;

    public function __construct()
    {
      $this->middleware('guest', ['except' => 'logout']);
    }

    public function loginAuth (Request $request)
    {
       if (auth()->guard('admin')->attempt(['user' => $request->username, 'password' => $request->password])) {
        $user = auth()->guard('admin')->user();

          $res = (object) [
            'code' => 0,
            'boolean' => true,
            'error' => '',
            'result' => $user
         ];
       }
       else {
         $res = (object) [
            'code' => 0,
            'boolean' => false,
            'error' => 'El usuario o contraseña son incorrectos',
            'result' => ''
         ];
       }

       return response()->json($res);
    }
 }

config / lgm.php

 return [
   'use_package_routes' => true,
   'middlewares' => ['web', 'auth', 'admin'],
   'url_prefix' => 'laravel-filemanager',
   'base_directory' => 'public',
   'images_folder_name' => 'photos',
   'files_folder_name'  => 'files',
   'shared_folder_name' => 'shares',
   'thumb_folder_name'  => 'thumbs',
   ...
 ]

config / auth.php

 return [
   'defaults' => [
     'guard' => 'web',
     'passwords' => 'users',
   ],
   'guards' => [
     'web' => [
        'driver' => 'session',
        'provider' => 'users',
     ],
     'api' => [
        'driver' => 'token',
        'provider' => 'users',
     ],
     'admin' => [
        'driver' => 'session',
        'provider' => 'admins',
     ]
   ],
   'providers' => [
      'users' => [
        'driver' => 'eloquent',
        'model' => App\User::class,
      ],
      'admins' => [
        'driver' => 'eloquent',
        'model' => App\Member::class,
      ],
    ],
   ...
 ]

app / Member

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class Member extends Authenticatable
{
   use Notifiable;


   protected $table = 'member';

   protected $fillabel = ['id', 'user', 'password', 'perfil'];

   protected $hidden = ['password', 'remember_token'];
  }

app / Http / Middleware / admin.php

 namespace App\Http\Middleware;

  use Closure;
  use Illuminate\Http\Request;
  use Illuminate\Support\Facades\Auth

 class admin
 {
   public function handle($request, Closure $next, $guard = 'admin')
   {
     if (Auth::guard($guard)->check()) {
      return $next($request);
     }
     else{
      return redirect('/admin');
     }
   }
 }//

Nose, what mistake am I making or am I missing, could you point me out? Thank you very much

    
asked by Albert Arias 20.11.2017 в 23:52
source

3 answers

2

Exclude the route you want to access from the VerifyCsrfToken.php file protected $ except = [         '/ your Route'     ];

The file is in app / Http / Middleware

    
answered by 28.11.2017 в 20:05
0

You have two authentication systems and both redirect to /auth/login in case the user is not logged. The Admin system should redirect to /admin .

When a user is not authenticated, they will be redirected to the url /auth/login (which is the one that returns the auth.login view.) You can change this redirection by defining the property $loginPath in the AuthController. (In this case in AdminController)

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

use App\Member;

class AdminController extends Controller
{
    use AuthenticatesUsers;
    //Se define la propiedad $loginPath
    protected $loginPath = '/admin';

    public function __construct()
    {
        $this->middleware('guest', ['except' => 'logout']);
    }

    public function loginAuth(Request $request)
    {
        if (auth()->guard('admin')->attempt(['user' => $request->username, 'password' => $request->password])) {
            $user = auth()->guard('admin')->user();

            $res = (object) [
                'code' => 0,
                'boolean' => true,
                'error' => '',
                'result' => $user
            ];
        } else {
            $res = (object) [
                'code' => 0,
                'boolean' => false,
                'error' => 'El usuario o contraseña son incorrectos',
                'result' => ''
            ];
        }

        return response()->json($res);
    }
}
    
answered by 29.11.2017 в 16:46
0

I found the solution for the time being. For the operation of filemanager in laravel you need authentication auth , and for an auth admin that is customized that is for utenticacion of another table that is not users if not administrator that I put it in the question.

The solution at the moment was to change in these files:

config / lgm.php

(remove the auth that is predetermined)

 return [
   ...
   'middlewares' => ['web', 'admin'],
   ...
 ]

vendors / unisharp / laravel-filemanager / src / Handlers / ConfigHandler.php

(Place which auth is calling)

namespace Unisharp\Laravelfilemanager\Handlers;

class ConfigHandler
{
   public function userField()
   {
      return auth()->guard('admin')->user()->id;
   }
}
    
answered by 30.11.2017 в 20:35