Refactored Peer Information to use InformationFields rather than being hard-coded into the peer record
This commit is contained in:
parent
75de51c910
commit
f689e36378
45 changed files with 1422 additions and 1337 deletions
|
@ -10,20 +10,20 @@
|
|||
use Socialbox\Classes\OtpCryptography;
|
||||
use Socialbox\Exceptions\CryptographyException;
|
||||
use Socialbox\Exceptions\DatabaseOperationException;
|
||||
use Socialbox\Objects\Database\RegisteredPeerRecord;
|
||||
use Socialbox\Objects\Database\PeerRecord;
|
||||
|
||||
class OneTimePasswordManager
|
||||
{
|
||||
/**
|
||||
* Checks if a given peer uses OTP for authentication.
|
||||
*
|
||||
* @param string|RegisteredPeerRecord $peerUuid Either a UUID as a string or a RegisteredPeerRecord object representing the peer.
|
||||
* @param string|PeerRecord $peerUuid Either a UUID as a string or a RegisteredPeerRecord object representing the peer.
|
||||
* @return bool Returns true if the peer uses OTP, otherwise false.
|
||||
* @throws DatabaseOperationException Thrown when a database error occurs.
|
||||
*/
|
||||
public static function usesOtp(string|RegisteredPeerRecord $peerUuid): bool
|
||||
public static function usesOtp(string|PeerRecord $peerUuid): bool
|
||||
{
|
||||
if($peerUuid instanceof RegisteredPeerRecord)
|
||||
if($peerUuid instanceof PeerRecord)
|
||||
{
|
||||
$peerUuid = $peerUuid->getUuid();
|
||||
}
|
||||
|
@ -45,12 +45,12 @@
|
|||
/**
|
||||
* Creates and stores a new OTP (One-Time Password) secret for the specified peer, and generates a key URI.
|
||||
*
|
||||
* @param string|RegisteredPeerRecord $peer The unique identifier of the peer, either as a string UUID
|
||||
* @param string|PeerRecord $peer The unique identifier of the peer, either as a string UUID
|
||||
* or an instance of RegisteredPeerRecord.
|
||||
* @return string The generated OTP key URI that can be used for applications like authenticator apps.
|
||||
* @throws DatabaseOperationException If there is an error during the database operation.
|
||||
*/
|
||||
public static function createOtp(string|RegisteredPeerRecord $peer): string
|
||||
public static function createOtp(string|PeerRecord $peer): string
|
||||
{
|
||||
if(is_string($peer))
|
||||
{
|
||||
|
@ -84,16 +84,16 @@
|
|||
/**
|
||||
* Verifies the provided OTP (One-Time Password) against the stored secret associated with the specified peer.
|
||||
*
|
||||
* @param string|RegisteredPeerRecord $peerUuid The unique identifier of the peer, either as a string UUID
|
||||
* @param string|PeerRecord $peerUuid The unique identifier of the peer, either as a string UUID
|
||||
* or an instance of RegisteredPeerRecord.
|
||||
* @param string $otp The OTP to be verified.
|
||||
* @return bool Returns true if the OTP is valid; otherwise, false.
|
||||
* @throws DatabaseOperationException If there is an error during the database operation.
|
||||
* @throws CryptographyException If there is a failure in decrypting the stored OTP secret.
|
||||
*/
|
||||
public static function verifyOtp(string|RegisteredPeerRecord $peerUuid, string $otp): bool
|
||||
public static function verifyOtp(string|PeerRecord $peerUuid, string $otp): bool
|
||||
{
|
||||
if($peerUuid instanceof RegisteredPeerRecord)
|
||||
if($peerUuid instanceof PeerRecord)
|
||||
{
|
||||
$peerUuid = $peerUuid->getUuid();
|
||||
}
|
||||
|
@ -145,13 +145,13 @@
|
|||
/**
|
||||
* Deletes the OTP record associated with the specified peer.
|
||||
*
|
||||
* @param string|RegisteredPeerRecord $peerUuid The peer's UUID or an instance of RegisteredPeerRecord whose OTP record needs to be deleted.
|
||||
* @param string|PeerRecord $peerUuid The peer's UUID or an instance of RegisteredPeerRecord whose OTP record needs to be deleted.
|
||||
* @return void
|
||||
* @throws DatabaseOperationException if the database operation fails.
|
||||
*/
|
||||
public static function deleteOtp(string|RegisteredPeerRecord $peerUuid): void
|
||||
public static function deleteOtp(string|PeerRecord $peerUuid): void
|
||||
{
|
||||
if($peerUuid instanceof RegisteredPeerRecord)
|
||||
if($peerUuid instanceof PeerRecord)
|
||||
{
|
||||
$peerUuid = $peerUuid->getUuid();
|
||||
}
|
||||
|
@ -171,12 +171,12 @@
|
|||
/**
|
||||
* Retrieves the last updated timestamp for the OTP record of the specified peer.
|
||||
*
|
||||
* @param string|RegisteredPeerRecord $peerUuid The peer's UUID or an instance of RegisteredPeerRecord whose OTP record's last updated timestamp needs to be retrieved
|
||||
* @param string|PeerRecord $peerUuid The peer's UUID or an instance of RegisteredPeerRecord whose OTP record's last updated timestamp needs to be retrieved
|
||||
* @return int The last updated timestamp of the OTP record, or 0 if no such record exists
|
||||
*/
|
||||
public static function getLastUpdated(string|RegisteredPeerRecord $peerUuid): int
|
||||
public static function getLastUpdated(string|PeerRecord $peerUuid): int
|
||||
{
|
||||
if($peerUuid instanceof RegisteredPeerRecord)
|
||||
if($peerUuid instanceof PeerRecord)
|
||||
{
|
||||
$peerUuid = $peerUuid->getUuid();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue