From b5b94e58ba38e3b7714db83adf0264e44751bcba Mon Sep 17 00:00:00 2001 From: wahyun Date: Thu, 1 Feb 2024 11:45:26 +0700 Subject: [PATCH] finish register & email notif --- .../Controllers/HumanResourceController.php | 32 ++++++++----------- app/Http/Controllers/RoleController.php | 2 +- routes/web.php | 4 ++- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/app/Http/Controllers/HumanResourceController.php b/app/Http/Controllers/HumanResourceController.php index a10877f..2ea52d7 100644 --- a/app/Http/Controllers/HumanResourceController.php +++ b/app/Http/Controllers/HumanResourceController.php @@ -19,7 +19,7 @@ class HumanResourceController extends Controller $this->validate($request, [ 'role_id' => 'required', 'name' => 'required', - 'ktp_number' => 'required|numeric|unique:m_users,ktp_number', + 'ktp_number' => 'required|string|unique:m_users,ktp_number', 'employee_type' => 'required', 'company_id' => 'required' ]); @@ -44,7 +44,7 @@ class HumanResourceController extends Controller $this->validate($request, [ 'role_id' => 'required', 'name' => 'required', - 'ktp_number' => 'required|numeric|unique:m_users,ktp_number', + 'ktp_number' => 'required|string|unique:m_users,ktp_number', 'employee_type' => 'required', 'company_id' => 'required', 'username' => 'required', @@ -60,7 +60,7 @@ class HumanResourceController extends Controller $result = HumanResource::create($data); if ($result) { - $this->sendEmail($request->email, $data['password']); + $this->sendEmail($request->email, $request->password); return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfull created', 'code' => 200]); } else { return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed created', 'code' => 400]); @@ -91,7 +91,7 @@ class HumanResourceController extends Controller } $humanresource = HumanResource::find($id); - $request->ktp_number !== $humanresource['ktp_number'] ? $this->validate($request,['ktp_number'=>'unique:m_users,ktp_number|numeric']) : ''; + $request->ktp_number !== $humanresource['ktp_number'] ? $this->validate($request,['ktp_number'=>'unique:m_users,ktp_number|string']) : ''; $request->email !== $humanresource['email'] ? $this->validate($request,['email'=>'unique:m_users,email|email']) : ''; $request->password ? $this->validate($request,['password'=>'required|min:8']) : ''; @@ -230,32 +230,28 @@ class HumanResourceController extends Controller Artisan::call('sync:integration-human-resources'); } - public function sendEmail($email, $hashPassword) + public function sendEmail($email, $password) { - $hashed = $hashPassword; - $user = User::select('email', 'name')->where('email', $email)->first(); - + $user = User::select('email', 'name', 'username')->where('email', $email)->first(); if (!$user) { return response()->json(['status' => 'error', 'message' => 'e-mail not found '], 400); } else { - $this->reqHttpCurl($email, $hashed, $user->name); - // if (User::where('email', $email)->update(['password'=> md5($hashed)])) - // return response()->json(['status' => 'success', 'code'=>200, 'message' => 'Password already sent to mail'], 200); - + $this->reqHttpCurl($email, $password, $user->username, $user->name); return response()->json(['status' => 'error', 'code'=>400, 'message' => 'e-mail not found '], 400); } } - private function reqHttpCurl($email, $password, $username) + private function reqHttpCurl($email, $password, $username, $name) { $postData = [ "to" => $email, - "password"=> $password, - "name" => $username, + "name" => $name, + "username" => $username, + "password" => $password, "from" => "app.integrasia@integrasiautama.com", - "alias_from" => "ADW", - "subject" => "Informasi Akun", - "body" => "informasi-akun-adw" + "alias_from" => "OSPRO", + "subject" => "Registration OSPRO", + "body" => "registration-ospro" ]; $curl = curl_init(); diff --git a/app/Http/Controllers/RoleController.php b/app/Http/Controllers/RoleController.php index 9b1c8b5..371ba5c 100644 --- a/app/Http/Controllers/RoleController.php +++ b/app/Http/Controllers/RoleController.php @@ -28,7 +28,7 @@ class RoleController extends Controller if (!$result) return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500], 500); - return response()->json(['status' => 'success', 'message' => 'Data added!', 'code' => 200], 200); + return response()->json(['status' => 'success', 'data' => $result, 'message' => 'Data added!', 'code' => 200], 200); } public function edit($id) diff --git a/routes/web.php b/routes/web.php index c40d8e9..69147fb 100644 --- a/routes/web.php +++ b/routes/web.php @@ -6,13 +6,15 @@ $router->get('/', function () use ($router) { $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($router) { $router->post('/login', 'AuthController@login'); + // Landing Route $router->post('/send-email', 'AuthController@sendEmail'); - $router->post('/company-management-user/add', 'CompanyController@add'); $router->post('/company-management-user/search', 'CompanyController@search'); $router->post('/human-resource-user/add', 'HumanResourceController@add_user'); $router->get('/company-management-user/edit/{id}', 'CompanyController@edit'); $router->post('/demo-management-user/add', 'DemoController@add'); + $router->post('/role-user/add', 'RoleController@add'); + $router->post('/menu-company-user/add-multiple', 'MenuCompanyController@addMultiple'); $router->post('/menu/add', 'MenuController@add'); $router->get('/menu/edit/{id}', 'MenuController@edit');