Fix Pint formatting

This commit is contained in:
root
2026-06-09 01:25:14 -04:00
parent 6be4875c5e
commit 20a0b6c4e5
1485 changed files with 11318 additions and 10273 deletions
+65 -49
View File
@@ -4,9 +4,9 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Schema;
@@ -58,14 +58,14 @@ class User extends Authenticatable implements JWTSubject
];
protected $casts = [
'school_id' => 'integer',
'failed_attempts' => 'integer',
'last_failed_at' => 'datetime',
'accept_school_policy' => 'boolean',
'is_suspended' => 'boolean',
'is_verified' => 'boolean',
'created_at' => 'datetime',
'updated_at' => 'datetime',
'school_id' => 'integer',
'failed_attempts' => 'integer',
'last_failed_at' => 'datetime',
'accept_school_policy' => 'boolean',
'is_suspended' => 'boolean',
'is_verified' => 'boolean',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
public function getJWTIdentifier()
@@ -176,7 +176,7 @@ class User extends Authenticatable implements JWTSubject
$pivotColumns[] = 'school_year';
}
if (!empty($pivotColumns)) {
if (! empty($pivotColumns)) {
$relation->withPivot($pivotColumns);
}
@@ -218,7 +218,7 @@ class User extends Authenticatable implements JWTSubject
public function scopeHasAnyRoleNames(Builder $q, array $roleNames): Builder
{
$names = array_values(array_unique(array_filter(array_map(
fn($v) => strtolower(trim((string)$v)),
fn ($v) => strtolower(trim((string) $v)),
$roleNames
))));
@@ -267,8 +267,10 @@ class User extends Authenticatable implements JWTSubject
$order = strtolower($order) === 'desc' ? 'desc' : 'asc';
// whitelist to prevent SQL injection
$allowedSort = ['users.id','users.firstname','users.lastname','users.email','role'];
if (!in_array($sort, $allowedSort, true)) $sort = 'users.id';
$allowedSort = ['users.id', 'users.firstname', 'users.lastname', 'users.email', 'role'];
if (! in_array($sort, $allowedSort, true)) {
$sort = 'users.id';
}
$q = DB::table('users')
->select('users.id', 'users.firstname', 'users.lastname', 'users.email', DB::raw('roles.name as role'))
@@ -277,12 +279,12 @@ class User extends Authenticatable implements JWTSubject
// sorting "role" alias requires orderByRaw
if ($sort === 'role') {
$q->orderByRaw('role ' . strtoupper($order));
$q->orderByRaw('role '.strtoupper($order));
} else {
$q->orderBy($sort, $order);
}
return $q->get()->map(fn($r) => (array) $r)->all();
return $q->get()->map(fn ($r) => (array) $r)->all();
}
/**
@@ -312,14 +314,16 @@ class User extends Authenticatable implements JWTSubject
// whitelist sort fields
$allowedSort = [
'users.id','users.firstname','users.lastname','users.email','users.cellphone',
'users.school_year','users.status','users.created_at','users.updated_at'
'users.id', 'users.firstname', 'users.lastname', 'users.email', 'users.cellphone',
'users.school_year', 'users.status', 'users.created_at', 'users.updated_at',
];
if (!in_array($sort, $allowedSort, true)) $sort = 'users.id';
if (! in_array($sort, $allowedSort, true)) {
$sort = 'users.id';
}
$q = static::query();
if (!empty($conditions)) {
if (! empty($conditions)) {
$q->where($conditions);
}
@@ -329,7 +333,7 @@ class User extends Authenticatable implements JWTSubject
$q->skip($offset)->take($limit);
}
return $q->get()->map(fn($u) => $u->toArray())->all();
return $q->get()->map(fn ($u) => $u->toArray())->all();
}
/**
@@ -353,6 +357,7 @@ class User extends Authenticatable implements JWTSubject
public static function getAllUsers(string $sort = 'users.id', string $order = 'asc')
{
$order = strtolower($order) === 'desc' ? 'desc' : 'asc';
return static::query()->orderBy($sort, $order)->get();
}
@@ -364,15 +369,17 @@ class User extends Authenticatable implements JWTSubject
{
$user = static::query()
->select([
'id','account_id','lastname','firstname','gender','cellphone','email',
'address_street','apt','city','state','zip','accept_school_policy',
'user_type','rfid_tag','school_id','failed_attempts','last_failed_at',
'semester','school_year','status','is_suspended','created_at','updated_at',
'id', 'account_id', 'lastname', 'firstname', 'gender', 'cellphone', 'email',
'address_street', 'apt', 'city', 'state', 'zip', 'accept_school_policy',
'user_type', 'rfid_tag', 'school_id', 'failed_attempts', 'last_failed_at',
'semester', 'school_year', 'status', 'is_suspended', 'created_at', 'updated_at',
])
->where('id', $userId)
->first();
if (!$user) return null;
if (! $user) {
return null;
}
$roles = DB::table('user_roles as ur')
->select('r.id', 'r.name', 'r.slug')
@@ -380,7 +387,7 @@ class User extends Authenticatable implements JWTSubject
->where('ur.user_id', $userId)
->whereNull('ur.deleted_at')
->get()
->map(fn($r) => (array) $r)
->map(fn ($r) => (array) $r)
->all();
$arr = $user->toArray();
@@ -401,7 +408,7 @@ class User extends Authenticatable implements JWTSubject
->where('roles.name', $roleName)
->whereNull('user_roles.deleted_at')
->get()
->map(fn($r) => (array) $r)
->map(fn ($r) => (array) $r)
->all();
}
@@ -418,7 +425,7 @@ class User extends Authenticatable implements JWTSubject
->where('users.school_year', $schoolYear)
->whereNull('user_roles.deleted_at')
->get()
->map(fn($r) => (array) $r)
->map(fn ($r) => (array) $r)
->all();
}
@@ -445,6 +452,7 @@ class User extends Authenticatable implements JWTSubject
public static function getSchoolIdByUserId(int $userId): ?int
{
$v = static::query()->where('id', $userId)->value('school_id');
return $v === null ? null : (int) $v;
}
@@ -458,7 +466,9 @@ class User extends Authenticatable implements JWTSubject
->whereRaw('LOWER(name) = ?', ['parent'])
->value('id');
if (!$parentRoleId) return [];
if (! $parentRoleId) {
return [];
}
return DB::table('users')
->select('users.id', 'users.firstname', 'users.lastname', 'users.email', 'users.school_id')
@@ -467,7 +477,7 @@ class User extends Authenticatable implements JWTSubject
->whereNull('user_roles.deleted_at')
->groupBy('users.id', 'users.firstname', 'users.lastname', 'users.email', 'users.school_id')
->get()
->map(fn($r) => (array) $r)
->map(fn ($r) => (array) $r)
->all();
}
@@ -511,7 +521,9 @@ class User extends Authenticatable implements JWTSubject
// whitelist sort fields
$allowedSort = ['users.id', 'users.firstname', 'users.lastname', 'users.email', 'roles'];
if (!in_array($sort, $allowedSort, true)) $sort = 'users.lastname';
if (! in_array($sort, $allowedSort, true)) {
$sort = 'users.lastname';
}
$q = DB::table('users')
->selectRaw("
@@ -526,12 +538,14 @@ class User extends Authenticatable implements JWTSubject
->whereNull('ur.deleted_at')
->whereNotIn(DB::raw('LOWER(r.name)'), ['parent', 'guest']); // drop parent/guest
if (!empty($selectedUserIds)) {
if (! empty($selectedUserIds)) {
$ids = array_values(array_unique(array_filter(array_map('intval', $selectedUserIds))));
if (!empty($ids)) $q->whereIn('users.id', $ids);
if (! empty($ids)) {
$q->whereIn('users.id', $ids);
}
}
if (!empty($schoolYear)) {
if (! empty($schoolYear)) {
// Prefer ur.school_year if it exists (role is year-scoped)
$hasUrSchoolYear = false;
try {
@@ -581,7 +595,7 @@ class User extends Authenticatable implements JWTSubject
$q->orderBy($sort, strtolower($order));
}
return $q->get()->map(fn($r) => (array) $r)->all();
return $q->get()->map(fn ($r) => (array) $r)->all();
}
/* ============================================================
@@ -601,7 +615,7 @@ class User extends Authenticatable implements JWTSubject
->orderBy('users.lastname', 'asc')
->orderBy('users.firstname', 'asc')
->get()
->map(fn($u) => $u->toArray())
->map(fn ($u) => $u->toArray())
->all();
}
@@ -622,7 +636,7 @@ class User extends Authenticatable implements JWTSubject
->orderBy('u.lastname', 'asc')
->orderBy('u.firstname', 'asc')
->get()
->map(fn($r) => (array) $r)
->map(fn ($r) => (array) $r)
->all();
}
@@ -664,7 +678,7 @@ class User extends Authenticatable implements JWTSubject
->orderBy('users.lastname', 'asc')
->orderBy('users.firstname', 'asc')
->get()
->map(fn($r) => (array) $r)
->map(fn ($r) => (array) $r)
->all();
}
@@ -676,15 +690,15 @@ class User extends Authenticatable implements JWTSubject
public static function registrationRules(): array
{
return [
'password' => ['required', 'string', 'min:8', 'regex:/[A-Z]/', 'regex:/[a-z]/', 'regex:/[0-9]/', 'regex:/[\W_]/'],
'lastname' => ['required', 'string', 'max:120'],
'firstname' => ['required', 'string', 'max:120'],
'cellphone' => ['required', 'regex:/^\d{10}$/'],
'email' => ['required', 'email', 'max:255'],
'address_street' => ['required', 'string', 'max:255'],
'city' => ['required', 'string', 'max:120'],
'state' => ['required', 'regex:/^[A-Z]{2}$/'],
'zip' => ['required', 'regex:/^\d{5}(-\d{4})?$/'],
'password' => ['required', 'string', 'min:8', 'regex:/[A-Z]/', 'regex:/[a-z]/', 'regex:/[0-9]/', 'regex:/[\W_]/'],
'lastname' => ['required', 'string', 'max:120'],
'firstname' => ['required', 'string', 'max:120'],
'cellphone' => ['required', 'regex:/^\d{10}$/'],
'email' => ['required', 'email', 'max:255'],
'address_street' => ['required', 'string', 'max:255'],
'city' => ['required', 'string', 'max:120'],
'state' => ['required', 'regex:/^[A-Z]{2}$/'],
'zip' => ['required', 'regex:/^\d{5}(-\d{4})?$/'],
'accept_school_policy' => ['required', 'in:1,true,on'],
];
}
@@ -706,10 +720,12 @@ class User extends Authenticatable implements JWTSubject
*/
public function setPasswordAttribute($value): void
{
if ($value === null || $value === '') return;
if ($value === null || $value === '') {
return;
}
// Avoid double-hashing
$this->attributes['password'] = str_starts_with((string)$value, '$2y$')
$this->attributes['password'] = str_starts_with((string) $value, '$2y$')
? $value
: Hash::make($value);
}