1
|
|
|
<?php namespace Modules\User\Entities\Sentinel; |
2
|
|
|
|
3
|
|
|
use Cartalyst\Sentinel\Laravel\Facades\Activation; |
4
|
|
|
use Cartalyst\Sentinel\Users\EloquentUser; |
5
|
|
|
use Illuminate\Support\Facades\Config; |
6
|
|
|
use Laracasts\Presenter\PresentableTrait; |
7
|
|
|
use Modules\User\Entities\UserInterface; |
8
|
|
|
|
9
|
|
|
class User extends EloquentUser implements UserInterface |
10
|
|
|
{ |
11
|
|
|
use PresentableTrait; |
12
|
|
|
|
13
|
|
|
protected $fillable = [ |
14
|
|
|
'email', |
15
|
|
|
'password', |
16
|
|
|
'permissions', |
17
|
|
|
'first_name', |
18
|
|
|
'last_name', |
19
|
|
|
]; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* {@inheritDoc} |
23
|
|
|
*/ |
24
|
|
|
protected $loginNames = ['email']; |
25
|
|
|
|
26
|
|
|
protected $presenter = 'Modules\User\Presenters\UserPresenter'; |
27
|
|
|
|
28
|
|
|
public function __construct(array $attributes = []) |
29
|
|
|
{ |
30
|
|
|
parent::__construct($attributes); |
31
|
|
|
|
32
|
|
|
$this->loginNames = config('asgard.user.users.login-columns'); |
|
|
|
|
33
|
|
|
$this->fillable = config('asgard.user.users.fillable'); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Checks if a user belongs to the given Role ID |
38
|
|
|
* @param int $roleId |
39
|
|
|
* @return bool |
40
|
|
|
*/ |
41
|
|
|
public function hasRoleId($roleId) |
42
|
|
|
{ |
43
|
|
|
return $this->roles()->whereId($roleId)->count() >= 1; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Checks if a user belongs to the given Role Name |
48
|
|
|
* @param string $name |
49
|
|
|
* @return bool |
50
|
|
|
*/ |
51
|
|
|
public function hasRoleName($name) |
52
|
|
|
{ |
53
|
|
|
return $this->roles()->whereName($name)->count() >= 1; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Check if the current user is activated |
58
|
|
|
* @return bool |
59
|
|
|
*/ |
60
|
|
|
public function isActivated() |
61
|
|
|
{ |
62
|
|
|
if (Activation::completed($this)) { |
63
|
|
|
return true; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return false; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function __call($method, $parameters) |
70
|
|
|
{ |
71
|
|
|
$class_name = class_basename($this); |
72
|
|
|
|
73
|
|
|
#i: Convert array to dot notation |
74
|
|
|
$config = implode('.', ['relations', $class_name, $method]); |
75
|
|
|
|
76
|
|
|
#i: Relation method resolver |
77
|
|
|
if (Config::has($config)) { |
78
|
|
|
$function = Config::get($config); |
79
|
|
|
|
80
|
|
|
return $function($this); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
#i: No relation found, return the call to parent (Eloquent) to handle it. |
84
|
|
|
return parent::__call($method, $parameters); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..