User.php
2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
namespace thread\modules\user;
use Yii;
use yii\helpers\Url;
use yii\db\ActiveRecord;
//
use thread\app\base\module\abstracts\Module as aModule;
/**
* Class User
*
* @package thread\modules\user
* @author FilamentV <vortex.filament@gmail.com>
* @copyright (c), Thread
*/
class User extends aModule
{
public $name = 'user';
public $translationsBasePath = __DIR__ . '/messages';
public $configPath = __DIR__ . '/config.php';
//
public $itemOnPage = 20;
//
public $username_attribute = 'username';
//
public $password_min_length = 4;
public $auto_login_after_register = true;
public $time_remember_user_sign_in = 2592000; // 24 * 30 * 3600
//
public $passwordResetTokenExpire = 3600;
/**
* @return string
*/
public static function getDb()
{
return Yii::$app->get('db-core');
}
/**
* @return string
*/
public static function getRedirectUrlAfterLogin()
{
return Url::toRoute(['/home/home/index']);
}
/**
* @param ActiveRecord $model
* @return string
*/
public function getAvatarUploadPath(ActiveRecord $model)
{
return $this->getBaseUploadPath('user', $model) . '/profile';
}
/**
* @param ActiveRecord $model
* @return string
*/
public function getAvatarUploadUrl(ActiveRecord $model)
{
return $this->getBaseUploadUrl('user', $model) . '/profile';
}
/**
* @param $key
* @param ActiveRecord $model
* @return string
*/
public function getBaseUploadPath($key, ActiveRecord $model)
{
$item = [
'user' => Yii::getAlias('@uploads') . '/user/',
];
return $item[$key] . $this->getBaseDirSuffix($model);
}
/**
* @param $key
* @param ActiveRecord $model
* @return string
*/
public function getBaseUploadUrl($key, ActiveRecord $model)
{
$item = [
'user' => '/uploads/user/',
];
return $item[$key] . $this->getBaseDirSuffix($model);
}
/**
* @param ActiveRecord $model
* @return string
*/
public function getBaseDirSuffix(ActiveRecord $model)
{
return date('Y/m/d', $model['created_at']) . '/' . $model['id'];
}
}