51 lines
1.4 KiB
PHP
51 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories;
|
|
|
|
use App\Models\User;
|
|
use DateTime;
|
|
|
|
class UserRepository {
|
|
public function findByUsername(string $username) : ?User {
|
|
return User::where(['username' => $username])->first();
|
|
}
|
|
|
|
public function checkVerificationToken(User $user, string $token) : bool {
|
|
if (new DateTime() > DateTime::createFromFormat('Y-m-d H:i:s', $user->activation_token_expires_at)) {
|
|
return false;
|
|
}
|
|
|
|
return $token === $user->activation_token;
|
|
}
|
|
|
|
public function getCurrentUserDetails() : array {
|
|
$user = auth()->user();
|
|
|
|
$return = [
|
|
'userId' => null,
|
|
'userName' => '',
|
|
'userEmail' => '',
|
|
'userTelephone' => '',
|
|
'userAccountOwner' => '',
|
|
'userAccountIban' => '',
|
|
];
|
|
|
|
if (null !== auth()->user()) {
|
|
$return = [
|
|
'userId' => $user->id,
|
|
'userName' => trim($user->getOfficialName()),
|
|
'userEmail' => trim($user->email),
|
|
'userTelephone' => trim($user->phone),
|
|
'userAccountOwner' => trim($user->bank_account_owner),
|
|
'userAccountIban' => trim($user->bank_account_iban),
|
|
];
|
|
|
|
if ($return['userAccountOwner'] === '') {
|
|
$return['userAccountOwner'] = $return['userName'];
|
|
}
|
|
}
|
|
|
|
return $return;
|
|
}
|
|
}
|