Support the ongoing development of Laravel.io →
Configuration Authentication
Last updated 2 years ago.
0

Have you looked at the example auth controller in L5, it has what you need. The docs are not up to date. Also look at laracast.

Last updated 9 years ago.
0

jimgwhit said:

Have you looked at the example auth controller in L5, it has what you need. The docs are not up to date. Also look at laracast.

I believe the example auth controller is the Auth/AuthController class that I'm trying to use.

0

Here is my auth controller, it does work. Note I use userid rather than email.

<?php namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\Registrar;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller {

	/*
	|--------------------------------------------------------------------------
	| Registration & Login Controller
	|--------------------------------------------------------------------------
	|
	| This controller handles the registration of new users, as well as the
	| authentication of existing users. By default, this controller uses
	| a simple trait to add these behaviors. Why don't you explore it?
	|
	*/

	use AuthenticatesAndRegistersUsers;

	/**
	 * Create a new authentication controller instance.
	 *
	 * @param  \Illuminate\Contracts\Auth\Guard  $auth
	 * @param  \Illuminate\Contracts\Auth\Registrar  $registrar
	 * @return void
	 */
	public function __construct(Guard $auth, Registrar $registrar)
	{
		$this->auth = $auth;
		$this->registrar = $registrar;

		$this->middleware('guest', ['except' => 'getLogout']);
	}
        
        
           public function getLogin()
	{
		//return view('auth.login');
                return view('auth.testview');
	}
        
        public function postLogin(Request $request)
	{
		$this->validate($request, [
			'userid' => 'required', 'password' => 'required',
		]);
                
                //added
                
                echo 'made it here====';
            $tvar = $request->input('userid');
            //echo $tvar;
            $pw = $request->input('password');
            if ($this->auth->attempt(['userid' => $tvar, 'password' => $pw]))
		{
                    //echo 'logged in========'.$request->user->userid;
                    //echo 'logged in========'.$request->user()->userid;
                    $yourvar = $request->user()->userid;
                    echo $yourvar;
                    echo "====loggin in now";
                    //return redirect('olist');
		}
            else
                {
                    echo ' not logged in';
                }

                //added

		/*$credentials = $request->only('email', 'password');

		if ($this->auth->attempt($credentials, $request->has('remember')))
		{
			return redirect($this->redirectPath());
		}

		return redirect('/auth/login')
					->withInput($request->only('email'))
					->withErrors([
						'email' => 'These credentials do not match our records.',
					]);*/
	}
        
        public function getLogout()
	{
		$this->auth->logout();

		return redirect('/');
	}



}//end class

My L5 is in work so controller isn't finished, but the login works 100%.

Last updated 9 years ago.
0

I had this same problem, searched around for a few days. Decided to drop the controller and wrote my own

0

But the issue I seem to be having is not that the controller doesn't work, its that the system doesn't find it. None of it gets to run and/or fail. It may be an issue with namespaces, or just me being dumb.

For the record, here's the content of my AuthController.php, sitting on app/Http/Controllers/Auth

<?php namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\Registrar;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller {

	/*
	|--------------------------------------------------------------------------
	| Registration & Login Controller
	|--------------------------------------------------------------------------
	|
	| This controller handles the registration of new users, as well as the
	| authentication of existing users. By default, this controller uses
	| a simple trait to add these behaviors. Why don't you explore it?
	|
	*/

	use AuthenticatesAndRegistersUsers;

	/**
	 * Create a new authentication controller instance.
	 *
	 * @param  \Illuminate\Contracts\Auth\Guard  $auth
	 * @param  \Illuminate\Contracts\Auth\Registrar  $registrar
	 * @return void
	 */
	public function __construct(Guard $auth, Registrar $registrar)
	{
		$this->auth = $auth;
		$this->registrar = $registrar;

		$this->middleware('guest', ['except' => 'getLogout']);
	}

}
0

Do your controller like mine and it will work, you are missing a use statement...

0
Solution

Well, no. The solution was changing on routes.php from

Route::controllers([
	'auth' => 'Auth\AuthController',
	'password' => 'Auth\PasswordController',
]);

to

Route::controllers([
	'auth' => '\App\Http\Controllers\Auth\AuthController',
	'password' => '\App\Http\Controllers\Auth\PasswordController',
]);
0

Actually, the most probable cause of this is leaving $namespace variable null in RouteServiceProvider as suggested in upgrade guide.

/**
 * This namespace is applied to the controller routes in your routes file.
 *
 * In addition, it is set as the URL generator's root namespace.
 *
 * @var string
 */
protected $namespace = null; // 'App\Http\Controllers';
0

Its resolve by adding this line in my Authenticate.php

use Illuminate\Contracts\Auth\Guard;

<?php

 namespace App\Http\Middleware;

 use Closure;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Contracts\Auth\Guard;

 class Authenticate
 {
Last updated 8 years ago.
0

perfect when i use dingo met the same problem,just add absolute path:


➜  laravel-auth-jwt-entrust git:(master) ✗ artisan api:routes
+------------------------------+----------+-----------------+------+----------------------------------------------------+-----------+------------+----------+------------+
| Host                         | Method   | URI             | Name | Action                                             | Protected | Version(s) | Scope(s) | Rate Limit |
+------------------------------+----------+-----------------+------+----------------------------------------------------+-----------+------------+----------+------------+
| laravel-auth-jwt-entrust.dev | GET|HEAD | /api/hello      |      | App\Http\Controllers\HomeController@index          | No        | v1         |          |            |
| laravel-auth-jwt-entrust.dev | GET|HEAD | /api/auth/login |      | \App\Http\Controllers\Auth\AuthController@getLogin | No        | v1         |          |            |
Last updated 8 years ago.
0

php artisan make:auth

0

Sign in to participate in this thread!

Eventy

Your banner here too?

rgoro rgoro Joined 15 Jan 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.