作者 Your Name

gx

@@ -60,99 +60,5 @@ class Handler extends ExceptionHandler @@ -60,99 +60,5 @@ class Handler extends ExceptionHandler
60 */ 60 */
61 public function report(Throwable $exception) 61 public function report(Throwable $exception)
62 { 62 {
63 -  
64 - //日志记录  
65 - $exceptionMessage = "错误CODE:" . $exception->getCode() .  
66 - "-----错误message:" . $exception->getMessage() .  
67 - '------错误文件:' . $exception->getFile() .  
68 - '-------错误行数:' . $exception->getLine();  
69 - //A端错误  
70 - if ($exception instanceof AsideGlobalException) {  
71 - LogUtils::error("AsideGlobalException", [], $exceptionMessage);  
72 - }  
73 - //B端错误  
74 - elseif($exception instanceof BsideGlobalException) {  
75 - LogUtils::error("BsideGlobalException", [], $exceptionMessage);  
76 - }  
77 - //验证错误(非手动抛出)  
78 - elseif ($exception instanceof ValidationException) {  
79 - LogUtils::error("参数验证失败", [], $exceptionMessage);  
80 - }  
81 - //Redis错误(非手动抛出)  
82 - elseif ($exception instanceof \RedisException) {  
83 - LogUtils::error("Redis服务异常", [], $exceptionMessage);  
84 - }  
85 - //Mysql错误(非手动抛出)  
86 - elseif ($exception instanceof \PDOException) {  
87 - LogUtils::error("数据库服务异常", [], $exceptionMessage);  
88 - }  
89 - //模型未找到错误(非手动抛出)  
90 - elseif ($exception instanceof ModelNotFoundException) {  
91 - LogUtils::error("模型资源未找到", [], $exceptionMessage);  
92 - }  
93 - //其他  
94 - else {  
95 - LogUtils::error("全局系统异常", [], $exceptionMessage);  
96 - }  
97 - }  
98 - /**  
99 - * Render an exception into an HTTP response.  
100 - *  
101 - * @param \Illuminate\Http\Request $request  
102 - * @param \Throwable $exception  
103 - * @return \Symfony\Component\HttpFoundation\Response  
104 - *  
105 - * @throws \Throwable  
106 - */  
107 - public function render($request, Throwable $exception)  
108 - {  
109 - $message = $exception->getMessage();  
110 -  
111 - if ($exception instanceof AsideGlobalException) {  
112 - $code = $exception->getCode();  
113 - }elseif ($exception instanceof BsideGlobalException) {  
114 - $code = $exception->getCode();  
115 - } elseif ($exception instanceof ValidationException) {  
116 - $code = Code::USER_PARAMS_ERROE();  
117 - } elseif ($exception instanceof \RedisException) {  
118 - $code = Code::SERVER_REDIS_ERROR();  
119 - } elseif ($exception instanceof \PDOException) {  
120 - $code = Code::SERVER_MYSQL_ERROR();  
121 - } elseif ($exception instanceof ModelNotFoundException) {  
122 - $code = Code::USER_MODEL_NOTFOUND_ERROE();  
123 - } elseif ($exception instanceof NotFoundHttpException || $exception instanceof MethodNotAllowedHttpException) {  
124 - return response('404 Not Found', 404);  
125 - } else {  
126 - $code = Code::SYSTEM_ERROR();  
127 - }  
128 - //钉钉通知错误信息  
129 - if (in_array(config('app.env'), ['test', 'production']) && (in_array(substr($code, 0, 1), ['B', 'C']))) {  
130 - $exceptionMessage = "路由:" . Route::current()->uri .  
131 - "-----错误CODE:" . $exception->getCode() .  
132 - "-----错误message:" . $exception->getMessage() .  
133 - '------错误文件:' . $exception->getFile() . '-------错误行数:' .  
134 - $exception->getLine();  
135 - (new DingService())->handle(['keyword' => "ERROR", 'msg' => config('app.env') . '环境报错:' . $exceptionMessage, 'isAtAll' => false]);  
136 - }  
137 - //开启debug 错误原样输出  
138 - $debub = config('app.debug');  
139 - $message = $debub ? $message : ($code->description ?? $message);  
140 -  
141 - //请求参数错误 输出具体错误信息  
142 - if($code == Code::USER_PARAMS_ERROE()){  
143 - $message = Arr::first(Arr::first($exception->errors()));  
144 - }  
145 - $response = [  
146 - 'code' => $code,  
147 - 'message' => $message  
148 - ];  
149 - //加密返回  
150 - if (config('app.params_encrypt')) {  
151 - $k = config('app.params_encrypt_key');  
152 - $i = config('app.params_encrypt_iv');  
153 - $response = [  
154 - 'p' => (new EncryptUtils())->openssl_en($response, $k, $i)];  
155 - }  
156 - return response($response);  
157 } 63 }
158 } 64 }
@@ -42,9 +42,13 @@ class BaseController extends Controller @@ -42,9 +42,13 @@ class BaseController extends Controller
42 * @method 42 * @method
43 */ 43 */
44 public function auth_token(){ 44 public function auth_token(){
  45 + $this->token = '810f28c1d80d0ccf27509816bf44b329';
45 $info = Cache::get($this->token); 46 $info = Cache::get($this->token);
46 - $this->user = $info;  
47 - $this->uid = $info['id']; 47 + if(!empty($info)){
  48 + $this->user = $info;
  49 + $this->uid = $info['id'];
  50 + }
  51 +
48 } 52 }
49 /** 53 /**
50 * 成功返回 54 * 成功返回
@@ -110,11 +114,12 @@ class BaseController extends Controller @@ -110,11 +114,12 @@ class BaseController extends Controller
110 } 114 }
111 /** 115 /**
112 * @name 统一返回参数 116 * @name 统一返回参数
113 - * @return void 117 + * @return JsonResponse
114 * @author :liyuhang 118 * @author :liyuhang
115 * @method 119 * @method
116 */ 120 */
117 - public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'){ 121 + public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse
  122 + {
118 $code = Code::fromValue($code); 123 $code = Code::fromValue($code);
119 $result = [ 124 $result = [
120 'msg' => $msg == ' ' ? $msg : $code->description, 125 'msg' => $msg == ' ' ? $msg : $code->description,
@@ -7,6 +7,7 @@ use App\Models\Project as ProjectModel; @@ -7,6 +7,7 @@ use App\Models\Project as ProjectModel;
7 use App\Models\ProjectMenu as ProjectMenuModel; 7 use App\Models\ProjectMenu as ProjectMenuModel;
8 use App\Models\ProjectRole as ProjectRoleModel; 8 use App\Models\ProjectRole as ProjectRoleModel;
9 use App\Models\User as UserModel; 9 use App\Models\User as UserModel;
  10 +use Illuminate\Support\Facades\Cache;
10 use Illuminate\Support\Facades\DB; 11 use Illuminate\Support\Facades\DB;
11 use Illuminate\Support\Facades\Validator; 12 use Illuminate\Support\Facades\Validator;
12 13
@@ -39,6 +40,7 @@ class ComController extends BaseController @@ -39,6 +40,7 @@ class ComController extends BaseController
39 return $this->response($validate->errors()->first(),Code::USER_ERROR,$this->param); 40 return $this->response($validate->errors()->first(),Code::USER_ERROR,$this->param);
40 } 41 }
41 $userModel = new UserModel(); 42 $userModel = new UserModel();
  43 + Cache::add('1345951a03fd1916a53c48c16b2fdecb','23423423423423');
42 $res = $userModel->login($this->param); 44 $res = $userModel->login($this->param);
43 if($res === false){ 45 if($res === false){
44 $this->response('当前用户不存在或者被禁用,登录失败',Code::USER_ERROR,[]); 46 $this->response('当前用户不存在或者被禁用,登录失败',Code::USER_ERROR,[]);
@@ -111,6 +113,29 @@ class ComController extends BaseController @@ -111,6 +113,29 @@ class ComController extends BaseController
111 * @method 113 * @method
112 */ 114 */
113 public function edit_info(){ 115 public function edit_info(){
  116 + $rules = [
  117 + 'id'=>'required',
  118 + 'mobile'=>'required|string|max:11',
  119 + 'password'=>'required|string|min:5',
  120 + 'name'=>'required|max:20',
  121 + ];
  122 + //验证的提示信息
  123 + $message = [
  124 + 'id.required'=>'主键不能为空',
  125 + 'mobile.required'=>'号码必须填写',
  126 + 'mobile.string'=>'号码中含有非法文字',
  127 + 'mobile.max' => '号码不大于11字符.',
  128 + 'password.required'=>'密码必须填写',
  129 + 'password.string'=>'密码中含有非法文字',
  130 + 'password.min' => '密码不小于5字符.',
  131 + 'name.required'=>'名称必须填写',
  132 + 'name.min' => '名称不小于5字符.',
  133 + ];
  134 + $validate = Validator::make($this->param, $rules, $message);
  135 + if($validate->fails()){
  136 + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
  137 + }
  138 + $user = new UserModel();
114 139
115 } 140 }
116 141
@@ -22,10 +22,12 @@ class LoginAuthMiddleware @@ -22,10 +22,12 @@ class LoginAuthMiddleware
22 public function handle(Request $request, Closure $next) 22 public function handle(Request $request, Closure $next)
23 { 23 {
24 $token = $request->header('token'); 24 $token = $request->header('token');
  25 + var_dump(Cache::get($token));
  26 + die();
25 if(!isset($token) || empty($token)){ 27 if(!isset($token) || empty($token)){
26 $this->response('当前用户未登录',Code::USER_ERROR); 28 $this->response('当前用户未登录',Code::USER_ERROR);
27 } 29 }
28 - $info = Cache::get($request->header('token')); 30 + $info = Cache::get($token);
29 if(empty($info)){ 31 if(empty($info)){
30 $this->response('当前用户未登录',Code::USER_ERROR); 32 $this->response('当前用户未登录',Code::USER_ERROR);
31 } 33 }
@@ -37,7 +39,6 @@ class LoginAuthMiddleware @@ -37,7 +39,6 @@ class LoginAuthMiddleware
37 //查询当前用户是否拥有权限操作 39 //查询当前用户是否拥有权限操作
38 $projectMenuModel = new ProjectMenu(); 40 $projectMenuModel = new ProjectMenu();
39 $menu_id = $projectMenuModel->read(['action'=>$action['as']],['id']); 41 $menu_id = $projectMenuModel->read(['action'=>$action['as']],['id']);
40 -  
41 if(strpos($role_info['role_menu'], $menu_id['id']) < 0){ 42 if(strpos($role_info['role_menu'], $menu_id['id']) < 0){
42 $this->response('当前用户没有权限',Code::USER_ERROR); 43 $this->response('当前用户没有权限',Code::USER_ERROR);
43 } 44 }
@@ -88,6 +88,7 @@ class User extends Base @@ -88,6 +88,7 @@ class User extends Base
88 if($rs === false){ 88 if($rs === false){
89 return false; 89 return false;
90 } 90 }
  91 + unset($info['password']);
91 return $info; 92 return $info;
92 } 93 }
93 94