簡體   English   中英

Laravel 5中的自定義身份驗證,以相同的形式登錄和注冊

[英]Custom auth in Laravel 5 with login and register in the same form

如何在同一頁面上執行相同的登錄和注冊表格。 像pinterest.com一樣,注冊后立即登錄用戶。

我不知道如何進行手動身份驗證,只是默認的Auth\\AuthController

我有此控制器,模型和視圖。. MethodNotAllowedHttpException in compiled.php line 7717:向我拋出錯誤MethodNotAllowedHttpException in compiled.php line 7717:

模型:publish.php

class Publish extends Model implements AuthenticatableContract, CanResetPasswordContract{

    //
    use Authenticatable, CanResetPassword;

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'user_profiles';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['email', 'password'];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = ['password', 'remember_token'];

}

控制器:PublishController

use App\Http\Controllers\Controller;
use App\Publicar;
use Auth;
use Request;

class PublishController extends Controller {


    public function index()
    {

        return view('partials.loginCreate', compact('publish'));


    }


     public function authenticate()
    {
        if (Auth::attempt(['email' => $email, 'password' => $password]))
        {
            return redirect()->intended('dashboard');
        }
    }

查看:login.blade.php

<form class="form-horizontal" role="form" method="POST" action="{{ url('/publish/authenticate') }}">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}">

                        <div class="form-group">
                            <label class="col-md-4 control-label">E-Mail Address</label>
                            <div class="col-md-6">
                                <input type="email" class="form-control" name="email" value="{{ old('email') }}">
                            </div>
                        </div>

routes.php

Route::get('publish', 'PublishController@index');
Route::get('publish/authenticate', 'PublishController@authenticate');
Route::get('publishLogout', 'PublishController@destroy');

從更改路線

Route::get('publish/authenticate', 'PublishController@authenticate');

Route::post('publish/authenticate', 'PublishController@authenticate');

因為您在調用authenticate方法時發布了一些數據,但是選擇的route方法是get,因此您將獲得MethodNotAllowed異常

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM