mobilebackendgateway/app/Models/User.php

104 lines
2.4 KiB
PHP

<?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 $uid
* @property string $firstname
* @property string $lastname
* @property string $phone
* @property string $email
* @property string $adresse
* @property float $solde
* @property string $encrypted_password
* @property string $salt
* @property string $validation_code
* @property int $active
* @property Carbon $date_modified
* @property Carbon $date_created
* @property int $network_id
*
* @package App\Models
*/
class User extends Model implements AuthenticatableContract, AuthorizableContract
{
use HasMultiAuthApiTokens, Authenticatable, Authorizable;
protected $table = 'users';
public $timestamps = false;
protected $casts = [
'solde' => 'float',
'active' => 'int',
'network_id' => 'int'
];
protected $dates = [
'date_modified',
'date_created'
];
protected $hidden = [
'encrypted_password'
];
protected $fillable = [
'uid',
'firstname',
'lastname',
'phone',
'email',
'adresse',
'solde',
'encrypted_password',
'salt',
'validation_code',
'active',
'date_modified',
'date_created'
];
/**
* 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();
return $user = (new User)->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;
}
}