Created
March 26, 2019 15:12
-
-
Save WendellAdriel/557c4c0733c02ff76998ea8f8aca6bfa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use Illuminate\Auth\EloquentUserProvider; | |
use Illuminate\Contracts\Auth\Authenticatable as UserContract; | |
class UserProvider extends EloquentUserProvider | |
{ | |
/** | |
* Retrieve a user by the given credentials. | |
* | |
* @param array $credentials | |
* @return \Illuminate\Contracts\Auth\Authenticatable|null | |
*/ | |
public function retrieveByCredentials(array $credentials) | |
{ | |
if (empty($credentials) || | |
(count($credentials) === 1 && | |
array_key_exists('senha', $credentials))) { | |
return; | |
} | |
// First we will add each credential element to the query as a where clause. | |
// Then we can execute the query and, if we found a user, return it in a | |
// Eloquent User "model" that will be utilized by the Guard instances. | |
$query = $this->createModel()->newQuery(); | |
foreach ($credentials as $key => $value) { | |
if (! Str::contains($key, 'senha')) { | |
$query->where($key, $value); | |
} | |
} | |
return $query->first(); | |
} | |
/** | |
* Validate a user against the given credentials. | |
* | |
* @param \Illuminate\Contracts\Auth\Authenticatable $user | |
* @param array $credentials | |
* @return bool | |
*/ | |
public function validateCredentials(UserContract $user, array $credentials) | |
{ | |
$plain = $credentials['senha']; | |
return $this->hasher->check($plain, $user->getAuthPassword()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment