1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace crocodicstudio\crudbooster\Modules\ApiGeneratorModule; |
4
|
|
|
|
5
|
|
|
use crocodicstudio\crudbooster\controllers\CBController; |
6
|
|
|
use crocodicstudio\crudbooster\helpers\CbValidator; |
7
|
|
|
use Illuminate\Support\Facades\DB; |
8
|
|
|
|
9
|
|
|
class AdminApiKeyController extends CBController |
10
|
|
|
{ |
11
|
|
|
public function cbInit() |
12
|
|
|
{ |
13
|
|
|
$this->table = 'cms_apicustom'; |
14
|
|
|
$this->primaryKey = "id"; |
15
|
|
|
$this->titleField = "nama"; |
16
|
|
|
$this->button_show = false; |
|
|
|
|
17
|
|
|
$this->button_new = false; |
|
|
|
|
18
|
|
|
$this->deleteBtn = false; |
19
|
|
|
$this->buttonAdd = false; |
20
|
|
|
$this->button_import = false; |
21
|
|
|
$this->buttonExport = false; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function getSecretKey() |
25
|
|
|
{ |
26
|
|
|
$this->cbLoader(); |
27
|
|
|
$data['page_title'] = 'API Generator'; |
|
|
|
|
28
|
|
|
$data['apikeys'] = DB::table('cms_apikey')->get(); |
29
|
|
|
|
30
|
|
|
return view('CbApiGen::api_key', $data); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function getGenerateSecretKey() |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
$this->cbLoader(); |
36
|
|
|
//Generate a random string. |
37
|
|
|
$token = openssl_random_pseudo_bytes(16); |
38
|
|
|
|
39
|
|
|
//Convert the binary data into hexadecimal representation. |
40
|
|
|
$token = bin2hex($token); |
41
|
|
|
|
42
|
|
|
$id = DB::table('cms_apikey')->insertGetId([ |
43
|
|
|
'secretkey' => $token, |
44
|
|
|
'created_at' => date('Y-m-d H:i:s'), |
45
|
|
|
'status' => 'active', |
46
|
|
|
'hit' => 0, |
47
|
|
|
]); |
48
|
|
|
|
49
|
|
|
$response = []; |
50
|
|
|
$response['key'] = $token; |
51
|
|
|
$response['id'] = $id; |
52
|
|
|
|
53
|
|
|
return response()->json($response); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getStatusApikey() |
57
|
|
|
{ |
58
|
|
|
CbValidator::valid(['id' => 'required', 'status' => 'required'], 'view'); |
59
|
|
|
|
60
|
|
|
$id = request('id'); |
61
|
|
|
$status = (request('status') == 1) ? "active" : "non active"; |
62
|
|
|
|
63
|
|
|
DB::table('cms_apikey')->where('id', $id)->update(['status' => $status]); |
64
|
|
|
|
65
|
|
|
backWithMsg('You have been update api key status !'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function getDeleteApiKey() |
69
|
|
|
{ |
70
|
|
|
$id = request('id'); |
71
|
|
|
if (DB::table('cms_apikey')->where('id', $id)->delete()) { |
72
|
|
|
return response()->json(['status' => 1]); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return response()->json(['status' => 0]); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
} |
79
|
|
|
|