Remove restriction of texture name and nickname

This commit is contained in:
Pig Fang 2019-12-22 10:46:10 +08:00
parent e21fb0fa31
commit 9cc83dad30
16 changed files with 10 additions and 85 deletions

View File

@ -593,9 +593,7 @@ class AdminController extends Controller
return json(trans('admin.users.operations.verification.success'), 0);
} elseif ($action == 'nickname') {
$this->validate($request, [
'nickname' => 'required|no_special_chars',
]);
$this->validate($request, ['nickname' => 'required']);
$user->nickname = $request->input('nickname');
$user->save();

View File

@ -121,7 +121,7 @@ class AuthController extends Controller
$rule = option('register_with_player_name') ?
['player_name' => 'required|player_name|min:'.option('player_name_length_min').'|max:'.option('player_name_length_max')] :
['nickname' => 'required|no_special_chars|max:255'];
['nickname' => 'required|max:255'];
$data = $this->validate($request, array_merge([
'email' => 'required|email|unique:users',
'password' => 'required|min:8|max:32',

View File

@ -85,7 +85,7 @@ class ClosetController extends Controller
{
$this->validate($request, [
'tid' => 'required|integer',
'name' => 'required|no_special_chars',
'name' => 'required',
]);
$user = Auth::user();
@ -126,7 +126,7 @@ class ClosetController extends Controller
public function rename(Request $request, $tid)
{
$this->validate($request, ['name' => 'required|no_special_chars']);
$this->validate($request, ['name' => 'required']);
$user = auth()->user();
if ($user->closet()->where('tid', $request->tid)->count() == 0) {

View File

@ -115,7 +115,7 @@ class SetupController extends Controller
{
$data = $this->validate($request, [
'email' => 'required|email',
'nickname' => 'required|no_special_chars|max:255',
'nickname' => 'required',
'password' => 'required|min:8|max:32|confirmed',
'site_name' => 'required',
]);

View File

@ -362,7 +362,7 @@ class SkinlibController extends Controller
{
$this->validate($request, [
'tid' => 'required|integer',
'new_name' => 'required|no_special_chars',
'new_name' => 'required',
]);
$user = $request->user();
$t = Texture::find($request->input('tid'));
@ -427,7 +427,7 @@ class SkinlibController extends Controller
$this->validate($request, [
'name' => [
'required',
option('texture_name_regexp') ? 'regex:'.option('texture_name_regexp') : 'no_special_chars',
option('texture_name_regexp') ? 'regex:'.option('texture_name_regexp') : 'string',
],
'file' => 'required|max:'.option('max_upload_file_size'),
'public' => 'required',

View File

@ -251,9 +251,7 @@ class UserController extends Controller
return json(trans('user.profile.nickname.single'), 1);
}
$this->validate($request, [
'new_nickname' => 'required|no_special_chars|max:255',
]);
$this->validate($request, ['new_nickname' => 'required']);
$nickname = $request->input('new_nickname');
$user->nickname = $nickname;

View File

@ -14,16 +14,6 @@ class ValidatorExtendServiceProvider extends ServiceProvider
*/
public function boot()
{
/*
* @param $a attribute
* @param $value value
* @param $p parameters
* @param $v validator
*/
Validator::extend('no_special_chars', function ($a, $value, $p, $v) {
return $value === e(addslashes(trim($value)));
});
Validator::extend('player_name', function ($a, $value, $p, $v) {
$regexp = '/^(.*)$/';

View File

@ -1,7 +1,6 @@
# Blessing Skin
username: ':attribute format is invalid.'
player_name: 'The :attribute contains invalid character.'
no_special_chars: 'The :attribute must not contain special characters.'
model: 'The :attribute must be steve, alex or cape.'
accepted: 'The :attribute must be accepted.'

View File

@ -47,6 +47,7 @@
- Removed package `swiggles/memcache`.
- Removed `commit` property from `blessing` global.
- Removed Element UI.
- Removed restriction of texture name and nickname.
## Internal Changes

View File

@ -47,6 +47,7 @@
- 移除扩展包 `swiggles/memcache`
- 从全局变量 `blessing` 中移除 `commit` 属性
- 移除 Element UI
- 移除对材质名和用户昵称的要求
## 内部更改

View File

@ -292,12 +292,6 @@ class AdminControllerTest extends TestCase
['uid' => $user->uid, 'action' => 'nickname']
)->assertJsonValidationErrors(['nickname']);
// Action is `nickname` but with an invalid nickname
$this->postJson(
'/admin/users',
['uid' => $user->uid, 'action' => 'nickname', 'nickname' => '\\']
)->assertJsonValidationErrors(['nickname']);
// Set nickname successfully
$this->postJson(
'/admin/users',

View File

@ -282,17 +282,6 @@ class AuthControllerTest extends TestCase
]
)->assertJsonValidationErrors('nickname');
// Should return a warning if `nickname` is invalid
$this->postJson(
'/auth/register',
[
'email' => 'a@b.c',
'password' => '12345678',
'nickname' => '\\',
'captcha' => 'a',
]
)->assertJsonValidationErrors('nickname');
// Should return a warning if `nickname` is too long
$this->postJson(
'/auth/register',

View File

@ -106,12 +106,6 @@ class ClosetControllerTest extends TestCase
['tid' => 0]
)->assertJsonValidationErrors('name');
// `name` field has special characters
$this->postJson(
'/user/closet/add',
['tid' => 0, 'name' => '\\']
)->assertJsonValidationErrors('name');
// The user doesn't have enough score to add a texture
$this->user->score = 0;
$this->user->save();
@ -181,10 +175,6 @@ class ClosetControllerTest extends TestCase
// Missing `name` field
$this->postJson('/user/closet/rename/0')->assertJsonValidationErrors('name');
// `new_name` field has special characters
$this->postJson('/user/closet/rename/0', ['name' => '\\'])
->assertJsonValidationErrors('name');
// Rename a not-existed texture
$this->postJson('/user/closet/rename/-1', ['name' => $name])
->assertJson([

View File

@ -109,18 +109,6 @@ class SetupControllerTest extends TestCase
'email' => 'a@b.c',
])->assertDontSee(trans('setup.wizard.finish.title'));
// Invalid characters in nickname
$this->post('/setup/finish', [
'email' => 'a@b.c',
'nickname' => '\\',
])->assertDontSee(trans('setup.wizard.finish.title'));
// Too long nickname
$this->post('/setup/finish', [
'email' => 'a@b.c',
'nickname' => Str::random(256),
])->assertDontSee(trans('setup.wizard.finish.title'));
// Without `password` field
$this->post('/setup/finish', [
'email' => 'a@b.c',

View File

@ -397,10 +397,6 @@ class SkinlibControllerTest extends TestCase
// Without `name` field
$this->postJson('/skinlib/upload')->assertJsonValidationErrors('name');
// With some special chars
$this->postJson('/skinlib/upload', ['name' => '\\'])
->assertJsonValidationErrors('name');
// Specified regular expression for texture name
option(['texture_name_regexp' => '/\\d+/']);
$this->postJson('/skinlib/upload', [
@ -846,13 +842,6 @@ class SkinlibControllerTest extends TestCase
])
->assertJsonValidationErrors('new_name');
// `new_name` has special chars
$this->postJson('/skinlib/rename', [
'tid' => $texture->tid,
'new_name' => '\\',
])
->assertJsonValidationErrors('new_name');
// Non-existed texture
$this->postJson('/skinlib/rename', [
'tid' => -1,

View File

@ -268,18 +268,6 @@ class UserControllerTest extends TestCase
$this->postJson('/user/profile', ['action' => 'nickname'])
->assertJsonValidationErrors('new_nickname');
// Invalid nickname
$this->postJson('/user/profile', [
'action' => 'nickname',
'new_nickname' => '\\',
])->assertJsonValidationErrors('new_nickname');
// Too long nickname
$this->postJson('/user/profile', [
'action' => 'nickname',
'new_nickname' => Str::random(256),
])->assertJsonValidationErrors('new_nickname');
// Single player
option(['single_player' => true]);
factory(\App\Models\Player::class)->create(['uid' => $user->uid]);