feat: add accessor and mutator for encrypting/decrypting discord tokens
This commit is contained in:
parent
d4c144b2d2
commit
a5cbd31b76
29
app/User.php
29
app/User.php
@ -24,9 +24,11 @@ namespace App;
|
|||||||
use App\Services\AccountSuspensionService;
|
use App\Services\AccountSuspensionService;
|
||||||
use App\Traits\HandlesAccountTokens;
|
use App\Traits\HandlesAccountTokens;
|
||||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||||
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
|
use Illuminate\Support\Facades\Crypt;
|
||||||
use Mpociot\Teamwork\Traits\UserHasTeams;
|
use Mpociot\Teamwork\Traits\UserHasTeams;
|
||||||
use Spatie\Permission\Traits\HasRoles;
|
use Spatie\Permission\Traits\HasRoles;
|
||||||
|
|
||||||
@ -100,6 +102,33 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ACCESSORS AND MUTATORS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encrypt/decrypt the Discord access token. Data is encrypted at rest.
|
||||||
|
*
|
||||||
|
* @return Attribute
|
||||||
|
*/
|
||||||
|
public function discordToken(): Attribute {
|
||||||
|
return Attribute::make(
|
||||||
|
get: fn ($value) => Crypt::decryptString($value),
|
||||||
|
set: fn ($value) => Crypt::encryptString($value)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encrypt/decrypt the Discord refresh token. Data is encrypted at rest.
|
||||||
|
*
|
||||||
|
* @return Attribute
|
||||||
|
*/
|
||||||
|
public function discordRefreshToken(): Attribute {
|
||||||
|
return Attribute::make(
|
||||||
|
get: fn ($value) => Crypt::decryptString($value),
|
||||||
|
set: fn ($value) => Crypt::encryptString($value)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// UTILITY LOGIC
|
// UTILITY LOGIC
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user