ranjith-dev #268

Merged
jothi merged 14 commits from ranjith-dev into master 2026-01-28 11:38:46 +00:00
Showing only changes of commit d33b1c7ccb - Show all commits

View File

@@ -4,7 +4,7 @@ namespace App\Http\Controllers;
use App\Models\Plant;
use App\Models\User;
//use Carbon\Carbon;
// use Carbon\Carbon;
use Hash;
use Illuminate\Http\Request;
@@ -29,72 +29,65 @@ class UserController extends Controller
/**
* Display the specified resource.
*/
//show(string $id)
// show(string $id)
public function get_testing_data(Request $request)
{
$expectedUser = env('API_AUTH_USER');
$expectedPw = env('API_AUTH_PW');
$header_auth = $request->header('Authorization');
$header_user = $request->header('User-Name');
$header_pass = $request->header('User-Pass');
$expectedToken = $expectedUser . ':' . $expectedPw;
$expectedPw = env('API_AUTH_PW');
$header_auth = $request->header('Authorization');
$header_user = $request->header('User-Name');
$header_pass = $request->header('User-Pass');
$expectedToken = $expectedUser.':'.$expectedPw;
if ("Bearer " . $expectedToken != $header_auth)
{
if ('Bearer '.$expectedToken != $header_auth) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => 'Invalid authorization token!'
'status_description' => 'Invalid authorization token!',
], 403);
}
if (!$header_user)
{
if (! $header_user) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => 'Invalid user name found!'
'status_description' => 'Invalid user name found!',
], 400);
}
else if (!$header_pass)
{
} elseif (! $header_pass) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => 'Invalid password found!'
'status_description' => 'Invalid password found!',
], 400);
}
$existUser = User::where('name', $header_user)->first();
$existPlant = "All Plants";
$existPlant = 'All Plants';
if (!$existUser)
{
if (! $existUser) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => 'Unknown user name found!'
'status_description' => 'Unknown user name found!',
], 400);
}
else {
} else {
$codeExist = Plant::where('id', $existUser->plant_id)->first();
if ($codeExist) {
$existPlant = $codeExist->code;
}
}
// Retrieve the user by email
//$user = User::where('email', $email)->first();
// $user = User::where('email', $email)->first();
if (Hash::check($header_pass, $existUser->password)) {
return response()->json([
'created_at' => $existUser->created_at->format('Y-m-d H:i:s') ?? "",
'updated_at' => $existUser->updated_at->format('Y-m-d H:i:s') ?? "",
'requested_at' => now()->format('Y-m-d H:i:s') ?? "", //Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s') ?? "",
'plant' => (String)$existPlant ?? "",
'email' => $existUser->email ?? "",
'roles' => $existUser->roles()->pluck('name')->toArray()
'created_at' => $existUser->created_at->format('Y-m-d H:i:s') ?? '',
'updated_at' => $existUser->updated_at->format('Y-m-d H:i:s') ?? '',
'requested_at' => now()->format('Y-m-d H:i:s') ?? '', // Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s') ?? "",
'plant' => (string) $existPlant ?? '',
'email' => $existUser->email ?? '',
'roles' => $existUser->roles()->pluck('name')->toArray(),
], 200);
} else {
return response()->json([
'status_code' => 'ERROR',
'status_description' => 'Password does not match!'
'status_description' => 'Password does not match!',
], 400);
}