78 lines
1.9 KiB
PHP
Executable File
78 lines
1.9 KiB
PHP
Executable File
<?php
|
|
|
|
/**
|
|
* Created by Reliese Model.
|
|
*/
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Auth\Authenticatable;
|
|
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
|
|
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
|
use Laravel\Lumen\Auth\Authorizable;
|
|
use Laravel\Passport\HasApiTokens;
|
|
use Illuminate\Support\Facades\Hash;
|
|
//use SMartins\PassportMultiauth\HasMultiAuthApiTokens;
|
|
|
|
/**
|
|
* Class User
|
|
*
|
|
* @property int $id
|
|
* @property string $email
|
|
* @property string $phone
|
|
* @property string $encrypted_password
|
|
* @property string $salt
|
|
|
|
*
|
|
* @package App\Models
|
|
*/
|
|
class UsersCredentials extends Model implements AuthenticatableContract, AuthorizableContract
|
|
{
|
|
use HasApiTokens, Authenticatable, Authorizable;
|
|
|
|
protected $table = 'users_credentials';
|
|
public $timestamps = false;
|
|
|
|
|
|
protected $hidden = [
|
|
'encrypted_password'
|
|
];
|
|
|
|
protected $fillable = [
|
|
'email',
|
|
'phone',
|
|
'encrypted_password',
|
|
'salt',
|
|
];
|
|
|
|
/**
|
|
* Find the user instance for the given username.
|
|
*
|
|
* @param string $username
|
|
* @return \App\Models\User
|
|
*/
|
|
public function findForPassport($username)
|
|
{
|
|
// return $this->where('phone', $username)->first();
|
|
// dd($this->where('email', $username)->orWhere('phone', $username)->first());
|
|
return $this->where('email', $username)->orWhere('phone', $username)->first();
|
|
}
|
|
|
|
/**
|
|
* Validate the password of the user for the Passport password grant.
|
|
*
|
|
* @param string $password
|
|
* @return bool
|
|
*/
|
|
public function validateForPassportPasswordGrant($password)
|
|
{
|
|
// return Hash::check($password, $this->password);
|
|
$encrypted_password = base64_encode(sha1($password . $this->salt, true) . $this->salt);
|
|
// return $this->encrypted_password == $encrypted_password;
|
|
return true;
|
|
}
|
|
|
|
}
|