Browse Source

finish register & email notif

pull/1/head
wahyun 11 months ago
parent
commit
b5b94e58ba
  1. 32
      app/Http/Controllers/HumanResourceController.php
  2. 2
      app/Http/Controllers/RoleController.php
  3. 4
      routes/web.php

32
app/Http/Controllers/HumanResourceController.php

@ -19,7 +19,7 @@ class HumanResourceController extends Controller
$this->validate($request, [ $this->validate($request, [
'role_id' => 'required', 'role_id' => 'required',
'name' => 'required', 'name' => 'required',
'ktp_number' => 'required|numeric|unique:m_users,ktp_number', 'ktp_number' => 'required|string|unique:m_users,ktp_number',
'employee_type' => 'required', 'employee_type' => 'required',
'company_id' => 'required' 'company_id' => 'required'
]); ]);
@ -44,7 +44,7 @@ class HumanResourceController extends Controller
$this->validate($request, [ $this->validate($request, [
'role_id' => 'required', 'role_id' => 'required',
'name' => 'required', 'name' => 'required',
'ktp_number' => 'required|numeric|unique:m_users,ktp_number', 'ktp_number' => 'required|string|unique:m_users,ktp_number',
'employee_type' => 'required', 'employee_type' => 'required',
'company_id' => 'required', 'company_id' => 'required',
'username' => 'required', 'username' => 'required',
@ -60,7 +60,7 @@ class HumanResourceController extends Controller
$result = HumanResource::create($data); $result = HumanResource::create($data);
if ($result) { 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]); return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfull created', 'code' => 200]);
} else { } else {
return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed created', 'code' => 400]); 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); $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->email !== $humanresource['email'] ? $this->validate($request,['email'=>'unique:m_users,email|email']) : '';
$request->password ? $this->validate($request,['password'=>'required|min:8']) : ''; $request->password ? $this->validate($request,['password'=>'required|min:8']) : '';
@ -230,32 +230,28 @@ class HumanResourceController extends Controller
Artisan::call('sync:integration-human-resources'); Artisan::call('sync:integration-human-resources');
} }
public function sendEmail($email, $hashPassword) public function sendEmail($email, $password)
{ {
$hashed = $hashPassword; $user = User::select('email', 'name', 'username')->where('email', $email)->first();
$user = User::select('email', 'name')->where('email', $email)->first();
if (!$user) { if (!$user) {
return response()->json(['status' => 'error', 'message' => 'e-mail not found '], 400); return response()->json(['status' => 'error', 'message' => 'e-mail not found '], 400);
} else { } else {
$this->reqHttpCurl($email, $hashed, $user->name); $this->reqHttpCurl($email, $password, $user->username, $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);
return response()->json(['status' => 'error', 'code'=>400, 'message' => 'e-mail not found '], 400); 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 = [ $postData = [
"to" => $email, "to" => $email,
"password"=> $password, "name" => $name,
"name" => $username, "username" => $username,
"password" => $password,
"from" => "app.integrasia@integrasiautama.com", "from" => "app.integrasia@integrasiautama.com",
"alias_from" => "ADW", "alias_from" => "OSPRO",
"subject" => "Informasi Akun", "subject" => "Registration OSPRO",
"body" => "informasi-akun-adw" "body" => "registration-ospro"
]; ];
$curl = curl_init(); $curl = curl_init();

2
app/Http/Controllers/RoleController.php

@ -28,7 +28,7 @@ class RoleController extends Controller
if (!$result) if (!$result)
return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500], 500); 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) public function edit($id)

4
routes/web.php

@ -6,13 +6,15 @@ $router->get('/', function () use ($router) {
$router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($router) { $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($router) {
$router->post('/login', 'AuthController@login'); $router->post('/login', 'AuthController@login');
// Landing Route
$router->post('/send-email', 'AuthController@sendEmail'); $router->post('/send-email', 'AuthController@sendEmail');
$router->post('/company-management-user/add', 'CompanyController@add'); $router->post('/company-management-user/add', 'CompanyController@add');
$router->post('/company-management-user/search', 'CompanyController@search'); $router->post('/company-management-user/search', 'CompanyController@search');
$router->post('/human-resource-user/add', 'HumanResourceController@add_user'); $router->post('/human-resource-user/add', 'HumanResourceController@add_user');
$router->get('/company-management-user/edit/{id}', 'CompanyController@edit'); $router->get('/company-management-user/edit/{id}', 'CompanyController@edit');
$router->post('/demo-management-user/add', 'DemoController@add'); $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->post('/menu/add', 'MenuController@add');
$router->get('/menu/edit/{id}', 'MenuController@edit'); $router->get('/menu/edit/{id}', 'MenuController@edit');

Loading…
Cancel
Save