root 2 лет назад
Родитель
Сommit
1c30e7cc50

+ 10 - 10
backendApi/modules/v1/controllers/BaseController.php

@@ -38,6 +38,11 @@ class BaseController extends \yii\rest\ActiveController {
     public function beforeAction($action) {
         $parentBeforeAction = parent::beforeAction($action);
 
+        // 动态返回语言:zh-CN | en-US
+        if (!Yii::$app->request->isOptions) {
+            Yii::$app->language = Yii::$app->request->headers->get('language') ?? 'zh-CN';
+            Yii::$app->sourceLanguage = (Yii::$app->request->headers->get('language') ?? 'zh-CN') == 'zh-CN' ? 'en-US' : 'zh-CN';
+        }
         // 增加的判断用户登录后未操作后的超时
         if (Yii::$app->getUser()->getUserInfo()){
             $adminId = Yii::$app->getUser()->getUserInfo()['id'];
@@ -53,7 +58,8 @@ class BaseController extends \yii\rest\ActiveController {
             $currentTime = time();
             $timeOut = Yii::$app->params['operationTimeOut'];
             if ($currentTime - $lastTime > $timeOut) {
-                return self::notice('Connection not operated for too long', 402);
+
+                return self::notice(Yii::t('ctx', 'notConnection'), 402);
             } else {
                 Yii::$app->tokenRedis->hset($redisKey, $adminId, time());
             }
@@ -68,24 +74,18 @@ class BaseController extends \yii\rest\ActiveController {
                 $menu = require Yii::getAlias('@backendApi/config/menu.php');// 获取此页面code,对应的权限值
                 $pagePermission = $this->checkPagePermission($sqlCode, $menu);
                 if (empty($pagePermission)) {
-                    return self::notice('Insufficient user permissions', 403);
+                    return self::notice(Yii::t('ctx', 'noPermission'), 403);
                 }
                 if(!Yii::$app->user->validateAdminAction($pagePermission['controller'], $pagePermission['action'])) {
 
-                    return self::notice('Insufficient user permissions', 403);
+                    return self::notice(Yii::t('ctx', 'noPermission'), 403);
                 } else {
                     
                     return $parentBeforeAction;
                 }
             }
             
-            return self::notice('Insufficient user permissions', 403);
-        }
-
-        // 动态返回语言:zh-CN | en-US
-        if (!Yii::$app->request->isOptions) {
-            Yii::$app->language = Yii::$app->request->headers->get('language') ?? 'zh-CN';
-            Yii::$app->sourceLanguage = (Yii::$app->request->headers->get('language') ?? 'zh-CN') == 'zh-CN' ? 'en-US' : 'zh-CN';
+            return self::notice(Yii::t('ctx', 'noPermission'), 403);
         }
 
         return $parentBeforeAction;

+ 4 - 5
backendApi/modules/v1/controllers/OauthController.php

@@ -156,7 +156,6 @@ class OauthController extends BaseController
 
             return static::notice(Form::formatErrorsForApi($model->getErrors()), 401);
         }
-
     }
 
     public function actionNoLoginModifyPassword() {
@@ -164,7 +163,7 @@ class OauthController extends BaseController
         $form->scenario = 'noLoginModifyPassword';
         if(Yii::$app->request->isPost && $form->load(Yii::$app->request->post(), '') && $result = $form->edit()){
             // Log::adminHandle('管理员'.$result->ADMIN_NAME.'重置密码');
-            return static::notice('重置密码成功');
+            return static::notice(Yii::t('ctx', 'resetPasswordSucceeded'));
         } else {
             return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
         }
@@ -182,7 +181,7 @@ class OauthController extends BaseController
         if($token){
             return static::notice($token);
         } else {
-            return static::notice('更新Token失败', 401);
+            return static::notice(Yii::t('ctx', 'refreshTokenFailed'), 401);
         }
     }
 
@@ -198,7 +197,7 @@ class OauthController extends BaseController
         if($token){
             return static::notice($token);
         } else {
-            return static::notice('更新Token失败', 401);
+            return static::notice(Yii::t('ctx', 'refreshTokenFailed'), 401);
         }
     }
 
@@ -214,7 +213,7 @@ class OauthController extends BaseController
         if($token){
             return static::notice($token);
         } else {
-            return static::notice('更新Token失败', 401);
+            return static::notice(Yii::t('ctx', 'refreshTokenFailed'), 401);
         }
     }
 

+ 8 - 7
backendApi/modules/v1/models/LoginForm.php

@@ -56,17 +56,17 @@ class LoginForm extends Model {
         if (!$this->hasErrors()) {
             $this->getUser();
             if(!$this->_user){
-                $this->addError($attribute, 'Member does not exist');
+                $this->addError($attribute, Yii::t('ctx', 'memberDoesNotExist'));
                 return false;
             }
             if (!$this->_user->validatePassword($this->password)) {
-                $this->addError($attribute, '用户名或者密码错误');
+                $this->addError($attribute, Yii::t('ctx', 'nameOrPasswdError'));
                 return false;
             }
             //验证IP
             $bindIp = trim($this->_user['BIND_IP']);
             if(!empty($bindIp) && !(new LoginIpChecker(Yii::$app->request->getUserIP(), $bindIp))->validate()){
-                $this->addError($attribute, '登录IP与此账号绑定的IP不符');
+                $this->addError($attribute, Yii::t('ctx', 'ipBindAccountNumberError'));
                 return false;
             }
             return true;
@@ -112,21 +112,22 @@ class LoginForm extends Model {
         try{
             $this->getUser();
             if(!$this->_user){
-                throw new Exception('The account does not exist'); // 账号不存在
+                throw new Exception(Yii::t('ctx', 'accountDoesNotExist')); // 账号不存在
             }
             if(!$this->_user['IS_ENABLE']){
                 $this->_updateFailTimes($transaction,'账号已经被锁定,无法登录');
-                throw new Exception('The account has been locked and cannot be logged in'); // 账号已经被锁定,无法登录
+                throw new Exception(Yii::t('ctx', 'accountLockCannotLoggedIn')); // 账号已经被锁定,无法登录
             }
             if (!$this->_user->validatePassword($this->password)) {
                 $this->_updateFailTimes($transaction,'用户名或者密码错误');
-                throw new Exception('Incorrect user name or password'); // 用户名或者密码错误
+                throw new Exception(Yii::t('ctx', 'nameOrPasswdError')); // 用户名或者密码错误
             }
             //验证IP
             $bindIp = trim($this->_user['BIND_IP']);
             if(!empty($bindIp) && !(new LoginIpChecker(Yii::$app->request->getUserIP(), $bindIp))->validate()){
                 $this->_updateFailTimes($transaction,'登录IP与此账号绑定的IP不符');
-                throw new Exception('The login IP does not match the IP bound to this account'.$bindIp); // 登录IP与此账号绑定的IP不符
+                $exceptionMessage = Yii::t('ctx', 'ipBindAccountNumberError');
+                throw new Exception($exceptionMessage.$bindIp); // 登录IP与此账号绑定的IP不符
             }
 
             //需要修改密码

+ 0 - 0
common/config/i18n.php


+ 0 - 0
common/messages/en-US/app.php


+ 13 - 1
common/messages/en-US/ctx.php

@@ -1,7 +1,18 @@
 <?php
 return [
+    # 登录
+    'memberDoesNotExist' => 'Member does not exist',
+    'nameOrPasswdError' => 'The member name or password is incorrect',
+    'ipBindAccountNumberError' => 'The login IP does not match the IP bound to this account',
+    'accountDoesNotExist' => 'The account does not exist',
+    'accountLockCannotLoggedIn' => 'The account has been locked and cannot be logged in',
+    'refreshTokenFailed' => 'refresh token failed',
+    'resetPasswordSucceeded' => 'Password reset succeeded',
 
-
+    # 公共-校验权限,登录状态
+    'notConnection' => 'Connection not operated for too long',
+    'noPermission' => 'Insufficient user permissions',
+    
 
     /**【以下内容为会员端词条,如果管理端有相同词条,移入分割线之上使用即可,翻译完全部项目之后删除以下内容】
      * 会员端翻译:Yii::t('app', 'addressId')
@@ -295,6 +306,7 @@ return [
 
     # 公用
     'notConnection' => 'Connection not operated for too long',
+    'noPermission' => 'Insufficient user permissions',
     'deleteFailed' => 'failed to delete',
     'deleteSuccessfully' => 'delete successfully',
     'quickLoginCanNotOperate' => '快速登录的会员无法进行任何操作',

+ 0 - 0
common/messages/zh-CN/app.php


+ 12 - 1
common/messages/zh-CN/ctx.php

@@ -1,7 +1,17 @@
 <?php
 return [
+    # 登录
+    'memberDoesNotExist' => '用户不存在',
+    'nameOrPasswdError' => '用户名或者密码错误',
+    'ipBindAccountNumberError' => '登录IP与此账号绑定的IP不符',
+    'accountDoesNotExist' => '账号不存在',
+    'accountLockCannotLoggedIn' => '账号已经被锁定,无法登录',
+    'refreshTokenFailed' => '更新Token失败',
+    'resetPasswordSucceeded' => '重置密码成功',
 
-
+    # 公共-校验权限,登录状态
+    'notConnection' => '长时间未操作',
+    'noPermission' => '用户权限不足',
 
     /**【以下内容为会员端词条,如果管理端有相同词条,移入分割线之上使用即可,翻译完全部项目之后删除以下内容】
      * 会员端翻译:Yii::t('app', 'addressId')
@@ -297,6 +307,7 @@ return [
 
     # 公用
     'notConnection' => '长时间未操作',
+    'noPermission' => '用户权限不足',
     'deleteFailed' => '删除失败',
     'deleteSuccessfully' => '删除成功',
     'quickLoginCanNotOperate' => '快速登录的会员无法进行任何操作',

+ 0 - 0
common/models/CalcBonusBSDefault.php


+ 0 - 0
common/models/CalcOperation.php