Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Authentication/Authenticators/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ public function login(User $user): void
$this->completeLogin($user);
}

private function issueRememberMeToken()
private function issueRememberMeToken(): void
{
if ($this->shouldRemember && setting('Auth.sessionConfig')['allowRemembering']) {
$this->rememberUser($this->user);
Expand Down
8 changes: 4 additions & 4 deletions src/Authentication/Traits/HasAccessTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ public function generateAccessToken(string $name, array $scopes = ['*']): Access
/**
* Delete any access tokens for the given raw token.
*/
public function revokeAccessToken(string $rawToken): bool
public function revokeAccessToken(string $rawToken): void
{
/** @var UserIdentityModel $identityModel */
$identityModel = model(UserIdentityModel::class);

return $identityModel->revokeAccessToken($this, $rawToken);
$identityModel->revokeAccessToken($this, $rawToken);
}

/**
* Revokes all access tokens for this user.
*/
public function revokeAllAccessTokens(): bool
public function revokeAllAccessTokens(): void
{
/** @var UserIdentityModel $identityModel */
$identityModel = model(UserIdentityModel::class);

return $identityModel->revokeAllAccessTokens($this);
$identityModel->revokeAllAccessTokens($this);
}

/**
Expand Down
10 changes: 8 additions & 2 deletions src/Models/GroupModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

class GroupModel extends Model
{
use CheckQueryReturnTrait;

protected $table = 'auth_groups_users';
protected $primaryKey = 'id';
protected $returnType = 'array';
Expand Down Expand Up @@ -37,9 +39,11 @@ public function getForUser(User $user): array
*/
public function deleteAll($userId): void
{
$this->builder()
$return = $this->builder()
->where('user_id', $userId)
->delete();

$this->checkQueryReturn($return);
}

/**
Expand All @@ -48,9 +52,11 @@ public function deleteAll($userId): void
*/
public function deleteNotIn($userId, $cache): void
{
$this->builder()
$return = $this->builder()
->where('user_id', $userId)
->whereNotIn('group', $cache)
->delete();

$this->checkQueryReturn($return);
}
}
10 changes: 8 additions & 2 deletions src/Models/PermissionModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

class PermissionModel extends Model
{
use CheckQueryReturnTrait;

protected $table = 'auth_permissions_users';
protected $primaryKey = 'id';
protected $returnType = 'array';
Expand Down Expand Up @@ -37,9 +39,11 @@ public function getForUser(User $user): array
*/
public function deleteAll($userId): void
{
$this->builder()
$return = $this->builder()
->where('user_id', $userId)
->delete();

$this->checkQueryReturn($return);
}

/**
Expand All @@ -48,9 +52,11 @@ public function deleteAll($userId): void
*/
public function deleteNotIn($userId, $cache): void
{
$this->builder()
$return = $this->builder()
->where('user_id', $userId)
->whereNotIn('permission', $cache)
->delete();

$this->checkQueryReturn($return);
}
}
28 changes: 20 additions & 8 deletions src/Models/UserIdentityModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ public function createEmailIdentity(User $user, array $credentials): void
/** @var Passwords $passwords */
$passwords = service('passwords');

$this->insert([
$return = $this->insert([
'user_id' => $user->id,
'type' => 'email_password',
'secret' => $credentials['email'],
'secret2' => $passwords->hash($credentials['password']),
]);

$this->checkQueryReturn($return);
}

/**
Expand Down Expand Up @@ -116,14 +118,16 @@ public function generateAccessToken(User $user, string $name, array $scopes = ['
{
helper('text');

$this->insert([
$return = $this->insert([
'type' => 'access_token',
'user_id' => $user->id,
'name' => $name,
'secret' => hash('sha256', $rawToken = random_string('crypto', 64)),
'extra' => serialize($scopes),
]);

$this->checkQueryReturn($return);

/** @var AccessToken $token */
$token = $this
->asObject(AccessToken::class)
Expand Down Expand Up @@ -243,35 +247,43 @@ public function touchIdentity(UserIdentity $identity): void
{
$identity->last_used_at = date('Y-m-d H:i:s');

$this->save($identity);
$return = $this->save($identity);

$this->checkQueryReturn($return);
}

public function deleteIdentitiesByType(User $user, string $type): void
{
$this->where('user_id', $user->id)
$return = $this->where('user_id', $user->id)
->where('type', $type)
->delete();

$this->checkQueryReturn($return);
}

/**
* Delete any access tokens for the given raw token.
*/
public function revokeAccessToken(User $user, string $rawToken)
public function revokeAccessToken(User $user, string $rawToken): void
{
return $this->where('user_id', $user->id)
$return = $this->where('user_id', $user->id)
->where('type', 'access_token')
->where('secret', hash('sha256', $rawToken))
->delete();

$this->checkQueryReturn($return);
}

/**
* Revokes all access tokens for this user.
*/
public function revokeAllAccessTokens(User $user)
public function revokeAllAccessTokens(User $user): void
{
return $this->where('user_id', $user->id)
$return = $this->where('user_id', $user->id)
->where('type', 'access_token')
->delete();

$this->checkQueryReturn($return);
}

public function fake(Generator &$faker): UserIdentity
Expand Down
2 changes: 2 additions & 0 deletions src/Models/UserModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ public function activate(User $user): void
* fields if they've been modified.
*
* @param array|User $data
*
* @TODO can't change the return type to void.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think we should find a way to handle this with model callback events so we can catch update() etc. That would solve the return typing.

*/
public function save($data): bool
{
Expand Down