2020-11-24 12:17:55 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2022-03-12 07:11:20 +08:00
|
|
|
* This file is part of Flarum.
|
2020-11-24 12:17:55 +08:00
|
|
|
*
|
2022-03-12 07:11:20 +08:00
|
|
|
* For detailed copyright and license information, please view the
|
|
|
|
* LICENSE file that was distributed with this source code.
|
2020-11-24 12:17:55 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Flarum\Nicknames;
|
|
|
|
|
2020-12-01 09:48:10 +08:00
|
|
|
use Flarum\Api\Serializer\UserSerializer;
|
2020-11-24 12:17:55 +08:00
|
|
|
use Flarum\Extend;
|
2021-11-18 00:17:36 +08:00
|
|
|
use Flarum\Nicknames\Access\UserPolicy;
|
2023-11-12 02:43:09 +08:00
|
|
|
use Flarum\Search\Database\DatabaseSearchDriver;
|
2020-11-24 12:17:55 +08:00
|
|
|
use Flarum\User\Event\Saving;
|
2021-04-05 01:41:15 +08:00
|
|
|
use Flarum\User\Search\UserSearcher;
|
2021-11-18 00:17:36 +08:00
|
|
|
use Flarum\User\User;
|
2020-12-01 09:48:10 +08:00
|
|
|
use Flarum\User\UserValidator;
|
2020-11-24 12:17:55 +08:00
|
|
|
|
|
|
|
return [
|
|
|
|
(new Extend\Frontend('forum'))
|
2022-03-12 07:11:20 +08:00
|
|
|
->js(__DIR__.'/js/dist/forum.js'),
|
2020-11-24 12:17:55 +08:00
|
|
|
|
|
|
|
(new Extend\Frontend('admin'))
|
2022-03-12 07:11:20 +08:00
|
|
|
->js(__DIR__.'/js/dist/admin.js'),
|
2020-11-24 12:17:55 +08:00
|
|
|
|
2022-03-12 07:11:20 +08:00
|
|
|
new Extend\Locales(__DIR__.'/locale'),
|
2020-12-24 05:10:51 +08:00
|
|
|
|
2023-01-20 04:49:38 +08:00
|
|
|
(new Extend\Model(User::class))
|
|
|
|
->cast('nickname', 'string'),
|
|
|
|
|
2020-11-24 12:17:55 +08:00
|
|
|
(new Extend\User())
|
|
|
|
->displayNameDriver('nickname', NicknameDriver::class),
|
|
|
|
|
|
|
|
(new Extend\Event())
|
2021-04-05 01:41:15 +08:00
|
|
|
->listen(Saving::class, SaveNicknameToDatabase::class),
|
2020-11-24 12:17:55 +08:00
|
|
|
|
2020-12-01 09:48:10 +08:00
|
|
|
(new Extend\ApiSerializer(UserSerializer::class))
|
2022-02-21 22:56:51 +08:00
|
|
|
->attribute('canEditNickname', function (UserSerializer $serializer, User $user) {
|
|
|
|
return $serializer->getActor()->can('editNickname', $user);
|
2020-12-01 09:48:10 +08:00
|
|
|
}),
|
|
|
|
|
2021-03-14 06:18:55 +08:00
|
|
|
(new Extend\Settings())
|
2021-11-18 00:17:36 +08:00
|
|
|
->default('flarum-nicknames.set_on_registration', true)
|
|
|
|
->default('flarum-nicknames.min', 1)
|
|
|
|
->default('flarum-nicknames.max', 150)
|
2023-11-11 05:20:18 +08:00
|
|
|
->default('display_name_driver', 'username')
|
|
|
|
->serializeToForum('displayNameDriver', 'display_name_driver')
|
2021-11-18 00:17:36 +08:00
|
|
|
->serializeToForum('setNicknameOnRegistration', 'flarum-nicknames.set_on_registration', 'boolval')
|
|
|
|
->serializeToForum('randomizeUsernameOnRegistration', 'flarum-nicknames.random_username', 'boolval'),
|
2020-12-03 06:29:39 +08:00
|
|
|
|
2020-12-01 09:48:10 +08:00
|
|
|
(new Extend\Validator(UserValidator::class))
|
|
|
|
->configure(AddNicknameValidation::class),
|
|
|
|
|
2023-11-12 02:43:09 +08:00
|
|
|
(new Extend\SearchDriver(DatabaseSearchDriver::class))
|
|
|
|
->setFulltext(UserSearcher::class, NicknameFullTextFilter::class),
|
2021-11-18 00:17:36 +08:00
|
|
|
|
|
|
|
(new Extend\Policy())
|
|
|
|
->modelPolicy(User::class, UserPolicy::class),
|
2020-11-24 12:17:55 +08:00
|
|
|
];
|