2016-05-04 25 views
0

誰かが私にLaravel 5.2認証を変更するのを手伝ってもらえますか?私は、デフォルトのデータベース移行を適切に調整する方法と、認証を設定する方法を理解することはできません。私はすでにデータベースを移行し、認証のビューを生成して認証をテストしました。そして、私がする必要があるのは、password_resetsusersテーブルの両方の名前を変更することと、両方のテーブルフィールドで同じことを変更することで、変更をロールバックしようとしました。 password_resetsusersのすべてのフィールドに接頭辞を追加する必要があります。私はそれをやり遂げる方法を研究し、それをテストしました。しかし、私はテーブル構造を変更したので、フォームを送信するたびに常にエラーが発生します。私はデータベースを調整した後、どこで何を修正すべきかを理解する必要があります。誰かがこれで私を導くことができますか?とても感謝しております。私は非常にLaravelに新しく、私は本当にフレームワークを学びたい。Laravel 5.2認証を変更してください

ここに私の進歩があります:

私はテーブルの名前を変更しました。私は私がusr_でフィールドにプレフィックスを追加emr_usersテーブルのフィールドに対して、両方userspassword_resets にプレフィックスemr_を追加し、emr_password_resetsのために私はps_を追加しました。

usersテーブル:2014_10_12_000000_create_users_table

//some codes 

    Schema::create('emr_users', function (Blueprint $table) { 
     $table->increments('usr_id'); 
     $table->string('usr_name'); 
     $table->string('usr_email')->unique(); 
     $table->string('usr_password'); 
     $table->rememberToken(); 
     $table->timestamps(); 
    }); 

    //some codes 

password_resetsテーブル:2014_10_12_100000_create_password_resets_table

//some codes 

    Schema::create('emr_password_resets', function (Blueprint $table) { 
     $table->string('ps_email')->index(); 
     $table->string('ps_token')->index(); 
     $table->timestamp('ps_created_at'); 
    }); 

    //some codes 

php artisan migrateを使用してデータベースを移行し、すべてが正常に見えるが、私は、ログインフォームをテストし、それを送信したとき、私は取得php artisan serveを実行した後次のエラー:

2/2 QueryException in Connection.php line 673: 
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'emr.users' doesn't exist (SQL: select * from `users` where `email` = [email protected] limit 1) 
... 

1/2 PDOException in Connection.php line 333: 
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'emr.users' doesn't exist 
... 

私は/config/auth.phpファイルを編集することで上記のエラーを解決しました。だから、エラーが消えると認識し

<?php 

return [ 

    /* 
    |-------------------------------------------------------------------------- 
    | Authentication Defaults 
    |-------------------------------------------------------------------------- 
    | 
    | This option controls the default authentication "guard" and password 
    | reset options for your application. You may change these defaults 
    | as required, but they're a perfect start for most applications. 
    | 
    */ 

    'defaults' => [ 
     'guard' => 'web', 
     'passwords' => 'users', 
    ], 

    /* 
    |-------------------------------------------------------------------------- 
    | Authentication Guards 
    |-------------------------------------------------------------------------- 
    | 
    | Next, you may define every authentication guard for your application. 
    | Of course, a great default configuration has been defined for you 
    | here which uses session storage and the Eloquent user provider. 
    | 
    | All authentication drivers have a user provider. This defines how the 
    | users are actually retrieved out of your database or other storage 
    | mechanisms used by this application to persist your user's data. 
    | 
    | Supported: "session", "token" 
    | 
    */ 

    'guards' => [ 
     'web' => [ 
      'driver' => 'session', 
      'provider' => 'users', 
     ], 

     'api' => [ 
      'driver' => 'token', 
      'provider' => 'users', 
     ], 
    ], 

    /* 
    |-------------------------------------------------------------------------- 
    | User Providers 
    |-------------------------------------------------------------------------- 
    | 
    | All authentication drivers have a user provider. This defines how the 
    | users are actually retrieved out of your database or other storage 
    | mechanisms used by this application to persist your user's data. 
    | 
    | If you have multiple user tables or models you may configure multiple 
    | sources which represent each model/table. These sources may then 
    | be assigned to any extra authentication guards you have defined. 
    | 
    | Supported: "database", "eloquent" 
    | 
    */ 

    'providers' => [ 
     'users' => [ 
      'driver' => 'eloquent', 
      'model' => App\User::class, 
     ], 

     'users' => [      /* line 73 */ 
      'driver' => 'database', 
      'table' => 'emr_users',  /* line 75 */ 
     ],        /* line 76 */ 
    ], 

    /* 
    |-------------------------------------------------------------------------- 
    | Resetting Passwords 
    |-------------------------------------------------------------------------- 
    | 
    | Here you may set the options for resetting passwords including the view 
    | that is your password reset e-mail. You may also set the name of the 
    | table that maintains all of the reset tokens for your application. 
    | 
    | You may specify multiple password reset configurations if you have more 
    | than one user table or model in the application and you want to have 
    | separate password reset settings based on the specific user types. 
    | 
    | The expire time is the number of minutes that the reset token should be 
    | considered valid. This security feature keeps tokens short-lived so 
    | they have less time to be guessed. You may change this as needed. 
    | 
    */ 

    'passwords' => [ 
     'users' => [ 
      'provider' => 'users', 
      'email' => 'auth.emails.password', 
      'table' => 'password_resets', 
      'expire' => 60, 
     ], 
    ], 

]; 

:デフォルトでは、コードのブロックは、私は、コードのブロックのコメントを解除73 76にラインでこのファイルでコメントアウトとにつながるライン75に'table' => 'emr_users''table' => 'users'を変更でテーブルemr_users

2/2 QueryException in Connection.php line 673: 
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'email' in 'where clause' (SQL: select * from `emr_users` where `email` = [email protected] limit 1) 
... 

1/2 PDOException in Connection.php line 333: 
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'email' in 'where clause' 

emailフィールドだusr_emailフィールドに変更された理由を示して、上記のエラー:しかし、私は、ログインフォームから再提出しようとすると、別のエラーを生成します。

は、ここで私はきちんとどこで、何を修正するために識別するために、Laravel 5.2の認証設計や構造と一緒にこれらのテーブルとフィールドを構成する方法を理解したいAuthController.php

<?php 

namespace App\Http\Controllers\Auth; 

use App\User; 
use Validator; 
use App\Http\Controllers\Controller; 
use Illuminate\Foundation\Auth\ThrottlesLogins; 
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, 
    ThrottlesLogins; 

    /** 
    * Where to redirect users after login/registration. 
    * 
    * @var string 
    */ 
    protected $redirectTo = '/'; 

    /** 
    * Create a new authentication controller instance. 
    * 
    * @return void 
    */ 
    public function __construct() { 
     $this->middleware($this->guestMiddleware(), ['except' => 'logout']); 
    } 

    /** 
    * Get a validator for an incoming registration request. 
    * 
    * @param array $data 
    * @return \Illuminate\Contracts\Validation\Validator 
    */ 
    protected function validator(array $data) { 
     return Validator::make($data, [ 
        'name' => 'required|max:255', 
        'email' => 'required|email|max:255|unique:users', 
        'password' => 'required|min:6|confirmed', 
     ]); 
    } 

    /** 
    * Create a new user instance after a valid registration. 
    * 
    * @param array $data 
    * @return User 
    */ 
    protected function create(array $data) { 
     return User::create([ 
        'name' => $data['name'], 
        'email' => $data['email'], 
        'password' => bcrypt($data['password']), 
     ]); 
    } 

    /** 
    * Handle a login request to the application. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @return \Illuminate\Http\Response 
    * 
    * Overrides AuthenticateUsers.php postLogin function 
    */ 
    public function postLogin(Request $request) { 
     $attempt_request = [ 
      'usr_email' => $request->email, 
      'usr_password' => $request->password 
     ]; 

     if (Auth::attempt($attempt_request)) { 
      // Authentication passed... 
      return redirect()->intended('dashboard'); 
     } 
    } 

} 

の内容です。

助けてください。ありがとう

+0

あなたが試したこととあなたが持っていたエラーを共有しますか? – Abbasi

+0

ご回答いただきありがとうございます。私は自分の投稿を親切に編集し直しました。 – emurmotol

答えて

0

最初は、laravelが提供するデフォルトのpostLogin機能を使用しています。これは素晴らしいですが、認証プロセスをより詳細に制御する必要がある場合は、この機能を無効にすることができます。

だからあなたAuthControllerにあなたが

<?php 

/** 
* Class AuthController 
* @package App\Http\Controllers\Auth 
*/ 
class AuthController extends Controller 
{ 
    .... 

    /** 
    * Handle a login request to the application. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @return \Illuminate\Http\Response 
    */ 
    public function postLogin(Request $request) 
    { 
     if (Auth::attempt(['usr_email' => $request->email, 'password' => $request->password]) { 
     // Authentication passed... 
     return redirect()->intended('dashboard'); 
     } 
     .... 
    } 

} 

今postLoginという関数を作成するあなたへのApp \ユーザーモデルは、名前だけを変更、パスワードのリセットテーブルのための今すぐ次の関数

/** 
* Get the password for the user. 
* 
* @return string 
*/ 
public function getAuthPassword() 
{ 
    return $this->usr_password; 
} 

を追加しますconfig/auth.phpファイルのテーブルのパスワード.users.table

/* 
|-------------------------------------------------------------------------- 
| Resetting Passwords 
|-------------------------------------------------------------------------- 
| 
| Here you may set the options for resetting passwords including the view 
| that is your password reset e-mail. You may also set the name of the 
| table that maintains all of the reset tokens for your application. 
| 
| You may specify multiple password reset configurations if you have more 
| than one user table or model in the application and you want to have 
| separate password reset settings based on the specific user types. 
| 
| The expire time is the number of minutes that the reset token should be 
| considered valid. This security feature keeps tokens short-lived so 
| they have less time to be guessed. You may change this as needed. 
| 
*/ 

'passwords' => [ 
    'users' => [ 
     'provider' => 'users', 
     'email' => 'auth.emails.password', 
     'table' => 'emr_password_resets', 
     'expire' => 60, 
    ], 
], 
+0

私はあなたの答えを試みたが、私はまだエラーを取得: 'Connection.phpライン673でQueryException:' 'SQLSTATE [42S22]:カラム見つかりません:1054不明な列 'メール' 'where句'(SQLのSELECT *から'emr_users'ここで 'email' = [email protected]の制限1) '。それでも同じ 'usr_email'フィールドはまだ認識されません。 – emurmotol

+0

があなたのコントローラのコード –

+0

を表示あなたも、あなたのconfig/auth.php '' ' 'ユーザー' => [ 'ドライバ' => 'データベース'、 'テーブル' => 'emr_users' から これを削除する必要があります]、 '' ' –

0

電子メール用の列は、その音ではないため、エラーが発生します。

usersテーブルのためにあなたの移行を確認し

あなたは

$卓上>の文字列( 'メール')を追加する必要があります - >ユニーク();

その後、php artisan migrateを実行します。フィールドを挿入するには

関連する問題