Browse Source

Merge pull request 'register endpoint' (#43) from dev-wahyun into staging

Reviewed-on: ibnu/generic-ospro-backend#43
pull/1/head
farhantock 11 months ago
parent
commit
eaf18e9e57
  1. 30
      app/Http/Controllers/HumanResourceController.php
  2. 2
      app/Http/Controllers/RoleController.php
  3. 4
      routes/web.php

30
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,
"name" => $name,
"username" => $username,
"password" => $password,
"name" => $username,
"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();

2
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)

4
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');

Loading…
Cancel
Save