From 23b2abdfaf68cf59fa2b820f09f05eeb37307889 Mon Sep 17 00:00:00 2001 From: printempw Date: Wed, 15 Aug 2018 13:57:20 +0800 Subject: [PATCH] Fix form validation rules --- app/Http/Controllers/AdminController.php | 2 +- .../ValidatorExtendServiceProvider.php | 4 +- resources/lang/en/validation.yml | 4 +- resources/lang/zh_CN/validation.yml | 50 +++++++------------ 4 files changed, 23 insertions(+), 37 deletions(-) diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index fbc19396..f30dc0f1 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -468,7 +468,7 @@ class AdminController extends Controller return json(trans('admin.players.delete.success'), 0); } elseif ($action == "name") { $this->validate($request, [ - 'name' => 'required' + 'name' => 'required|player_name|min:'.option('player_name_length_min').'|max:'.option('player_name_length_max') ]); $player->rename($request->input('name')); diff --git a/app/Providers/ValidatorExtendServiceProvider.php b/app/Providers/ValidatorExtendServiceProvider.php index a4be21ac..a0967280 100644 --- a/app/Providers/ValidatorExtendServiceProvider.php +++ b/app/Providers/ValidatorExtendServiceProvider.php @@ -21,7 +21,7 @@ class ValidatorExtendServiceProvider extends ServiceProvider * @param $v validator */ Validator::extend('no_special_chars', function ($a, $value, $p, $v) { - return $value === addslashes(trim($value)); + return $value === e(addslashes(trim($value))); }); Validator::extend('player_name', function ($a, $value, $p, $v) { @@ -65,7 +65,7 @@ class ValidatorExtendServiceProvider extends ServiceProvider protected function registerExpiredRules() { Validator::extend('nickname', function ($a, $value, $p, $v) { - return $value === addslashes(trim($value)); + return $value === e(addslashes(trim($value))); }); Validator::extend('playername', function($a, $value, $p, $v) { diff --git a/resources/lang/en/validation.yml b/resources/lang/en/validation.yml index 71116512..a7d778e2 100644 --- a/resources/lang/en/validation.yml +++ b/resources/lang/en/validation.yml @@ -76,8 +76,10 @@ url: 'The :attribute format is invalid.' # Here you may specify custom validation messages for attributes using the # convention "attribute.rule" to name the lines. This makes it quick to # specify a specific custom language line for a given attribute rule. +# custom: - attribute-name: { rule-name: custom-message } + attribute-name: + rule-name: custom-message # -------------------------------------------------------------------------- # Custom Validation Attributes diff --git a/resources/lang/zh_CN/validation.yml b/resources/lang/zh_CN/validation.yml index 9cdfb4a0..c3cd9a1f 100644 --- a/resources/lang/zh_CN/validation.yml +++ b/resources/lang/zh_CN/validation.yml @@ -1,7 +1,7 @@ # Blessing Skin username: ':attribute 格式错误。' player_name: ':attribute 不符合规则。' -no_special_chars: ':attribute 不能包含特殊字母。' +no_special_chars: ':attribute 不能包含特殊字符。' preference: ':attribute 的值必须为 default 或 slim。' model: ':attribute 的值必须为 steve、alex 或 cape。' @@ -73,43 +73,27 @@ unique: ':attribute 已经存在。' url: ':attribute 格式不正确。' custom: - attribute-name: { rule-name: custom-message } + attribute-name: + rule-name: custom-message identification: required: 邮箱或角色名格式错误 attributes: - name: 名称 - file: 文件 + email: 邮箱 + new_email: 新邮箱 username: 用户名 identification: 邮箱或角色名 - new_player_name: 角色名 - sitename: 站点名称 - nickname: 昵称 - player_name: 角色名 - email: 邮箱 - first_name: 名 - last_name: 姓 password: 密码 password_confirmation: 确认密码 - city: 城市 - country: 国家 - address: 地址 - phone: 电话 - mobile: 手机 - age: 年龄 - sex: 性别 - gender: 性别 - day: 天 - month: 月 - year: 年 - hour: 时 - minute: 分 - second: 秒 - title: 标题 - content: 内容 - description: 描述 - excerpt: 摘要 - date: 日期 - time: 时间 - available: 可用的 - size: 大小 + nickname: 昵称 + new_nickname: 新昵称 + player_name: 角色名 + new_player_name: 新角色名 + preference: 优先模型 + model: 模型 + name: 名称 + new_name: 新名称 + score: 积分 + file: 文件 + public: 是否公开 + site_name: 站点名称