265 lines
8.3 KiB
PHP
Executable file
265 lines
8.3 KiB
PHP
Executable file
<?php
|
|
|
|
namespace App;
|
|
|
|
use Carbon\Carbon;
|
|
use App\Models\SfGuardUser;
|
|
use App\Mail\MailResetPassword;
|
|
use Laravel\Passport\HasApiTokens;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
|
|
|
|
/**
|
|
* App\User
|
|
*
|
|
* @property int $id
|
|
* @property string $name
|
|
* @property string $email
|
|
* @property string $password
|
|
* @property string|null $remember_token
|
|
* @property string|null $token
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereEmail($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereName($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User wherePassword($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereRememberToken($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereToken($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereUpdatedAt($value)
|
|
* @mixin \Eloquent
|
|
* @property int|null $confirmed
|
|
* @property string|null $confirmation_code
|
|
* @property string|null $confirmation_date
|
|
* @property string|null $confirmation_code_to
|
|
* @property int|null $confirmation_code_remider
|
|
* @property int|null $active
|
|
* @property string|null $active_date
|
|
* @property string|null $agreement
|
|
* @property int|null $admin
|
|
* @property string|null $identify
|
|
* @property string|null $lang
|
|
* @property string|null $last_login
|
|
* @property \Illuminate\Support\Carbon|null $deleted_at
|
|
* @property-read \App\Models\Account $account
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\UserUpdateEmail[] $user_update_email
|
|
* @method static bool|null forceDelete()
|
|
* @method static \Illuminate\Database\Query\Builder|\App\User onlyTrashed()
|
|
* @method static bool|null restore()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereActive($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereActiveDate($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereAdmin($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereAgreement($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereConfirmationCode($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereConfirmationCodeRemider($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereConfirmationCodeTo($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereConfirmationDate($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereConfirmed($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereDeletedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereIdentify($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereLang($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereLastLogin($value)
|
|
* @method static \Illuminate\Database\Query\Builder|\App\User withTrashed()
|
|
* @method static \Illuminate\Database\Query\Builder|\App\User withoutTrashed()
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\Laravel\Passport\Client[] $clients
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\Laravel\Passport\Token[] $tokens
|
|
* @property array|null $permissions
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User query()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User wherePermissions($value)
|
|
* @property-read int|null $clients_count
|
|
* @property-read int|null $notifications_count
|
|
* @property-read int|null $tokens_count
|
|
* @property-read int|null $user_update_email_count
|
|
*/
|
|
class User extends Authenticatable
|
|
{
|
|
use HasApiTokens, Notifiable;
|
|
|
|
use SoftDeletes;
|
|
|
|
|
|
|
|
protected $permissionData = [];
|
|
|
|
protected $dates = ['deleted_at'];
|
|
protected $table = 'users';
|
|
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'name', 'email', 'password', 'token',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for arrays.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $hidden = [
|
|
'password', 'remember_token', 'token',
|
|
];
|
|
|
|
protected $casts = [
|
|
'permissions' => 'array',
|
|
];
|
|
|
|
public function sf_guard_user()
|
|
{
|
|
return $this->hasOne(SfGuardUser::class, 'user_id', 'id');
|
|
}
|
|
|
|
public function account()
|
|
{
|
|
return $this->hasOne('App\Models\Account');
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function user_update_email()
|
|
{
|
|
return $this->hasMany('App\Models\UserUpdateEmail', 'user_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function isPasswort(){
|
|
if($this->password == env('APP_KEY')){
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function isAdmin()
|
|
{
|
|
if($this->admin >= 1){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function isSuperAdmin()
|
|
{
|
|
if($this->admin >= 2){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function isSySAdmin()
|
|
{
|
|
if($this->admin >= 3){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
private function setPermissionsDefault(){
|
|
$groups = config('permissions.groups');
|
|
$permissions = [];
|
|
foreach ($groups as $role_id => $perms){
|
|
if($role_id <= $this->admin){
|
|
foreach ($perms as $key => $val){
|
|
$permissions[$key] = 1;
|
|
}
|
|
}
|
|
}
|
|
$this->permissions = $permissions;
|
|
|
|
}
|
|
public function isPermission($key){
|
|
|
|
//default by role
|
|
if(!is_array($this->permissions)){
|
|
$this->setPermissionsDefault();
|
|
}
|
|
|
|
if($key == strtolower($key)){
|
|
if(isset($this->permissions[$key]) && $this->permissions[$key] == 1){
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getConfirmationDateFormat(){
|
|
if(!$this->attributes['confirmation_date']){ return ""; }
|
|
return Carbon::parse($this->attributes['confirmation_date'])->format(\Util::formatDateTimeDB());
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getActiveDateFormat(){
|
|
if(!$this->attributes['active_date']){ return ""; }
|
|
return Carbon::parse($this->attributes['active_date'])->format(\Util::formatDateTimeDB());
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getAgreementFormat(){
|
|
if(!$this->attributes['agreement']){ return ""; }
|
|
return Carbon::parse($this->attributes['agreement'])->format(\Util::formatDateTimeDB());
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getLandByCountry(){
|
|
if($this->account && $this->account->country_id){
|
|
$code = $this->account->country->code;
|
|
if($code == "FR"){
|
|
return 'fr';
|
|
}
|
|
if($code == "CH"){
|
|
return 'de';
|
|
}
|
|
if($code == "NL"){
|
|
return 'nl';
|
|
}
|
|
if($code == "DE"){
|
|
return 'de';
|
|
}
|
|
}
|
|
return "en";
|
|
}
|
|
|
|
/**
|
|
* Send the password reset notification.
|
|
*
|
|
* @param string $token
|
|
* @return void
|
|
*/
|
|
public function sendPasswordResetNotification($token)
|
|
{
|
|
Mail::to($this->email)->send(new MailResetPassword($token, $this));
|
|
// $this->notify(new ResetPasswordNotification($token));
|
|
}
|
|
|
|
}
|