私はプロジェクトでLaravel
5.2を使用しています。ログインフォームがphonenumberの代わりにの資格情報を使用する必要があります。Laravel 5.2で認証する際にphonenumberをメールで送信する方法は?
Illuminateパッケージファイルを編集したくありません。
私はプロジェクトでLaravel
5.2を使用しています。ログインフォームがphonenumberの代わりにの資格情報を使用する必要があります。Laravel 5.2で認証する際にphonenumberをメールで送信する方法は?
Illuminateパッケージファイルを編集したくありません。
手動でユーザーを認証することができます:あなたの認証コントローラで
public function authenticate(Request $request)
{
$password=$request->password;
$phone=$request->phone_number;
if (Auth::attempt(['phone_number' => $phone, 'password' => $password]))
{
return redirect()->intended('/');
}
else
{
return redirect('/login');
}
}
使用この検証中:
$rules = array(
'mobile' => 'required', // make sure the mobile is an actual mobile
'password' => 'required' // password can only be alphanumeric and has to be greater than 3 characters
);
// run the validation rules on the inputs from the form
//$validator = Validator::make(Input::all(), $rules);
$validator = Validator::make(Input::all(), $rules);
// if the validator fails, redirect back to the form
if ($validator->fails()) {
return Redirect::to('login')
->withErrors($validator) // send back all errors to the login form
->withInput(Input::except('password')); // send back the input (not the password) so that we can repopulate the form
} else {
//Create our user data for the authentication
$userdata = array(
'mobile' => Input::get('mobile'),
'password' => Input::get('password')
);
$user = User::where('mobile',Input::get('mobile'))->with('userRoles')- >first();
if($user){
if (Auth::attempt($userdata)) {
/*if(User::isAdmin($user->id)) {
return Redirect::to('/admin');
}
if(User::isAuthor($user->id)) {
return Redirect::to('/dashboard');
}*/
// validation successful!
// redirect them to the secure section or whatever
// return Redirect::to('secure');
// for now we'll just echo success (even though echoing in a controller is bad)
//echo 'SUCCESSSSS!';
return Redirect::to('/');
} else {
// validation not successful, send back to form
return Redirect::to('login')->withErrors(['Invalid Username/Password']);
}
}
ありがとうございますが、これはauth laravel 5.2を使用していません。 –
これはlaravel..leaseの認証を使用しています。私の回答を参照してください編集済み –
これは動作するはずです:
// app/Http/Controllers/Auth/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;
public $username = 'phonenumber';
// ...
あなたが登録のための標準的な5.2定型を使用している場合は、validator
とcreate
方法を変更する必要があります彼らはあなたのカスタム資格情報で作業することができます。
これは5.2でのみ有効です。 Laravel 5.3では、Authワークフローで多くの変更が加えられました。
Laravel 5.3+互換性については、https://stackoverflow.com/questions/42190620/authentication-on-username-instead-of-email/42191005#42191005を参照してください。回答。 – Tayler
は
public function loginUsername()
{
return 'phonenumber';
}
を追加するには、テキスト入力フィールドの名前も同じと呼ばれていることを確認してください。
悪くないか良い。 –