Skip to content

Commit

Permalink
App store token verify
Browse files Browse the repository at this point in the history
  • Loading branch information
cuneytsenturk committed Apr 25, 2018
1 parent f9e7da3 commit 244b5aa
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
19 changes: 18 additions & 1 deletion app/Http/Requests/Module/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,26 @@
namespace App\Http\Requests\Module;

use App\Http\Requests\Request;
use Illuminate\Validation\Factory as ValidationFactory;
use App\Traits\Modules;

class Module extends Request
{
use Modules;

public function __construct(ValidationFactory $validationFactory)
{

$validationFactory->extend(
'check',
function ($attribute, $value, $parameters) {
return $this->checkToken($value);
},
trans('modules.invalid_token')
);

}

/**
* Determine if the user is authorized to make this request.
*
Expand All @@ -24,7 +41,7 @@ public function authorize()
public function rules()
{
return [
'api_token' => 'required|string',
'api_token' => 'required|string|check',
];
}
}
19 changes: 19 additions & 0 deletions app/Traits/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@
trait Modules
{

public function checkToken($token)
{
$data = [
'form_params' => [
'token' => $token,
]
];

$response = $this->getRemote('token/check', 'POST', $data);

if ($response->getStatusCode() == 200) {
$result = json_decode($response->getBody());

return ($result->success) ? true : false;
}

return false;
}

public function getModules()
{
$response = $this->getRemote('apps/items');
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en-GB/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

'title' => 'API Token',
'api_token' => 'Token',
'invalid_token' => 'Sorry, it invalid token validation!',
'top_paid' => 'Top Paid',
'new' => 'New',
'top_free' => 'Top Free',
Expand Down

0 comments on commit 244b5aa

Please sign in to comment.