X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FUser.php;h=4f56ac17f93b8af4ef2aff0c8478ee913ee19fd1;hb=d32516335ea2534e15256c948e9c38d3de40794b;hp=89963686eb21407d17eea9a5871d88658ff32d2b;hpb=4bf2dd1dd1f6d31b2ebe299b7495a8b0e259ec77;p=alttp.git diff --git a/app/Models/User.php b/app/Models/User.php index 8996368..4f56ac1 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,43 +2,91 @@ namespace App\Models; -use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Laravel\Sanctum\HasApiTokens; + class User extends Authenticatable { - use HasApiTokens, HasFactory, Notifiable; - - /** - * The attributes that are mass assignable. - * - * @var array - */ - protected $fillable = [ - 'name', - 'email', - 'password', - ]; - - /** - * The attributes that should be hidden for serialization. - * - * @var array - */ - protected $hidden = [ - 'password', - 'remember_token', - ]; - - /** - * The attributes that should be cast. - * - * @var array - */ - protected $casts = [ - 'email_verified_at' => 'datetime', - ]; + use HasApiTokens, HasFactory, Notifiable; + + public function isParticipant(Tournament $tournament) { + foreach ($tournament->participants as $participant) { + if ($participant->user_id == $this->id) { + return true; + } + } + return false; + } + + public function isRunner(Tournament $tournament) { + foreach ($tournament->participants as $participant) { + if ($participant->user_id == $this->id) { + return in_array('runner', $participant->roles); + } + } + return false; + } + + public function isTournamentAdmin(Tournament $tournament) { + foreach ($tournament->participants as $participant) { + if ($participant->user_id == $this->id) { + return in_array('admin', $participant->roles); + } + } + return false; + } + + public function participation() { + return $this->hasMany(Participant::class); + } + + /** + * The attributes that are mass assignable. + * + * @var string[] + */ + protected $fillable = [ + 'id', + 'username', + 'discriminator', + 'email', + 'avatar', + 'verified', + 'locale', + 'mfa_enabled', + 'refresh_token', + 'role', + ]; + + /** + * The attributes that should be hidden for serialization. + * + * @var array + */ + protected $hidden = [ + 'email', + 'mfa_enabled', + 'refresh_token', + 'remember_token', + ]; + + /** + * The attributes that should be cast. + * + * @var array + */ + protected $casts = [ + 'id' => 'string', + 'username' => 'string', + 'discriminator' => 'string', + 'email' => 'string', + 'avatar' => 'string', + 'verified' => 'boolean', + 'locale' => 'string', + 'mfa_enabled' => 'boolean', + 'refresh_token' => 'encrypted', + ]; }