forked from kuafuRace/phprap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPublicController.php
More file actions
executable file
·138 lines (103 loc) · 3.41 KB
/
PublicController.php
File metadata and controls
executable file
·138 lines (103 loc) · 3.41 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
namespace app\controllers\admin;
use app\models\Apply;
use app\models\Model;
use Yii;
use yii\debug\Module;
use yii\helpers\Url;
use yii\web\Controller;
class PublicController extends Controller
{
public $layout = false;
public $debugTags;
public $beforeAction = true;
public $checkLogin = true;
public function beforeAction($action)
{
if($this->beforeAction){
if(!$this->isInstalled()){
return $this->redirect(['home/install/step1'])->send();
}
if($this->checkLogin && Yii::$app->user->isGuest){
return $this->redirect(['home/account/login'])->send();
}
if(!Yii::$app->user->identity->isAdmin){
return $this->error('抱歉,您无权访问');
}
}
return true;
}
/** 展示模板
* @param $view
* @param array $params
* @return string
*/
public function display($view, $params = [])
{
$account = Yii::$app->user->identity;
$params['creater_id'] = $account->id;
$params['check_status'] = Apply::CHECK_STATUS;
$params['order_by'] = 'id desc';
$notify = Apply::findModel()->search($params);
$params['notify'] = $notify;
$params['account'] = $account;
$params['installed_at'] = Model::findModel()->getInstallTime();
exit($this->render($view . '.html', $params));
}
/**
* 成功消息提示
* @param $message 提示信息
* @param int $jumpSeconds 延迟时间
* @param string $jumpUrl 跳转链接
* @param null $model
* @return string
*/
public function success($message, $jumpSeconds = 1, $jumpUrl = '', $model = null)
{
$jumpUrl = $jumpUrl ? Url::toRoute($jumpUrl) : \Yii::$app->request->referrer;
return $this->display('/home/public/message', ['flag' => 'success', 'message' => $message, 'time' => $jumpSeconds, 'url' => $jumpUrl, 'model' => $model]);
}
/**
* 错误消息提示
* @param $message
* @param int $jumpSeconds
* @param string $jumpUrl
* @return string
*/
public function error($message, $jumpSeconds = 3, $jumpUrl = '')
{
$jumpUrl = $jumpUrl ? Url::toRoute($jumpUrl) : \Yii::$app->request->referrer;
return $this->display('/home/public/message', ['flag' => 'error', 'message' => $message, 'time' => $jumpSeconds, 'url' => $jumpUrl]);
}
/**
* 判断是否已经安装过
* @return bool
*/
public function isInstalled()
{
return file_exists(Yii::getAlias("@runtime") . '/install/install.lock');
}
private function getDebugTags($forceReload = false)
{
if ($this->debugTags === null || $forceReload) {
if ($forceReload) {
clearstatcache();
}
$indexFile = Module::getInstance()->dataPath . '/index.data';
$content = '';
$fp = @fopen($indexFile, 'r');
if ($fp !== false) {
@flock($fp, LOCK_SH);
$content = fread($fp, filesize($indexFile));
@flock($fp, LOCK_UN);
fclose($fp);
}
if ($content !== '') {
$this->debugTags = array_reverse(unserialize($content), true);
} else {
$this->debugTags = [];
}
}
return $this->debugTags;
}
}