请帮忙 我尝试使用auth laravel,但我现在不在我开始的地方,但我尝试使用UserInterface和UserProvider自己制作一些代码 这是我的代码: App \ Billing \ User.php:
的的
的 的
命名空间App \ Billing;
use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use App\Billing\User;
class AutoLogin implements UserProvider {
protected $table = 'tblAKSES';
protected $userInterface;
public function __construct(){
$this->userInterface = new App\Billing\User();
}
public function retrieveById($identifier) {
$this->userInterface->setUsername($identifier);
$user = DB::table($this->table)->where('USERNAME', $this->userInterface->getUsername())->first();
if (!is_null($user)){
return $this->userInterface->getUsername();
}
return null;
}
public function retrieveByToken($identifier, $token){
$this->userInterface->setUsername($identifier);
$this->userInterfacesetRememberToken($token);
$data = array(
'ID' => $this->userInterface->getAuthIdentifier(),
'remember_token' => $this->userInterface->getRememberToken(),
);
$user = DB::table($this->table)->where($data)->first();
if (is_null($user)){
return $this->userInterface->getUsername();
}
return null;
}
public function retrieveByCredentials ($credential){
$user = DB::table($this->table)->where($credential['USERNAME'])->first();
if (Hash::check($user->PASSWORD, Hash::make($credential['PASSWORD'])) && !is_null($user)) {
return $this->userInterface->getAuthIdentifier();
}
return null;
}
public function validateCredentials(User $ username,$ credential){
$this->userInterface->setUsername($credential['USERNAME']);
$this->userInterface->setPassword($credential['PASSWORD']);
$user = DB::table($this->table)->where('USERNAME', $username->getAuthIdentifier())->first();
if (is_null($user)){
return false;
}
if(Hash::check($user->PASSWORD, $username->getAuthPassword())){
return true;
}
return false;
}
public function updateRememberToken(User $username, $token){
$this->userInterface->setRememberToken($token);
DB::table($this->table)->where('USERNAME', $username->getAuthIdentifier())->update([
$username->getRememberTokenName => $username->getRememberToken,
]);
}
} 的
这里我的班级使用Autheticable:
<?php
/**
*
*/
namespace App\Billing;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
class User implements Authenticatable
{
protected $table = 'tblAKSES';
protected $username;
protected $password;
protected $token;
public function getToken(){
return $this->token;
}
public function setUsername($username){
$this->username = $username;
}
public function setPassword($password){
$pass = $this->password = $password;
return $pass;
}
public function setToken($token){
$this->token = $token;
}
public function getAuthIdentifier(){
return $this->USERNAME;
}
public function getAuthPassword(){
return $this->PASSWORD;
}
public function getRememberToken(){
return $this->token;
}
public function setRememberToken($token){
return $this->token = $token;
}
public function getRememberTokenName(){
return remember_token;
}
public function getAuthIdentifierName(){
$user = DB::table($this->table)->where([
'USERNAME' => $this->getUsername(),
])->first();
if (!is_null($user)) {
return $user->USERNAME;
}
return null;
}
}
请帮助