rbrecruiter/app/Traits/HandlesAccountTokens.php
Miguel Nogueira 596a469e15 Add user invitation facilities RSM-5
Adds user invitation to teams, and framework for assigning taems
Also adds user acc. deletion.
2020-10-08 19:19:10 +01:00

51 lines
1008 B
PHP

<?php
namespace App\Traits;
use Illuminate\Support\Facades\Hash;
trait HandlesAccountTokens
{
public function generateAccountTokens()
{
$deleteToken = bin2hex(openssl_random_pseudo_bytes(32));
$cancelToken = bin2hex(openssl_random_pseudo_bytes(32));
$tokens = [
'delete' => Hash::make($deleteToken),
'cancel' => Hash::make($cancelToken)
];
$this->account_tokens = json_encode($tokens);
$this->save();
return [
'delete' => $deleteToken,
'cancel' => $cancelToken
];
}
public function verifyAccountToken(string $token, string $type): bool
{
$tokens = json_decode($this->account_tokens);
if ($type == 'deleteToken')
{
return Hash::check($token, $tokens->delete);
}
elseif ($type == 'cancelToken')
{
return Hash::check($token, $tokens->cancel);
}
return false;
}
}