1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* _ __ __ _____ _____ ___ ____ _____ |
5
|
|
|
* | | / // // ___//_ _// || __||_ _| |
6
|
|
|
* | |/ // /(__ ) / / / /| || | | | |
7
|
|
|
* |___//_//____/ /_/ /_/ |_||_| |_| |
8
|
|
|
* @link https://vistart.me/ |
9
|
|
|
* @copyright Copyright (c) 2016 - 2017 vistart |
10
|
|
|
* @license https://vistart.me/license/ |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace rhosocial\user\components; |
14
|
|
|
|
15
|
|
|
use rhosocial\user\models\LoginMethod\ID; |
16
|
|
|
use rhosocial\user\models\LoginMethod\Username; |
17
|
|
|
use rhosocial\user\rbac\roles\Admin; |
18
|
|
|
use rhosocial\user\rbac\roles\Webmaster; |
19
|
|
|
use yii\base\Event; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class User |
23
|
|
|
* @package rhosocial\user\web\components |
24
|
|
|
* @version 1.0 |
25
|
|
|
* @author vistart <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class User extends \rhosocial\base\models\web\User |
28
|
|
|
{ |
29
|
|
|
public function init() |
30
|
|
|
{ |
31
|
|
|
parent::init(); |
32
|
|
|
$this->on(static::EVENT_AFTER_LOGIN, [$this, 'onRecordLogin']); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param Event $event |
37
|
|
|
*/ |
38
|
|
|
public function onRecordLogin($event) |
39
|
|
|
{ |
40
|
|
|
return $event->sender->identity->recordLogin(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return bool|mixed |
45
|
|
|
*/ |
46
|
|
|
public function getIsAdmin() |
47
|
|
|
{ |
48
|
|
|
if ($this->getIsGuest()) { |
49
|
|
|
return false; |
50
|
|
|
} |
51
|
|
|
return $this->can((new Admin)->name, $this->identity); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return bool|mixed |
56
|
|
|
*/ |
57
|
|
|
public function getIsWebmaster() |
58
|
|
|
{ |
59
|
|
|
if ($this->getIsGuest()) { |
60
|
|
|
return false; |
61
|
|
|
} |
62
|
|
|
return $this->can((new Webmaster)->name, $this->identity); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
const LOGIN_BY_ID = 'id'; |
66
|
|
|
const LOGIN_BY_USERNAME = 'username'; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get the priority of login. |
70
|
|
|
* Array value is login method class name. |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
|
|
public function getLoginPriority() |
74
|
|
|
{ |
75
|
|
|
return [ |
76
|
|
|
self::LOGIN_BY_ID => ID::class, |
77
|
|
|
self::LOGIN_BY_USERNAME => Username::class, |
78
|
|
|
]; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: