-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from ligerphp/1.0.1
1.0.1
- Loading branch information
Showing
61 changed files
with
2,827 additions
and
1,056 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
<?php | ||
|
||
namespace Core\Auth; | ||
|
||
use Core\Http\Request; | ||
use Core\Contracts\Auth\Guard; | ||
use Illuminate\Contracts\Auth\UserProvider; | ||
|
||
class TokenGuard implements Guard | ||
{ | ||
use GuardHelpers; | ||
|
||
/** | ||
* The request instance. | ||
* | ||
* @var \Illuminate\Http\Request | ||
*/ | ||
protected $request; | ||
|
||
/** | ||
* The name of the query string item from the request containing the API token. | ||
* | ||
* @var string | ||
*/ | ||
protected $inputKey; | ||
|
||
/** | ||
* The name of the token "column" in persistent storage. | ||
* | ||
* @var string | ||
*/ | ||
protected $storageKey; | ||
|
||
/** | ||
* Create a new authentication guard. | ||
* | ||
* @param \Illuminate\Contracts\Auth\UserProvider $provider | ||
* @param \Illuminate\Http\Request $request | ||
* @param string $inputKey | ||
* @param string $storageKey | ||
* @return void | ||
*/ | ||
public function __construct(UserProvider $provider, Request $request, $inputKey = 'api_token', $storageKey = 'api_token') | ||
{ | ||
$this->request = $request; | ||
$this->provider = $provider; | ||
$this->inputKey = $inputKey; | ||
$this->storageKey = $storageKey; | ||
} | ||
|
||
/** | ||
* Get the currently authenticated user. | ||
* | ||
* @return \Illuminate\Contracts\Auth\Authenticatable|null | ||
*/ | ||
public function user() | ||
{ | ||
// If we've already retrieved the user for the current request we can just | ||
// return it back immediately. We do not want to fetch the user data on | ||
// every call to this method because that would be tremendously slow. | ||
if (! is_null($this->user)) { | ||
return $this->user; | ||
} | ||
|
||
$user = null; | ||
|
||
$token = $this->getTokenForRequest(); | ||
|
||
if (! empty($token)) { | ||
$user = $this->provider->retrieveByCredentials( | ||
[$this->storageKey => $token] | ||
); | ||
} | ||
|
||
return $this->user = $user; | ||
} | ||
|
||
/** | ||
* Get the token for the current request. | ||
* | ||
* @return string | ||
*/ | ||
public function getTokenForRequest() | ||
{ | ||
$token = $this->request->query($this->inputKey); | ||
|
||
if (empty($token)) { | ||
$token = $this->request->input($this->inputKey); | ||
} | ||
|
||
if (empty($token)) { | ||
$token = $this->request->bearerToken(); | ||
} | ||
|
||
if (empty($token)) { | ||
$token = $this->request->getPassword(); | ||
} | ||
|
||
return $token; | ||
} | ||
|
||
/** | ||
* Validate a user's credentials. | ||
* | ||
* @param array $credentials | ||
* @return bool | ||
*/ | ||
public function validate(array $credentials = []) | ||
{ | ||
if (empty($credentials[$this->inputKey])) { | ||
return false; | ||
} | ||
|
||
$credentials = [$this->storageKey => $credentials[$this->inputKey]]; | ||
|
||
if ($this->provider->retrieveByCredentials($credentials)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Set the current request instance. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return $this | ||
*/ | ||
public function setRequest(Request $request) | ||
{ | ||
$this->request = $request; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
namespace Core\Cart; | ||
|
||
interface CartInterface { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
/** | ||
* Manages the logic behind creating a cart | ||
* | ||
*/ |
Oops, something went wrong.