general/check.pm untested

filter: Statementstmt 0.0% 0 / 93 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 117 CC 6 SCAR 18.8
CC
6
Cov
0%
auth_key
12.0
domain
12.0
nkti_get_authkey
6.0
CRAP 6.5
1 package NKTI::general::check;
2
3 use strict;
4 use warnings;
5 use JSON;
6 use NKTI::general::request::post;
7 use NKTI::general::dbconnect;
8 use NKTI::general::char::split;
9
10 # Items to export into callers namespace by default. Note: do not export
11 # names by default without a very good reason. Use EXPORT_OK instead.
12 # Do not simply export all your public functions/methods/constants.
13
14 # This allows declaration use NKTI::general::request::post ':all';
15 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
16 # will save memory.
17 our @EXPORT = qw(nkti_get_authkey);
18
19 # Create Module for Constructor :
20 # ------------------------------------------------------------------------
21 #
22 =head1 MODULE new()
23
24 Parameter Modul :
25 ----------------------------------------
26 _db_config => Parameter yang berisi String JSON Konfigurasi Database.
27 _query_get => Parameter yang berisi query untuk mengambil data Auth Key dari Database.
28 _domain => Parameter yang berisi nama domain.
29 Ex : "yourdomain.tld"
30 _auth_key => Parameter yang berisi auth key yang sudah didefinisikan.
31 _other_config => Parameter yang berisi hash config nama kolom table databsae untuk Auth Key dan Domain
32 ataupun data config lainnya
33
34 Format Array _other_config :
35 ----------------------------------------
36 %hash = (
37 'authkey' => 'col_name',
38 'domain' => 'col_name',
39 'other_config1' => 'value_other_config1'
40 )
41
42 =cut
43 sub new {
44
45 # Declare parameter module :
46 # ----------------------------------------------------------------
47 my $class = shift;
48 my $self = {
49 _db_config => shift,
50 _query_get => shift,
51 _domain => shift,
52 _auth_key => shift,
53 _other_config => shift,
54 };
55 bless $self, $class;
56
57 # Return result constructor :
58 # ----------------------------------------------------------------
59 return $self;
60
61 }
62 # End of Create Module for Constructor.
63 # ===========================================================================================================
64
65 # Create Module for Check Auth Key :
66 # ------------------------------------------------------------------------
67 #
68 =head1 MODULE auth_key
69
70 Parameter Modul :
71 ----------------------------------------
72 Tidak memiliki Parameter Module, aksi dilakukan berdasarkan input parameter di constructor.
73
74 =cut
75 sub auth_key {
76
77 # Define result constructor :
78 # ----------------------------------------------------------------
79 my ($self) = @_;
80
81 # Define scalar for get parameter constructor :
82 # ----------------------------------------------------------------
83 my $db_config = $self->{_db_config};
84 my $query_get = $self->{_query_get};
85 my $auth_key = $self->{_auth_key};
86 my $other_conf = $self->{_other_config};
87 my $colname_authKey = $other_conf->{'authkey'};
88
89 # Action Request for Get Database Config :
90 # ----------------------------------------------------------------
91 my $unpack_dbconf = decode_json($db_config);
92 my $prefix_db = $unpack_dbconf->{'prefix_table'};
93
94 # Action for Check Authentication Key :
95 # ----------------------------------------------------------------
96 my $db_con = NKTI::general::dbconnect->mysql($db_config);
97 my $q= $query_get;
98 my $sth = $db_con->prepare($q);
99 $sth->execute($prefix_db, $colname_authKey);
100 my $result_get = $sth->rows;
101
102 # Declare scalar for placing result :
103 # ----------------------------------------------------------------
104 my %data;
105
106 # Check IF $result_get >= 1 :
107 # ----------------------------------------------------------------
108 if ($result_get >= 1) {
109
110 # While loop to get data :
111 # ----------------------------------------------------------------
112 while (my @r_data = $sth->fetchrow_array()) {
113
114 # Declare scalar for get result data :
115 # ----------------------------------------------------------------
116 my ($id_pengaturan, $item_pengaturan, $value_pengaturan) = @r_data;
117
118 # Decode Auth Key :
119 # ----------------------------------------------------------------
120 my $docode_auth_key = NKTI::general::char::split->based_char($auth_key, "-", 1);
121
122 # Check IF $value_pengaturan eq $docode_auth_key :
123 # ----------------------------------------------------------------
124 if ($value_pengaturan eq $docode_auth_key) {
125
126 # Placing result into hash %data :
127 # ----------------------------------------------------------------
128 $data{'result'} = {
129 'sukses' => 1,
130 'code' => 'success',
131 'data' => $value_pengaturan
132 };
133 }
134 # End of check IF $value_pengaturan eq $docode_auth_key.
135 # ----------------------------------------------------------------
136
137 # Check IF $value_pengaturan eq $docode_auth_key :
138 # ----------------------------------------------------------------
139 else {
140
141 # Placing result into hash %data :
142 # ----------------------------------------------------------------
143 $data{'result'} = {
144 'sukses' => 0,
145 'code' => 'no-eq'
146 };
147 }
148 # End of check IF $value_pengaturan eq $docode_auth_key.
149 # ----------------------------------------------------------------
150 }
151 # End of while to get data.
152 # ================================================================
153 }
154 # End of check IF $result_get >= 1.
155 # ----------------------------------------------------------------
156
157 # Check IF $result_get == 0 :
158 # ----------------------------------------------------------------
159 else {
160
161 # Placing error result into hash %data :
162 # ----------------------------------------------------------------
163 $data{'result'} = {
164 'sukses' => 0,
165 'code' => 'not-found'
166 };
167
168 }
169 # End of check IF $result_get == 0.
170 # ----------------------------------------------------------------
171
172 # Return Result :
173 # ----------------------------------------------------------------
174 return \%data;
175
176 }
177 # End of Create Module for Check Auth Key.
178 # ===========================================================================================================
179
180 # Create Module for Check Domain :
181 # ------------------------------------------------------------------------
182 #
183 =head1 MODULE domain()
184
185 Parameter Modul :
186 ----------------------------------------
187 Tidak memiliki Parameter Module, aksi dilakukan berdasarkan input parameter di constructor.
188
189 =cut
190 sub domain {
191
192 # Declare Parameter Module :
193 # ----------------------------------------------------------------
194 my ($self) = @_;
195
196 # Define scalar for get parameter constructor :
197 # ----------------------------------------------------------------
198 my $db_config = $self->{_db_config};
199 my $query_get = $self->{_query_get};
200 my $domain = $self->{_domain};
201 my $other_conf = $self->{_other_config};
202 my $colname_domain = $other_conf->{'domain'};
203
204 # Action Request for Get Database Config :
205 # ----------------------------------------------------------------
206 my $unpack_dbconf = decode_json($db_config);
207 my $prefix_db = $unpack_dbconf->{'prefix_table'};
208
209 # Action for Check Domain :
210 # ----------------------------------------------------------------
211 my $db_con = NKTI::general::dbconnect->mysql($db_config);
212 my $q = $query_get;
213 my $sth = $db_con->prepare($q);
214 $sth->execute($prefix_db, $colname_domain);
215 my $result_get = $sth->rows;
216
217 # Declare scalar for placing result :
218 # ----------------------------------------------------------------
219 my %data = ();
220
221 # Check IF $result_get >= 1 :
222 # ----------------------------------------------------------------
223 if ($result_get >= 1) {
224
225 # Define scalar will be uesd in this condition :
226 # ----------------------------------------------------------------
227 my $r_data = $sth->fetchrow_hashref();
228
229 # Declare scalar for define result database :
230 # ----------------------------------------------------------------
231 my $result_item = $r_data->{'value_pengaturan'};
232
233 # Check IF $result_item == $domain :
234 # ----------------------------------------------------------------
235 if ($result_item eq $domain) {
236
237 # Placing success result into hashref %data :
238 # ----------------------------------------------------------------
239 $data{'result'} = {
240 'sukses' => 1,
241 'code' => 'success',
242 'data' => $result_item
243 }
244 }
245 # End of check IF $result_item == $domain.
246 # ----------------------------------------------------------------
247
248 # Check IF $result_item == $domain :
249 # ----------------------------------------------------------------
250 else {
251
252 # Placing Error Result into hashref %data :
253 # ----------------------------------------------------------------
254 $data{'result'} = {
255 'sukses' => 0,
256 'code' => 'no-eq'
257 }
258
259 }
260 # End of check IF $result_item == $domain.
261 # ----------------------------------------------------------------
262 }
263 # End of check IF $result_get >= 1.
264 # ----------------------------------------------------------------
265
266 # Check IF $result_get == 0 :
267 # ----------------------------------------------------------------
268 else {
269
270 # Placing Error Result into hashref %data :
271 # ----------------------------------------------------------------
272 $data{'result'} = {
273 'sukses' => 0,
274 'code' => 'no-found'
275 }
276
277 }
278 # End of check IF $result_get == 0.
279 # ----------------------------------------------------------------
280
281 # Return result :
282 # ----------------------------------------------------------------
283 return \%data;
284 }
285 # End of Create Module for Check Domain.
286 # ===========================================================================================================
287
288 # Create Module for Get Auth Key : :
289 # ------------------------------------------------------------------------
290 #
291 =head1 MODULE get_authkey()
292
293 Parameter Modul :
294 ----------------------------------------
295 $db_config => Parameter yang berisi string JSON Database Config.
296 $result_check => Parameter yang berisi hashref Hasil pengecekan Auth Key dan Domain.
297 $item_db => Parameter yang berisi Nama item ditable database.
298 $query_db => Parameter yang berisi Query Database.
299
300 =cut
301 sub nkti_get_authkey {
302
303 # Declare parameter module :
304 # ----------------------------------------------------------------
305 my ($db_config, $result_check, $item_db, $query_db) = @_;
306
307 # Declare scalar for parameter module :
308 # ----------------------------------------------------------------
309 my $get_dbconf = decode_json($db_config);
310 my $prefix_db = $get_dbconf->{'prefix_table'};
311
312 # Declare scalar for Placing result :
313 # ----------------------------------------------------------------
314 my %data = ();
315
316 # Query for get auth key :
317 # ----------------------------------------------------------------
318 my $dbcon = NKTI::general::dbconnect->mysql($db_config);
319 my $q = $query_db;
320 my $sth = $dbcon->prepare($q);
321 $sth->execute($prefix_db, $item_db);
322 my $result_get = $sth->rows;
323
324 # Check IF $result_get >= 1 :
325 # ----------------------------------------------------------------
326 if ($result_get >= 1) {
327
328 # Declare scalar for placing result Database :
329 # ----------------------------------------------------------------
330 my $r_data = $sth-> $sth->fetchrow_hashref();
331 my $auth_key = $r_data->{'value_pengaturan'};
332
333 # Placing data into hashref %data :
334 # ----------------------------------------------------------------
335 $data{'result'} = {
336 'sukses' => 1,
337 'code' => 'success',
338 'data' => $auth_key
339 };
340 }
341 # End of check IF $result_get >= 1.
342 # ----------------------------------------------------------------
343
344 # Check IF $result_get == 0 :
345 # ----------------------------------------------------------------
346 else {
347
348 # Placing Error result into hashref %data :
349 # ----------------------------------------------------------------
350 $data{'result'} = {
351 'sukses' => 0,
352 'code' => 'not-found'
353 };
354 }
355 # End of check IF $result_get == 0.
356 # ----------------------------------------------------------------
357
358 # Return Result :
359 # ----------------------------------------------------------------
360 return \%data;
361 }
362 # End of Create Module for Get Auth Key :.
363 # ===========================================================================================================
364 1;
365
366 __END__