1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\User; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
use Chrisbjr\ApiGuard\Models\ApiKey; |
8
|
|
|
use App\Http\Requests; |
9
|
|
|
|
10
|
|
|
class ApiKeyController extends Controller |
11
|
|
|
{ |
12
|
|
|
protected $apiKey; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* ApiKeyController constructor. |
16
|
|
|
* @param ApiKey $apiKey |
17
|
|
|
*/ |
18
|
|
|
public function __construct(ApiKey $apiKey) |
19
|
|
|
{ |
20
|
|
|
$this->middleware('auth'); |
21
|
|
|
$this->middleware('lang'); |
22
|
|
|
|
23
|
|
|
$this->apiKey = $apiKey; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Create a new api token. |
28
|
|
|
* |
29
|
|
|
* TODO: implement session to the view. |
30
|
|
|
* TODO: Build api key limit that the user can have max. 5 keys. |
31
|
|
|
* @param Request $request |
32
|
|
|
* @return \Illuminate\Http\RedirectResponse |
33
|
|
|
*/ |
34
|
|
|
public function makeKey(Request $request) |
35
|
|
|
{ |
36
|
|
|
$id = auth()->user()->id; |
|
|
|
|
37
|
|
|
$create = $this->apiKey->make($id); |
38
|
|
|
$insertedId = $create->id; |
39
|
|
|
|
40
|
|
|
$serviceInsert = $this->apiKey->find($insertedId); |
41
|
|
|
$serviceInsert->service = $request->get('service'); |
42
|
|
|
$serviceInsert->save(); |
43
|
|
|
|
44
|
|
|
$token = $this->apiKey->find($insertedId); |
45
|
|
|
|
46
|
|
|
session()->flash('message', 'Token created'); |
47
|
|
|
session()->flash('token', $token->key); |
48
|
|
|
return redirect()->back(302); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function revokeKey() |
52
|
|
|
{ |
53
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get the apikey |
58
|
|
|
* |
59
|
|
|
* @param int $id the database id off the api key. |
60
|
|
|
* @return \Illuminate\Http\RedirectResponse |
61
|
|
|
*/ |
62
|
|
|
public function getKey($id) |
|
|
|
|
63
|
|
|
{ |
64
|
|
|
return redirect()->back(302); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Delete a api key out off the system. |
69
|
|
|
* |
70
|
|
|
* @param int $id the database id off the api key. |
71
|
|
|
* @return \Illuminate\Http\RedirectResponse |
72
|
|
|
*/ |
73
|
|
|
public function deleteKey($id) |
74
|
|
|
{ |
75
|
|
|
$this->apiKey->destroy($id); |
76
|
|
|
session()->flash('message', 'The api key is deleted.'); |
77
|
|
|
|
78
|
|
|
return redirect()->back(302); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.