@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | |
7 | 7 | class AppLicenseServerServiceProvider extends ServiceProvider |
8 | 8 | { |
9 | - protected $namespace='AppLicenseServer\Controllers'; |
|
9 | + protected $namespace = 'AppLicenseServer\Controllers'; |
|
10 | 10 | /** |
11 | 11 | * Register services. |
12 | 12 | * |
@@ -24,9 +24,9 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function boot() |
26 | 26 | { |
27 | - \Route::middleware('api')->any(config('irfa.app_license_server.license_route'),'Irfa\AppLicenseServer\Controller\AppLicenseController@check')->name(config('irfa.app_license_server.route_name')); |
|
27 | + \Route::middleware('api')->any(config('irfa.app_license_server.license_route'), 'Irfa\AppLicenseServer\Controller\AppLicenseController@check')->name(config('irfa.app_license_server.route_name')); |
|
28 | 28 | $this->publishes([ |
29 | - __DIR__.'/../config/irfa/' => config_path('irfa')],'app-license-server'); |
|
29 | + __DIR__.'/../config/irfa/' => config_path('irfa')], 'app-license-server'); |
|
30 | 30 | $this->publishes([ |
31 | 31 | __DIR__.'/../migrations/' => database_path('migrations'), |
32 | 32 | ], 'app-license-server'); |
@@ -11,18 +11,18 @@ |
||
11 | 11 | { |
12 | 12 | public function check(Request $request,License $license,Json $json) |
13 | 13 | { |
14 | - if(empty($request->serial)) |
|
15 | - { |
|
16 | - $data['active'] = false; |
|
17 | - $data['message'] = "Serial number must be provided."; |
|
18 | - return $json->response(400,'data',$data,[]); |
|
19 | - } |
|
20 | - $res = $license->serial($request->serial)->check(); |
|
14 | + if(empty($request->serial)) |
|
15 | + { |
|
16 | + $data['active'] = false; |
|
17 | + $data['message'] = "Serial number must be provided."; |
|
18 | + return $json->response(400,'data',$data,[]); |
|
19 | + } |
|
20 | + $res = $license->serial($request->serial)->check(); |
|
21 | 21 | if($res->active) |
22 | 22 | { |
23 | - return $json->response(200,'data',$res,[]); |
|
23 | + return $json->response(200,'data',$res,[]); |
|
24 | 24 | } |
25 | - return $json->response(400,'data',$res,[$res->message]); |
|
25 | + return $json->response(400,'data',$res,[$res->message]); |
|
26 | 26 | |
27 | 27 | } |
28 | 28 | } |
@@ -9,20 +9,20 @@ |
||
9 | 9 | |
10 | 10 | class AppLicenseController extends Controller |
11 | 11 | { |
12 | - public function check(Request $request,License $license,Json $json) |
|
12 | + public function check(Request $request, License $license, Json $json) |
|
13 | 13 | { |
14 | - if(empty($request->serial)) |
|
14 | + if (empty($request->serial)) |
|
15 | 15 | { |
16 | 16 | $data['active'] = false; |
17 | 17 | $data['message'] = "Serial number must be provided."; |
18 | - return $json->response(400,'data',$data,[]); |
|
18 | + return $json->response(400, 'data', $data, []); |
|
19 | 19 | } |
20 | 20 | $res = $license->serial($request->serial)->check(); |
21 | - if($res->active) |
|
21 | + if ($res->active) |
|
22 | 22 | { |
23 | - return $json->response(200,'data',$res,[]); |
|
23 | + return $json->response(200, 'data', $res, []); |
|
24 | 24 | } |
25 | - return $json->response(400,'data',$res,[$res->message]); |
|
25 | + return $json->response(400, 'data', $res, [$res->message]); |
|
26 | 26 | |
27 | 27 | } |
28 | 28 | } |
@@ -6,7 +6,7 @@ |
||
6 | 6 | |
7 | 7 | class Json |
8 | 8 | { |
9 | - public function response($status, $key_data = 'data', $data=null, $errors=null) |
|
9 | + public function response($status, $key_data = 'data', $data=null, $errors=null) |
|
10 | 10 | { |
11 | 11 | return response()->json([ |
12 | 12 | 'status' => $status, |
@@ -6,12 +6,12 @@ |
||
6 | 6 | |
7 | 7 | class Json |
8 | 8 | { |
9 | - public function response($status, $key_data = 'data', $data=null, $errors=null) |
|
9 | + public function response($status, $key_data = 'data', $data = null, $errors = null) |
|
10 | 10 | { |
11 | 11 | return response()->json([ |
12 | 12 | 'status' => $status, |
13 | 13 | $key_data => $data, |
14 | 14 | 'errors' => $errors |
15 | - ],$status); |
|
15 | + ], $status); |
|
16 | 16 | } |
17 | 17 | } |
@@ -8,26 +8,26 @@ |
||
8 | 8 | |
9 | 9 | class SerialGenerator extends SerialType |
10 | 10 | { |
11 | - protected function generateSerial() |
|
11 | + protected function generateSerial() |
|
12 | 12 | { |
13 | - if(config('irfa.app_license_server.char_type') == "alphanumeric") { |
|
13 | + if(config('irfa.app_license_server.char_type') == "alphanumeric") { |
|
14 | 14 | |
15 | - return $this->alphanumeric(); |
|
15 | + return $this->alphanumeric(); |
|
16 | 16 | |
17 | - } elseif(config('irfa.app_license_server.char_type') == "numeric") { |
|
17 | + } elseif(config('irfa.app_license_server.char_type') == "numeric") { |
|
18 | 18 | |
19 | - return $this->numeric(); |
|
19 | + return $this->numeric(); |
|
20 | 20 | |
21 | - } |
|
22 | - elseif(config('irfa.app_license_server.char_type') == "alphabet") { |
|
21 | + } |
|
22 | + elseif(config('irfa.app_license_server.char_type') == "alphabet") { |
|
23 | 23 | |
24 | - return $this->alphabet(); |
|
24 | + return $this->alphabet(); |
|
25 | 25 | |
26 | - } else { |
|
27 | - throw new \Exception('\''.config('irfa.app_license_server.char_type').'\' is not supported, supported char type : alphanumeric, numeric, or alphabet'); |
|
26 | + } else { |
|
27 | + throw new \Exception('\''.config('irfa.app_license_server.char_type').'\' is not supported, supported char type : alphanumeric, numeric, or alphabet'); |
|
28 | 28 | |
29 | - return false; |
|
30 | - } |
|
29 | + return false; |
|
30 | + } |
|
31 | 31 | |
32 | 32 | } |
33 | 33 |
@@ -10,16 +10,16 @@ |
||
10 | 10 | { |
11 | 11 | protected function generateSerial() |
12 | 12 | { |
13 | - if(config('irfa.app_license_server.char_type') == "alphanumeric") { |
|
13 | + if (config('irfa.app_license_server.char_type') == "alphanumeric") { |
|
14 | 14 | |
15 | 15 | return $this->alphanumeric(); |
16 | 16 | |
17 | - } elseif(config('irfa.app_license_server.char_type') == "numeric") { |
|
17 | + } elseif (config('irfa.app_license_server.char_type') == "numeric") { |
|
18 | 18 | |
19 | 19 | return $this->numeric(); |
20 | 20 | |
21 | 21 | } |
22 | - elseif(config('irfa.app_license_server.char_type') == "alphabet") { |
|
22 | + elseif (config('irfa.app_license_server.char_type') == "alphabet") { |
|
23 | 23 | |
24 | 24 | return $this->alphabet(); |
25 | 25 |
@@ -18,8 +18,7 @@ |
||
18 | 18 | |
19 | 19 | return $this->numeric(); |
20 | 20 | |
21 | - } |
|
22 | - elseif(config('irfa.app_license_server.char_type') == "alphabet") { |
|
21 | + } elseif(config('irfa.app_license_server.char_type') == "alphabet") { |
|
23 | 22 | |
24 | 23 | return $this->alphabet(); |
25 | 24 |
@@ -20,9 +20,9 @@ |
||
20 | 20 | |
21 | 21 | return $sn; |
22 | 22 | } |
23 | - protected function alphanumeric() |
|
23 | + protected function alphanumeric() |
|
24 | 24 | { |
25 | - return $this->sn()->setConfig([ |
|
25 | + return $this->sn()->setConfig([ |
|
26 | 26 | 'length' => config('irfa.app_license_server.length'), |
27 | 27 | 'segment' => config('irfa.app_license_server.segment'), |
28 | 28 | 'seperator' => $this->seperator, |
@@ -89,12 +89,12 @@ discard block |
||
89 | 89 | |
90 | 90 | protected function disableSN($sn) |
91 | 91 | { |
92 | - return LicenseSerial::where('serial',$sn)->update(['status'=>1]); |
|
92 | + return LicenseSerial::where('serial',$sn)->update(['status'=>1]); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | protected function enableSN($sn) |
96 | 96 | { |
97 | - return LicenseSerial::where('serial',$sn)->update(['status'=>0]); |
|
97 | + return LicenseSerial::where('serial',$sn)->update(['status'=>0]); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | protected function renewSN($sn,$days) |
@@ -112,6 +112,6 @@ discard block |
||
112 | 112 | |
113 | 113 | } |
114 | 114 | $return['message'] = "Renew serial number Failed because serial number not exists."; |
115 | - return $return; |
|
115 | + return $return; |
|
116 | 116 | } |
117 | 117 | } |
@@ -21,12 +21,12 @@ discard block |
||
21 | 21 | |
22 | 22 | protected function expired($sn) |
23 | 23 | { |
24 | - $exp = LicenseSerial::where('serial',$sn)->first(); |
|
25 | - if(empty($exp)) |
|
24 | + $exp = LicenseSerial::where('serial', $sn)->first(); |
|
25 | + if (empty($exp)) |
|
26 | 26 | { |
27 | 27 | return true; |
28 | - } else{ |
|
29 | - if($exp->expired > strtotime(date('Y-m-d'))) |
|
28 | + } else { |
|
29 | + if ($exp->expired > strtotime(date('Y-m-d'))) |
|
30 | 30 | { |
31 | 31 | return false; |
32 | 32 | } |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | |
38 | 38 | protected function disabled($sn) |
39 | 39 | { |
40 | - $disabled = LicenseSerial::where('serial',$sn)->first(); |
|
41 | - if($disabled->status==1) |
|
40 | + $disabled = LicenseSerial::where('serial', $sn)->first(); |
|
41 | + if ($disabled->status == 1) |
|
42 | 42 | { |
43 | 43 | return true; |
44 | 44 | } |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | |
49 | 49 | protected function exists($sn) |
50 | 50 | { |
51 | - $exp = LicenseSerial::where('serial',$sn)->count(); |
|
52 | - if(empty($exp)) |
|
51 | + $exp = LicenseSerial::where('serial', $sn)->count(); |
|
52 | + if (empty($exp)) |
|
53 | 53 | { |
54 | 54 | return false; |
55 | 55 | } |
@@ -58,25 +58,25 @@ discard block |
||
58 | 58 | |
59 | 59 | protected function createLicense($params, $expired) |
60 | 60 | { |
61 | - $sn = $this->generateSerial(); |
|
61 | + $sn = $this->generateSerial(); |
|
62 | 62 | $expired = strtotime($expired); |
63 | - if($this->checkAvaibility($sn)) |
|
63 | + if ($this->checkAvaibility($sn)) |
|
64 | 64 | { |
65 | 65 | $this->name = $params['name']; |
66 | 66 | $this->domain = $params['domain']; |
67 | 67 | $this->phone_number = $params['phone_number']; |
68 | 68 | $this->address = $params['address']; |
69 | - $this->serial =$sn; |
|
69 | + $this->serial = $sn; |
|
70 | 70 | $this->expired = $expired; |
71 | 71 | |
72 | 72 | return $this->insertToTable(); |
73 | - } else{ |
|
73 | + } else { |
|
74 | 74 | return $this->createLicense($params); |
75 | 75 | } |
76 | 76 | } |
77 | 77 | private function checkAvaibility($sn) |
78 | 78 | { |
79 | - if(LicenseSerial::where('serial',$sn)->count() == 0) |
|
79 | + if (LicenseSerial::where('serial', $sn)->count() == 0) |
|
80 | 80 | { |
81 | 81 | return true; |
82 | 82 | } |
@@ -84,30 +84,30 @@ discard block |
||
84 | 84 | } |
85 | 85 | private function insertToTable() |
86 | 86 | { |
87 | - return LicenseSerial::create(['name'=>$this->name,'domain'=>$this->domain,'phone_number'=>$this->phone_number,'address'=>$this->address,'serial'=>$this->serial,'expired'=>$this->expired]); |
|
87 | + return LicenseSerial::create(['name'=>$this->name, 'domain'=>$this->domain, 'phone_number'=>$this->phone_number, 'address'=>$this->address, 'serial'=>$this->serial, 'expired'=>$this->expired]); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | protected function disableSN($sn) |
91 | 91 | { |
92 | - return LicenseSerial::where('serial',$sn)->update(['status'=>1]); |
|
92 | + return LicenseSerial::where('serial', $sn)->update(['status'=>1]); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | protected function enableSN($sn) |
96 | 96 | { |
97 | - return LicenseSerial::where('serial',$sn)->update(['status'=>0]); |
|
97 | + return LicenseSerial::where('serial', $sn)->update(['status'=>0]); |
|
98 | 98 | } |
99 | 99 | |
100 | - protected function renewSN($sn,$days) |
|
100 | + protected function renewSN($sn, $days) |
|
101 | 101 | { |
102 | - if($this->exists($sn)) |
|
102 | + if ($this->exists($sn)) |
|
103 | 103 | { |
104 | 104 | $days = strtotime($days); |
105 | - $sn = LicenseSerial::where('serial',$sn); |
|
105 | + $sn = LicenseSerial::where('serial', $sn); |
|
106 | 106 | $sn->update(['expired' => $days]); |
107 | 107 | |
108 | 108 | $return = $sn->first(); |
109 | 109 | $return['message'] = "Renew serial number succesfully"; |
110 | - $return['expired'] = date("Y-m-d, H:m:s",$days); |
|
110 | + $return['expired'] = date("Y-m-d, H:m:s", $days); |
|
111 | 111 | return $return; |
112 | 112 | |
113 | 113 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | |
23 | 23 | public function disable() |
24 | 24 | { |
25 | - return $this->disableSN($this->serial); |
|
25 | + return $this->disableSN($this->serial); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | public function enable() |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | return (object)['active' => false,'message' => "Serial Number is Disabled"]; |
50 | 50 | } |
51 | 51 | |
52 | - return (object)['active' => true,'message' => "Serial Number is valid"]; |
|
52 | + return (object)['active' => true,'message' => "Serial Number is valid"]; |
|
53 | 53 | } else{ |
54 | 54 | return (object)['active' => false,'message' => "Serial Number invalid"]; |
55 | 55 | } |
@@ -9,9 +9,9 @@ discard block |
||
9 | 9 | class License extends SerialManager |
10 | 10 | { |
11 | 11 | private $serial; |
12 | - public function register($params,$expired) |
|
12 | + public function register($params, $expired) |
|
13 | 13 | { |
14 | - return $this->createLicense($params,$expired); |
|
14 | + return $this->createLicense($params, $expired); |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | public function serial($serial) |
@@ -32,26 +32,26 @@ discard block |
||
32 | 32 | |
33 | 33 | public function renew($date) |
34 | 34 | { |
35 | - return $this->renewSN($this->serial,$date); |
|
35 | + return $this->renewSN($this->serial, $date); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | public function check() |
39 | 39 | { |
40 | - if($this->exists($this->serial)) |
|
40 | + if ($this->exists($this->serial)) |
|
41 | 41 | { |
42 | - if($this->expired($this->serial)) |
|
42 | + if ($this->expired($this->serial)) |
|
43 | 43 | { |
44 | - return (object)['active' => false,'message' => "Serial Number is Expired"]; |
|
44 | + return (object)['active' => false, 'message' => "Serial Number is Expired"]; |
|
45 | 45 | } |
46 | 46 | |
47 | - if($this->disabled($this->serial)) |
|
47 | + if ($this->disabled($this->serial)) |
|
48 | 48 | { |
49 | - return (object)['active' => false,'message' => "Serial Number is Disabled"]; |
|
49 | + return (object)['active' => false, 'message' => "Serial Number is Disabled"]; |
|
50 | 50 | } |
51 | 51 | |
52 | - return (object)['active' => true,'message' => "Serial Number is valid"]; |
|
53 | - } else{ |
|
54 | - return (object)['active' => false,'message' => "Serial Number invalid"]; |
|
52 | + return (object)['active' => true, 'message' => "Serial Number is valid"]; |
|
53 | + } else { |
|
54 | + return (object)['active' => false, 'message' => "Serial Number invalid"]; |
|
55 | 55 | } |
56 | 56 | } |
57 | 57 | } |
@@ -6,6 +6,6 @@ |
||
6 | 6 | |
7 | 7 | class LicenseSerial extends Model |
8 | 8 | { |
9 | - protected $table = 'license_serials'; |
|
9 | + protected $table = 'license_serials'; |
|
10 | 10 | protected $fillable = ['name','domain','phone_number','address','serial','expired','status']; |
11 | 11 | } |
@@ -7,5 +7,5 @@ |
||
7 | 7 | class LicenseSerial extends Model |
8 | 8 | { |
9 | 9 | protected $table = 'license_serials'; |
10 | - protected $fillable = ['name','domain','phone_number','address','serial','expired','status']; |
|
10 | + protected $fillable = ['name', 'domain', 'phone_number', 'address', 'serial', 'expired', 'status']; |
|
11 | 11 | } |
@@ -10,4 +10,4 @@ |
||
10 | 10 | | contains the "web" middleware group. Now create something great! |
11 | 11 | | |
12 | 12 | */ |
13 | -Route::any('/check','Controller\AppLicenseController@check'); |
|
14 | 13 | \ No newline at end of file |
14 | +Route::any('/check', 'Controller\AppLicenseController@check'); |
|
15 | 15 | \ No newline at end of file |