95
app/User.php
95
app/User.php
@@ -24,21 +24,15 @@ namespace App;
|
||||
use App\Services\AccountSuspensionService;
|
||||
use App\Traits\HandlesAccountTokens;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Mpociot\Teamwork\Traits\UserHasTeams;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
|
||||
class User extends Authenticatable implements MustVerifyEmail
|
||||
{
|
||||
use UserHasTeams, Notifiable, HasRoles, HasFactory;
|
||||
use UserHasTeams, Notifiable, HasRoles;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
@@ -46,19 +40,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
'originalIP',
|
||||
'registrationIp',
|
||||
'username',
|
||||
'uuid',
|
||||
'dob',
|
||||
'email_verified_at',
|
||||
'currentIp',
|
||||
'discord_user_id',
|
||||
'discord_token',
|
||||
'discord_refresh_token'
|
||||
'name', 'email', 'password', 'originalIP', 'username', 'uuid', 'dob',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -67,7 +49,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password', 'remember_token', 'discord_token', 'discord_refresh_token'
|
||||
'password', 'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -77,8 +59,6 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
'discord_token' => 'encrypted',
|
||||
'discord_refresh_token' => 'encrypted'
|
||||
];
|
||||
|
||||
// RELATIONSHIPS
|
||||
@@ -91,7 +71,6 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
public function votes()
|
||||
{
|
||||
return $this->hasMany('App\Vote', 'userID', 'id');
|
||||
|
||||
}
|
||||
|
||||
public function profile()
|
||||
@@ -120,52 +99,32 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
}
|
||||
|
||||
|
||||
public function isEligible(): bool {
|
||||
$lastApplication = Application::where('applicantUserID', $this->getAttribute('id'))->latest()->first();
|
||||
|
||||
if (is_null($lastApplication)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($lastApplication->created_at->diffInMonths(now()) > 1 && in_array($lastApplication->applicationStatus, ['DENIED', 'APPROVED'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function isVerified(): bool {
|
||||
return !is_null($this->email_verified_at);
|
||||
}
|
||||
// UTILITY LOGIC
|
||||
|
||||
/**
|
||||
* Checks if user is staff
|
||||
* Checks if a user is banned.
|
||||
*
|
||||
* @deprecated This method is being replaced by a better way of checking permissions, rather than checking for group name.
|
||||
* @return bool
|
||||
* @deprecated This method is obsolete, as it has been replaced by the suspension service.
|
||||
* @see AccountSuspensionService::isSuspended()
|
||||
*
|
||||
* @return bool Whether the user is banned
|
||||
*/
|
||||
public function isStaffMember(): bool
|
||||
public function isBanned(): bool
|
||||
{
|
||||
return ! $this->bans()->get()->isEmpty();
|
||||
}
|
||||
|
||||
public function isStaffMember()
|
||||
{
|
||||
return $this->hasAnyRole('reviewer', 'admin', 'hiringManager');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if user has 2fa enabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function has2FA(): bool
|
||||
public function has2FA()
|
||||
{
|
||||
return ! is_null($this->twofa_secret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if user has team
|
||||
*
|
||||
* @param $team
|
||||
* @return bool
|
||||
*/
|
||||
public function hasTeam($team): bool
|
||||
{
|
||||
if ($team instanceof Team || is_int($team))
|
||||
@@ -181,23 +140,9 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user linked their Discord account
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasDiscordConnection(): bool {
|
||||
return !is_null($this->discord_token) && !is_null($this->discord_refresh_token);
|
||||
|
||||
public function routeNotificationForSlack($notification)
|
||||
{
|
||||
return config('slack.webhook.integrationURL');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if user has a password
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPassword(): bool {
|
||||
return !is_null($this->password);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user