From 3e5692847b0c3423e9e11eedf36698554668e3da Mon Sep 17 00:00:00 2001 From: farhantock Date: Tue, 30 Jan 2024 14:54:18 +0700 Subject: [PATCH 1/3] Demo End Point --- app/Http/Controllers/DemoController.php | 114 ++++++++++++++++++++++++ app/Models/Demo.php | 27 ++++++ routes/web.php | 11 ++- 3 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 app/Http/Controllers/DemoController.php create mode 100644 app/Models/Demo.php diff --git a/app/Http/Controllers/DemoController.php b/app/Http/Controllers/DemoController.php new file mode 100644 index 0000000..715f379 --- /dev/null +++ b/app/Http/Controllers/DemoController.php @@ -0,0 +1,114 @@ +validate($request, [ + 'name' => 'required', + 'role' => 'required', + 'number_phone' => 'required', + 'message' => 'required', + ]); + + $data = $request->all(); + + $data['created_by'] = '@System'; + $data['status'] = 'New Request'; + + $result = Demo::create($data); + + if ($result) { + return response()->json(['status' => 'success', 'data' => $result, 'message' => 'Request Demo successfully!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'Request Demo failed!', 'code' => 400], 400); + } + } + + public function edit($id) + { + if (!$id || (int) $id < 0 || $id == "") { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + die(); + } + + $result = Demo::find($id); + + if ($result) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get data Demo, please try again later!', 'code' => 400], 400); + } + } + + public function update(Request $request, $id) + { + if (!$id || (int) $id < 0 || $id == "") { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + + $data = Demo::find($id); + + + if ($data) { + $result = $data->update($request->all()); + } else { + return response()->json(['status' => 'failed', 'message' => 'data Demo not found!', 'code' => 400], 400); + die(); + } + + + if ($result) { + return response()->json(['status' => 'success', 'message' => 'data Demo successfully updated!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data Demo failed updated!', 'code' => 400], 400); + } + } + + public function delete($id) + { + $data = Demo::find($id); + + if ($data) { + $delete = $data->delete(); + } else { + return response()->json(['status' => 'failed', 'message' => 'data Demo not found!', 'code' => 400], 400); + die(); + } + + + if ($delete) { + return response()->json(['status' => 'success', 'message' => 'data Demo successfully deleted!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data Demo failed deleted!', 'code' => 400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_company'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); + } + + public function list() + { + $data = Demo::all(); + $countData = $data->count(); + + if ($data) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get list Demo, please try again later!', 'code' => 400], 400); + } + } +} diff --git a/app/Models/Demo.php b/app/Models/Demo.php new file mode 100644 index 0000000..ded3b3a --- /dev/null +++ b/app/Models/Demo.php @@ -0,0 +1,27 @@ +group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro $router->post('/image/search', 'ImageController@search'); $router->delete('/image/delete/{id}', 'ImageController@delete'); $router->delete('/image/delete/{id}/{category}', 'ImageController@deleteByRef'); - $router->delete('/image/multiple-delete/{id}/{category}', 'ImageController@deleteByRefMultiple'); + $router->delete('/image/multiple-delete/{id}/{category}', 'ImageController@deleteByRefMultiple'); $router->post('/image/upload', 'ImageController@uploadImage'); - $router->post('/image/multiple-upload', 'ImageController@uploadMultipleImage'); + $router->post('/image/multiple-upload', 'ImageController@uploadMultipleImage'); $router->get('/image/{id}/{category}', 'ImageController@getByRefId'); $router->post('/panic-button/add', 'PanicButtonController@add'); @@ -550,5 +550,12 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro $router->post('/menu-company/search', 'MenuCompanyController@search'); $router->get('/menu-company/management/{id}', 'MenuCompanyController@listMenu'); $router->get('/menu-company/list', 'MenuCompanyController@list'); + + $router->post('/demo-management/add', 'DemoController@add'); + $router->get('/demo-management/edit/{id}', 'DemoController@edit'); + $router->put('/demo-management/update/{id}', 'DemoController@update'); + $router->post('/demo-management/search', 'DemoController@search'); + $router->delete('/demo-management/delete/{id}', 'DemoController@delete'); + $router->get('/demo-management/list', 'DemoController@list'); }); }); From 1e1388f46d0cb15402e4e141f3b95af09a60534e Mon Sep 17 00:00:00 2001 From: farhantock Date: Tue, 30 Jan 2024 15:03:58 +0700 Subject: [PATCH 2/3] update demo controller --- app/Http/Controllers/DemoController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/DemoController.php b/app/Http/Controllers/DemoController.php index 715f379..a0bda60 100644 --- a/app/Http/Controllers/DemoController.php +++ b/app/Http/Controllers/DemoController.php @@ -5,7 +5,7 @@ namespace App\Http\Controllers; use App\Models\Demo; use Illuminate\Http\Request; -class CompanyController extends Controller +class DemoController extends Controller { public function add(Request $request) { @@ -92,7 +92,7 @@ class CompanyController extends Controller public function search(Request $request) { $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 'm_company'); + $dataBuilder = $this->setUpPayload($payload, 'm_demo'); $builder = $dataBuilder['builder']; $countBuilder = $dataBuilder['count']; $dataGet = $builder->get(); From b005fbbcae9ff3351121215af661dbb3f2456ac9 Mon Sep 17 00:00:00 2001 From: farhantock Date: Tue, 30 Jan 2024 17:45:16 +0700 Subject: [PATCH 3/3] send email register --- app/Http/Controllers/AuthController.php | 65 ++++++++++++++++++++++++- routes/web.php | 1 + 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index 1f26ba3..e88d853 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -13,7 +13,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\Password; use Illuminate\Validation\ValidationException; - +const URL_EMAIL = 'https://notifapp.odm-iu.com/service-mail/notif_mail.php'; class AuthController extends Controller { public function __construct() @@ -108,4 +108,67 @@ class AuthController extends Controller return response()->json(['code' => 201, 'message' => "username doesn't match"], 201); } } + + + public function sendEmail(Request $request) + { + $hashed = Str::random(15); + $email = $request->email; + $user = User::select('email', 'name')->where('email', $email)->first(); + + if (!$user) { + return response()->json(['status' => 'error', 'message' => 'e-mail not found '], 400); + } else { + $this->reqHttpCurl($email, $hashed, $user->username, $user->name); + // $updateUser = User::where('email', $email)->update(['password'=> $hashed]); + if (User::where('email', $email)->update(['password' => md5($hashed)])) + return response()->json(['status' => 'success', 'code' => 200, 'message' => 'Password already sent to mail'], 200); + + return response()->json(['status' => 'error', 'code' => 400, 'message' => 'e-mail not found '], 400); + } + } + + private function reqHttpCurl($email, $password, $username, $name) + { + $postData = [ + "to" => $email, + "username" => $name, + "username" => $username, + "password" => $password, + "from" => "app.integrasia@integrasiautama.com", + "alias_from" => "OSPRO", + "subject" => "Registration OSPRO", + "body" => "registration-ospro" + ]; + + $curl = curl_init(); + + curl_setopt_array($curl, array( + CURLOPT_URL => URL_EMAIL, // your preferred url + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30000, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => "POST", + CURLOPT_POSTFIELDS => json_encode($postData), + CURLOPT_HTTPHEADER => array( + // Set here requred headers + "accept: */*", + "accept-language: en-US,en;q=0.8", + "content-type: application/json", + ), + )); + + $response = curl_exec($curl); + $err = curl_error($curl); + + curl_close($curl); + + if ($err) { + echo "cURL Error #:" . $err; + } else { + print_r(json_decode($response)); + } + } } diff --git a/routes/web.php b/routes/web.php index cd1d199..3c8bdb6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -6,6 +6,7 @@ $router->get('/', function () use ($router) { $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($router) { $router->post('/login', 'AuthController@login'); + $router->post('/send-email', 'AuthController@sendEmail'); $router->post('/menu/add', 'MenuController@add'); $router->get('/menu/edit/{id}', 'MenuController@edit');