Harden legacy user profile lookups.
Keep the old user controller aligned with current profile fields and safer query handling.
This commit is contained in:
@@ -3,12 +3,12 @@
|
|||||||
namespace App\Http\Controllers\Legacy;
|
namespace App\Http\Controllers\Legacy;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Hash;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
use App\Services\AvatarService;
|
use App\Services\AvatarService;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
class UserController extends Controller
|
class UserController extends Controller
|
||||||
{
|
{
|
||||||
@@ -46,11 +46,21 @@ class UserController extends Controller
|
|||||||
|
|
||||||
// Collect other profile updates to persist into `user_profiles` when available
|
// Collect other profile updates to persist into `user_profiles` when available
|
||||||
$profileUpdates = [];
|
$profileUpdates = [];
|
||||||
if (!empty($data['web'])) $profileUpdates['website'] = $data['web'];
|
if (! empty($data['web'])) {
|
||||||
if (!empty($data['signature'])) $profileUpdates['signature'] = $data['signature'];
|
$profileUpdates['website'] = $data['web'];
|
||||||
if (!empty($data['description'])) $profileUpdates['description'] = $data['description'];
|
}
|
||||||
if (!empty($data['about_me'])) $profileUpdates['about'] = $data['about_me'];
|
if (! empty($data['signature'])) {
|
||||||
if (!empty($data['country_code'])) $profileUpdates['country_code'] = $data['country_code'];
|
$profileUpdates['signature'] = $data['signature'];
|
||||||
|
}
|
||||||
|
if (! empty($data['description'])) {
|
||||||
|
$profileUpdates['description'] = $data['description'];
|
||||||
|
}
|
||||||
|
if (! empty($data['about_me'])) {
|
||||||
|
$profileUpdates['about'] = $data['about_me'];
|
||||||
|
}
|
||||||
|
if (! empty($data['country_code'])) {
|
||||||
|
$profileUpdates['country_code'] = $data['country_code'];
|
||||||
|
}
|
||||||
|
|
||||||
$d1 = $request->input('date1');
|
$d1 = $request->input('date1');
|
||||||
$d2 = $request->input('date2');
|
$d2 = $request->input('date2');
|
||||||
@@ -60,10 +70,19 @@ class UserController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$userGender = $request->input('gender', $user->gender);
|
$userGender = $request->input('gender', $user->gender);
|
||||||
if (!empty($userGender)) {
|
if ($userGender !== null && $userGender !== '') {
|
||||||
$g = strtolower($userGender);
|
$g = strtolower(trim((string) $userGender));
|
||||||
$map = ['m' => 'M', 'f' => 'F', 'n' => 'X', 'x' => 'X'];
|
$map = [
|
||||||
$profileUpdates['gender'] = $map[$g] ?? strtoupper($userGender);
|
'm' => 'M',
|
||||||
|
'male' => 'M',
|
||||||
|
'f' => 'F',
|
||||||
|
'female' => 'F',
|
||||||
|
'n' => 'X',
|
||||||
|
'x' => 'X',
|
||||||
|
'na' => 'X',
|
||||||
|
'n/a' => 'X',
|
||||||
|
];
|
||||||
|
$profileUpdates['gender'] = $map[$g] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$profileUpdates['mlist'] = $request->has('newsletter') ? 1 : 0;
|
$profileUpdates['mlist'] = $request->has('newsletter') ? 1 : 0;
|
||||||
@@ -143,15 +162,33 @@ class UserController extends Controller
|
|||||||
$profile = DB::table('user_profiles')->where('user_id', $user->id)->first();
|
$profile = DB::table('user_profiles')->where('user_id', $user->id)->first();
|
||||||
if ($profile) {
|
if ($profile) {
|
||||||
// map modern profile fields onto the legacy user properties/helpers used by the view
|
// map modern profile fields onto the legacy user properties/helpers used by the view
|
||||||
if (isset($profile->website)) $user->homepage = $profile->website;
|
if (isset($profile->website)) {
|
||||||
if (isset($profile->about)) $user->about_me = $profile->about;
|
$user->homepage = $profile->website;
|
||||||
if (isset($profile->birthdate)) $user->birth = $profile->birthdate;
|
}
|
||||||
if (isset($profile->gender)) $user->gender = $profile->gender;
|
if (isset($profile->about)) {
|
||||||
if (isset($profile->country_code)) $user->country_code = $profile->country_code;
|
$user->about_me = $profile->about;
|
||||||
if (isset($profile->avatar_hash)) $user->icon = $profile->avatar_hash;
|
}
|
||||||
if (isset($profile->cover_image)) $user->picture = $profile->cover_image;
|
if (isset($profile->birthdate)) {
|
||||||
if (isset($profile->signature)) $user->signature = $profile->signature;
|
$user->birth = $profile->birthdate;
|
||||||
if (isset($profile->description)) $user->description = $profile->description;
|
}
|
||||||
|
if (isset($profile->gender)) {
|
||||||
|
$user->gender = $profile->gender;
|
||||||
|
}
|
||||||
|
if (isset($profile->country_code)) {
|
||||||
|
$user->country_code = $profile->country_code;
|
||||||
|
}
|
||||||
|
if (isset($profile->avatar_hash)) {
|
||||||
|
$user->icon = $profile->avatar_hash;
|
||||||
|
}
|
||||||
|
if (isset($profile->cover_image)) {
|
||||||
|
$user->picture = $profile->cover_image;
|
||||||
|
}
|
||||||
|
if (isset($profile->signature)) {
|
||||||
|
$user->signature = $profile->signature;
|
||||||
|
}
|
||||||
|
if (isset($profile->description)) {
|
||||||
|
$user->description = $profile->description;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user