[SECURITY][Register] New users should have their current browser language set as first language preference

This commit is contained in:
Diogo Peralta Cordeiro 2022-01-04 23:13:41 +00:00
parent 3f8fab0021
commit 0d1ab2c9cf
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
3 changed files with 8 additions and 1 deletions

View File

@ -29,6 +29,7 @@ use App\Util\Exception\NotFoundException;
use App\Util\Exception\ServerException;
use App\Util\Form\FormFields;
use App\Util\Nickname;
use Component\Language\Entity\ActorLanguage;
use Component\Subscription\Entity\Subscription;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use LogicException;
@ -166,6 +167,11 @@ class Security extends Controller
// Self subscription for the Home feed and alike
DB::persist(Subscription::create(['subscriber_id' => $id, 'subscribed_id' => $id]));
Feed::createDefaultFeeds($id, $user);
DB::persist(ActorLanguage::create([
'actor_id' => $id,
'language_id' => Common::currentLanguage()->getId(),
'ordering' => 1,
]));
},
);

View File

@ -235,6 +235,7 @@ abstract class Cache
/**
* Retrieve a list from the cache, with a different implementation
* for redis and others, trimming to $max_count if given
* TODO(hugo): $calculate = [] is the same as false miss
*
* @param callable(?CacheItem $item, bool &$save): (string|object|array<int,mixed>) $calculate
*/

View File

@ -323,6 +323,6 @@ abstract class Common
public static function currentLanguage(): Language
{
return self::actor()?->getTopLanguage() ?? Language::getByLocale(!\is_null(self::$request->headers->get('accept-language')) ? I18n::clientPreferredLanguage(self::$request->headers->get('accept-language')) : self::$request->getDefaultLocale());
return self::actor()?->getTopLanguage() ?? Language::getByLocale(!\is_null(self::$request->headers->get('accept-language')) ? I18n::clientPreferredLanguage(self::$request->headers->get('accept-language')) : self::config('site', 'language'));
}
}