feat: locale
This commit is contained in:
@@ -65,6 +65,10 @@ class AuthController extends Controller
|
||||
], 401);
|
||||
}
|
||||
|
||||
if (isset($data['locale']) && $user->locale !== $data['locale']) {
|
||||
$user->forceFill(['locale' => $data['locale']])->save();
|
||||
}
|
||||
|
||||
if (! $user->hasVerifiedEmail()) {
|
||||
return response()->json([
|
||||
'message' => __('api.auth.email_not_verified'),
|
||||
@@ -162,9 +166,13 @@ class AuthController extends Controller
|
||||
|
||||
public function showResetPasswordForm(Request $request, string $token): View
|
||||
{
|
||||
$email = (string) $request->query('email', '');
|
||||
$locale = $this->localeForEmail($email);
|
||||
|
||||
return view('auth.reset-password', [
|
||||
'appName' => config('app.name'),
|
||||
'email' => (string) $request->query('email', ''),
|
||||
'email' => $email,
|
||||
'locale' => $locale,
|
||||
'passwordReset' => false,
|
||||
'token' => $token,
|
||||
]);
|
||||
@@ -172,6 +180,9 @@ class AuthController extends Controller
|
||||
|
||||
public function resetPasswordFromView(ResetPasswordRequest $request): RedirectResponse|View
|
||||
{
|
||||
$locale = $this->localeForEmail((string) $request->validated('email'));
|
||||
app()->setLocale($locale);
|
||||
|
||||
$status = $this->resetPasswordFor($request->safe());
|
||||
|
||||
if ($status !== Password::PASSWORD_RESET) {
|
||||
@@ -183,6 +194,7 @@ class AuthController extends Controller
|
||||
return view('auth.reset-password', [
|
||||
'appName' => config('app.name'),
|
||||
'email' => strtolower($request->validated('email')),
|
||||
'locale' => $locale,
|
||||
'passwordReset' => true,
|
||||
'token' => '',
|
||||
]);
|
||||
@@ -298,6 +310,11 @@ class AuthController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
private function localeForEmail(string $email): string
|
||||
{
|
||||
return User::where('email', strtolower($email))->value('locale') ?: 'en';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
@@ -307,6 +324,7 @@ class AuthController extends Controller
|
||||
$attributes = Arr::only($data, [
|
||||
'name',
|
||||
'avatar_url',
|
||||
'locale',
|
||||
'height',
|
||||
'bio',
|
||||
'sex',
|
||||
|
||||
Reference in New Issue
Block a user