|
|
@@ -11,6 +11,8 @@ namespace frontendApi\modules\v1\controllers;
|
|
|
use common\components\ActiveRecord;
|
|
|
use common\helpers\Date;
|
|
|
use common\helpers\Form;
|
|
|
+use common\helpers\LoggerTool;
|
|
|
+use \frontendApi\modules\v1\models\brand\User AS Brand;
|
|
|
use frontendApi\modules\v1\models\User;
|
|
|
use Yii;
|
|
|
use yii\db\Exception;
|
|
|
@@ -38,6 +40,17 @@ class BaseController extends \yii\rest\ActiveController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @throws ForbiddenHttpException
|
|
|
+ */
|
|
|
+ protected function forbiddenQuicklyBaUser() {
|
|
|
+ $isQuickly = Brand::isQuicklyLogin();
|
|
|
+ $requestMethod = Yii::$app->request->getMethod();
|
|
|
+ if ($isQuickly == 1 && strtoupper($requestMethod) != 'GET') {
|
|
|
+ throw new ForbiddenHttpException('快速登录的会员无法进行任何操作!');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param $action
|
|
|
* @return bool
|
|
|
@@ -45,27 +58,53 @@ class BaseController extends \yii\rest\ActiveController {
|
|
|
* @throws \yii\web\BadRequestHttpException
|
|
|
*/
|
|
|
public function beforeAction($action) {
|
|
|
- $this->forbiddenQuicklyUser();
|
|
|
+ if (!\Yii::$app->getUser()->isGuest) {
|
|
|
+ $this->forbiddenQuicklyUser();
|
|
|
|
|
|
- // 增加的判断用户登录后未操作后的超时 和 快速登录的逻辑
|
|
|
- $isQuickly = User::isQuicklyLogin();
|
|
|
- if ($isQuickly != 1 && Yii::$app->getUser()->getUserInfo()){
|
|
|
- $userId = Yii::$app->getUser()->getUserInfo()['id'];
|
|
|
- $redisKey = 'user:timeOut';
|
|
|
+ // 增加的判断用户登录后未操作后的超时 和 快速登录的逻辑
|
|
|
+ $isQuickly = User::isQuicklyLogin();
|
|
|
+ if ($isQuickly != 1 && Yii::$app->getUser()->getUserInfo()) {
|
|
|
+ $userId = Yii::$app->getUser()->getUserInfo()['id'];
|
|
|
+ $redisKey = 'user:timeOut';
|
|
|
|
|
|
- $lastTime = '';
|
|
|
- if (!Yii::$app->tokenRedis->hget($redisKey, $userId)) {
|
|
|
- $lastTime = time();
|
|
|
- }else{
|
|
|
- $lastTime = Yii::$app->tokenRedis->hget($redisKey, $userId);
|
|
|
+ $lastTime = '';
|
|
|
+ if (!Yii::$app->tokenRedis->hget($redisKey, $userId)) {
|
|
|
+ $lastTime = time();
|
|
|
+ } else {
|
|
|
+ $lastTime = Yii::$app->tokenRedis->hget($redisKey, $userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ $currentTime = time();
|
|
|
+ $timeOut = Yii::$app->params['operationTimeOut'];
|
|
|
+ if ($currentTime - $lastTime > $timeOut) {
|
|
|
+ return self::notice('Connection not operated for too long', 402);
|
|
|
+ } else {
|
|
|
+ Yii::$app->tokenRedis->hset($redisKey, $userId, time());
|
|
|
+ }
|
|
|
}
|
|
|
+ } else {
|
|
|
+ $this->forbiddenQuicklyBaUser();
|
|
|
|
|
|
- $currentTime = time();
|
|
|
- $timeOut = Yii::$app->params['operationTimeOut'];
|
|
|
- if ($currentTime - $lastTime > $timeOut) {
|
|
|
- return self::notice('Connection not operated for too long', 402);
|
|
|
- } else {
|
|
|
- Yii::$app->tokenRedis->hset($redisKey, $userId, time());
|
|
|
+ // 增加的判断用户登录后未操作后的超时 和 快速登录的逻辑
|
|
|
+ $isQuickly = Brand::isQuicklyLogin();
|
|
|
+ if ($isQuickly != 1 && \Yii::$app->getUser()->getId()) {
|
|
|
+ $userId = Yii::$app->getUser()->getId();
|
|
|
+ $redisKey = 'user:timeOut';
|
|
|
+
|
|
|
+ $lastTime = '';
|
|
|
+ if (!Yii::$app->tokenRedis->hget($redisKey, $userId)) {
|
|
|
+ $lastTime = time();
|
|
|
+ } else {
|
|
|
+ $lastTime = Yii::$app->tokenRedis->hget($redisKey, $userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ $currentTime = time();
|
|
|
+ $timeOut = Yii::$app->params['operationTimeOut'];
|
|
|
+ if ($currentTime - $lastTime > $timeOut) {
|
|
|
+ return self::notice('Connection not operated for too long', 402);
|
|
|
+ } else {
|
|
|
+ Yii::$app->tokenRedis->hset($redisKey, $userId, time());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -184,7 +223,7 @@ class BaseController extends \yii\rest\ActiveController {
|
|
|
if ($isDelData) {
|
|
|
// 真实删除数据
|
|
|
if (!$modelClass::deleteAll($condition, $params)) {
|
|
|
- throw new Exception('删除失败');
|
|
|
+ throw new Exception('failed to delete');//删除失败
|
|
|
}
|
|
|
} else {
|
|
|
// 设置IS_DEL字段为1
|
|
|
@@ -192,7 +231,7 @@ class BaseController extends \yii\rest\ActiveController {
|
|
|
}
|
|
|
if ($afterFun) $afterFun($selected);
|
|
|
$transaction->commit();
|
|
|
- return self::notice('删除成功');
|
|
|
+ return self::notice('delete successfully');//删除成功
|
|
|
} catch (Exception $e) {
|
|
|
$transaction->rollBack();
|
|
|
return self::notice($e->getMessage(), 500);
|