自定义Laravel Auth无法正常工作

时间:2015-08-22 18:50:55

标签: laravel authentication laravel-5 password-recovery

我已经创建了自己的登录路线:

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

Route::get('/registrar', [
    'as' => 'clubRegistrar',
    'uses' => 'Auth\AuthController@getRegister'
]);

Route::post('/registrar', [
    'as' => 'clubPostRegistrar',
    'uses' => 'Auth\AuthController@postRegister'
]);

Route::get('/ingresar', [
    'as' => 'clubIngresar',
    'uses' => 'Auth\AuthController@getLogin'
]);

Route::post('/ingresar', [
    'as' => 'clubPostIngresar',
    'uses' => 'Auth\AuthController@postLogin'
]);

Route::get('/salir', [
    'as' => 'clubSalir',
    'uses' => 'Auth\AuthController@getLogout'
]);

只缺少某些内容,密码重置

我现在的问题是使用登录路由,get方法没问题,但是有效,但是post方法无法正常运行,它会对用户进行身份验证,但不会重定向到另一条路线或路径...好奇的是它适用于默认视图,但如果我使用自己的视图,它不会...

这是我的 AuthController

class AuthController extends Controller
{

    use AuthenticatesAndRegistersUsers;

    private $loginPath = '/ingresar';
    private $redirectTo = '/reservacion';

    public function __construct(Guard $auth, Registrar $registrar)
    {
        $this->auth = $auth;
        $this->registrar = $registrar;

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

    public function getRegister()
    {
        return view('Club.auth.register');
    }

    public function getLogin()
    {
        return view('Club.auth.login');
    }

    public function postLogin(Request $request)
    {
        $this->validate($request, [
            'email' => 'required|email',
            'password' => 'required',
        ]);

        $inputs = $request->only('email', 'password');
        $credentials = array_merge($inputs, ['type' => 1]);


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

        return redirect($this->loginPath())
            ->withInput($request->only('email', 'remember'))
            ->withErrors([
                'email' => $this->getFailedLoginMessage(),
            ]);
    }
}

这是我的自定义视图:

<section class = "store-checkout" >
        <div class = "container wow fadeInDown" >
            <div class = "row" >
                <div class = "col-md-12" >
                    <div class = "container" >
                        <div class = "row" >
                            <div class = "col-md-6 col-md-offset-3 wow fadeInDown" >
                                <div class = "contact-form-contaienr" >
                                    <div class = "section-title" >
                                        <h1 ><span >Inicia Sesion</span ></h1 >
                                    </div >
                                    {!! Form::open(['route' => 'clubPostIngresar', 'action' => 'clubPostIngresar',
                                     'method' => 'post', 'id' => 'contact-form', 'role' => 'form' ]) !!}
                                    {!! Form::token() !!}
                                    {!! Form::email('email', old('email'), ['autocomplete' => 'off', 'placeholder' => 'E-Mail*','required']) !!}
                                    {!! Form::password('password', ['placeholder' => 'Contrasena']) !!}
                                    {!! Form::submit('Ingresar!',[]) !!}
                                    {!! Form::close() !!}
                                    <div id = "form-messages" >
                                        @if (count($errors) > 0)
                                            <strong >Whoops!</strong > Hubieron unos problemas con tus datos.<br ><br >
                                            <ul >
                                                @foreach ($errors->all() as $error)
                                                    <li >{{ $error }}</li >
                                                @endforeach
                                            </ul >
                                        @endif
                                    </div >
                                </div >
                                <!-- /contact-form-container -->
                            </div >
                            <!-- /col-md-6 -->
                        </div >
                        <!-- /row -->
                    </div >
                    <!-- /container -->
                </div >
                <!-- /col-md-12 -->
            </div >
            <!-- /row -->
        </div >
        <!-- /container -->
    </section >

更新2015年8月22日

我在登录时使用提交按钮解决了问题,这是一个jQuery配置。

现在我的问题变成密码重置,我如何为它制作自定义路线?我知道它是由PasswordController处理的,但是我只是覆盖ResetsPassword trait的方法在PasswordController?有人可以举个例子吗?

0 个答案:

没有答案