Revert "Revert "merge 1""

This reverts commit 0c463d1f10.
This commit is contained in:
2022-10-24 01:04:22 +01:00
parent 0c463d1f10
commit b89d71b371
166 changed files with 4250 additions and 1833 deletions

View File

@@ -24,15 +24,21 @@ 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;
use UserHasTeams, Notifiable, HasRoles, HasFactory;
/**
* The attributes that are mass assignable.
@@ -40,7 +46,19 @@ class User extends Authenticatable implements MustVerifyEmail
* @var array
*/
protected $fillable = [
'name', 'email', 'password', 'originalIP', 'username', 'uuid', 'dob',
'name',
'email',
'password',
'originalIP',
'registrationIp',
'username',
'uuid',
'dob',
'email_verified_at',
'currentIp',
'discord_user_id',
'discord_token',
'discord_refresh_token'
];
/**
@@ -49,7 +67,7 @@ class User extends Authenticatable implements MustVerifyEmail
* @var array
*/
protected $hidden = [
'password', 'remember_token',
'password', 'remember_token', 'discord_token', 'discord_refresh_token'
];
/**
@@ -59,6 +77,8 @@ class User extends Authenticatable implements MustVerifyEmail
*/
protected $casts = [
'email_verified_at' => 'datetime',
'discord_token' => 'encrypted',
'discord_refresh_token' => 'encrypted'
];
// RELATIONSHIPS
@@ -71,6 +91,7 @@ class User extends Authenticatable implements MustVerifyEmail
public function votes()
{
return $this->hasMany('App\Vote', 'userID', 'id');
}
public function profile()
@@ -99,32 +120,52 @@ class User extends Authenticatable implements MustVerifyEmail
}
public function isEligible(): bool {
$lastApplication = Application::where('applicantUserID', $this->getAttribute('id'))->latest()->first();
// UTILITY LOGIC
if (is_null($lastApplication)) {
return true;
}
/**
* Checks if a user is banned.
*
* @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 isBanned(): bool
{
return ! $this->bans()->get()->isEmpty();
if ($lastApplication->created_at->diffInMonths(now()) > 1 && in_array($lastApplication->applicationStatus, ['DENIED', 'APPROVED'])) {
return true;
}
return false;
}
public function isStaffMember()
public function isVerified(): bool {
return !is_null($this->email_verified_at);
}
/**
* Checks if user is staff
*
* @deprecated This method is being replaced by a better way of checking permissions, rather than checking for group name.
* @return bool
*/
public function isStaffMember(): bool
{
return $this->hasAnyRole('reviewer', 'admin', 'hiringManager');
}
public function has2FA()
/**
* Checks if user has 2fa enabled
*
* @return bool
*/
public function has2FA(): bool
{
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))
@@ -140,9 +181,23 @@ class User extends Authenticatable implements MustVerifyEmail
}
}
public function routeNotificationForSlack($notification)
{
return config('slack.webhook.integrationURL');
/**
* 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);
}
/**
* Check if user has a password
*
* @return bool
*/
public function hasPassword(): bool {
return !is_null($this->password);
}
}