[英]Login only with phone number without password - Laravel
我在 Laravel 工作,到目前為止,我使用守衛創建了兩個登錄名。 現在我正在嘗試使用社交名流通過 Google 登錄。 谷歌的身份驗證如此成功,我得到了一個用戶個人資料。 因此,我可以從中獲取用戶的電子郵件 ID。 現在我想用密碼通過同一個守衛登錄。
'adminpanel' => [
'driver' => 'session',
'provider' => 'adminusers',
],
'web' => [
'driver' => 'session',
'provider' => 'users',
],
]
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'adminusers' => [
'driver' => 'eloquent',
'model' => App\VendorUser::class,
],
],
那么是否有任何技巧可以進行身份驗證,我嘗試了很多。
更改app/Http/Middleware/RedirectIfAuthenticated.php的handle函數
public function handle($request, Closure $next, $guard = null)
{
if (Auth::check()) {
return redirect('/home');
}
return $next($request);
}
修改並覆蓋您的登錄功能:
public function login(Request $request)
{
$this->validate($request, [
'mobile_no' => 'required|regex:/[0-9]{10}/|digits:10',
]);
$user = User::where('mobile_no', $request->get('mobile_no'))->first();
// Check Condition Mobile No. Found or Not
if($request->get('mobile_no') != $user->mobile_no) {
\Session::put('errors', 'Your mobile number not match in our system..!!');
return back();
}
\Auth::login($user);
return redirect()->route('home');
}
在 resources/views/auth/login.blade.php 中為 mobile_no 添加一個條目
<div class="form-group{{ $errors->has('mobile_no') ? ' has-error' : '' }}">
<label for="mobile_no" class="col-md-4 control-label">Enter Mobile No.</label>
<div class="col-md-6">
<input id="mobile_no" type="text" class="form-control" name="mobile_no" value="{{ old('mobile_no') }}" required autofocus>
@if ($errors->has('mobile_no'))
<span class="help-block">
<strong>{{ $errors->first('mobile_no') }}</strong>
</span>
@endif
</div>
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.