Skip to content

Commit

Permalink
Merge pull request #8 from Braunson/5.5
Browse files Browse the repository at this point in the history
Added config option to allow tokens or default to auth
  • Loading branch information
jarektkaczyk authored Jan 15, 2018
2 parents b10aa56 + 8d0cf0a commit 90b6a2d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions published/config.stub
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ return [
*/
'user_model' => 'App\User',

/*
|--------------------------------------------------------------------------
| Do you want to use tokens or just check based on the user authorized?
|--------------------------------------------------------------------------
*/
'use_tokens' => true,

/*
|--------------------------------------------------------------------------
| Channels for events broadcasting.
Expand Down
1 change: 1 addition & 0 deletions spec/LockingSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
'model_locking.use_authenticated_user' => null,
'model_locking.request_shorten_duration' => null,
'model_locking.user' => null,
'model_locking.use_tokens' => true,
'auth.providers.users.model' => null,
];
});
Expand Down
8 changes: 6 additions & 2 deletions src/ModelLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ public function generateToken()
* @param string $token
* @return boolean
*/
public function verify($token)
public function verify($token = null)
{
return $this->token === $token;
if (config('model_locking.use_tokens', true)) {
return $this->token === $token;
}

return $this->user_id === auth()->user()->id;
}

/**
Expand Down

0 comments on commit 90b6a2d

Please sign in to comment.