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\models; |
14
|
|
|
|
15
|
|
|
use rhosocial\base\models\models\BaseBlameableModel; |
16
|
|
|
use rhosocial\user\User; |
17
|
|
|
use Yii; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class Username |
21
|
|
|
* @package rhosocial\user\models |
22
|
|
|
* @version 1.0 |
23
|
|
|
* @author vistart <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class Username extends BaseBlameableModel |
26
|
|
|
{ |
27
|
|
|
public $hostClass = User::class; |
28
|
|
|
|
29
|
|
|
public $idAttribute = false; |
30
|
|
|
|
31
|
|
|
public $createdByAttribute = 'guid'; |
32
|
|
|
public $updatedByAttribute = false; |
33
|
|
|
|
34
|
|
|
public $contentAttributeRule = ['string', 'max' => 32, 'min' => 2]; |
35
|
|
|
|
36
|
|
|
public static $regex = '/^\w{2,32}$/'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
|
|
public function rules() |
42
|
|
|
{ |
43
|
|
|
return array_merge([ |
44
|
|
|
[$this->contentAttribute, 'match', 'not' => true, 'pattern' => '/^\d+$/', 'message' => Yii::t('user', 'The username can not be a pure number.')], |
45
|
|
|
[$this->contentAttribute, 'unique', 'message'=> Yii::t('user', 'The username should be unique.')], |
46
|
|
|
], parent::rules()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return string |
51
|
|
|
*/ |
52
|
|
|
public function __toString() |
53
|
|
|
{ |
54
|
|
|
return $this->getContent(); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|