GCTC-NTGC /
TalentCloud
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace App\Traits; |
||||||
| 4 | |||||||
| 5 | use Illuminate\Support\Str; |
||||||
| 6 | |||||||
| 7 | trait RememberDeviceTrait |
||||||
| 8 | { |
||||||
| 9 | /** |
||||||
| 10 | * The column name of the "remember device" token. |
||||||
| 11 | * |
||||||
| 12 | * @var string |
||||||
| 13 | */ |
||||||
| 14 | protected $rememberDeviceTokenName = 'remember_device_token'; |
||||||
| 15 | |||||||
| 16 | /** |
||||||
| 17 | * Get the token value for the "remember device" session. |
||||||
| 18 | * |
||||||
| 19 | * @return string|null |
||||||
| 20 | */ |
||||||
| 21 | public function getRememberDeviceToken() |
||||||
| 22 | { |
||||||
| 23 | if (!empty($this->getRememberDeviceTokenName())) { |
||||||
| 24 | return (string)$this->{$this->getRememberDeviceTokenName()}; |
||||||
| 25 | } |
||||||
| 26 | } |
||||||
| 27 | |||||||
| 28 | /** |
||||||
| 29 | * Set the token value for the "remember device" session. |
||||||
| 30 | * |
||||||
| 31 | * @param string $value |
||||||
| 32 | * @return void |
||||||
| 33 | */ |
||||||
| 34 | public function setRememberDeviceToken($value) |
||||||
| 35 | { |
||||||
| 36 | if (!empty($this->getRememberDeviceTokenName())) { |
||||||
| 37 | $this->{$this->getRememberDeviceTokenName()} = $value; |
||||||
| 38 | } |
||||||
| 39 | } |
||||||
| 40 | |||||||
| 41 | /** |
||||||
| 42 | * Get the column name for the "remember device" token. |
||||||
| 43 | * |
||||||
| 44 | * @return string |
||||||
| 45 | */ |
||||||
| 46 | public function getRememberDeviceTokenName() |
||||||
| 47 | { |
||||||
| 48 | return $this->rememberDeviceTokenName; |
||||||
| 49 | } |
||||||
| 50 | |||||||
| 51 | /** |
||||||
| 52 | * Refresh the "remember device" token for the User. |
||||||
| 53 | * |
||||||
| 54 | * @return void |
||||||
| 55 | */ |
||||||
| 56 | public function cycleRememberDeviceToken() |
||||||
| 57 | { |
||||||
| 58 | $this->setRememberDeviceToken(Str::random(60)); |
||||||
| 59 | $timestamps = $this->timestamps; |
||||||
| 60 | $this->timestamps = false; |
||||||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||||
| 61 | $this->save(); |
||||||
|
0 ignored issues
–
show
It seems like
save() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 62 | $this->timestamps = $timestamps; |
||||||
| 63 | } |
||||||
| 64 | |||||||
| 65 | /** |
||||||
| 66 | * Get a key to be used by a cookie for the |
||||||
| 67 | * remember device token. |
||||||
| 68 | * |
||||||
| 69 | * @return string |
||||||
| 70 | */ |
||||||
| 71 | public function getRememberDeviceKey(): string |
||||||
| 72 | { |
||||||
| 73 | return 'remember_device_' . sha1(static::class); |
||||||
| 74 | } |
||||||
| 75 | } |
||||||
| 76 |