Updated alignment for controller
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
This commit is contained in:
@@ -4,7 +4,7 @@ namespace App\Http\Controllers;
|
|||||||
|
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
//use Carbon\Carbon;
|
// use Carbon\Carbon;
|
||||||
use Hash;
|
use Hash;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
@@ -29,72 +29,65 @@ class UserController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Display the specified resource.
|
* Display the specified resource.
|
||||||
*/
|
*/
|
||||||
//show(string $id)
|
// show(string $id)
|
||||||
public function get_testing_data(Request $request)
|
public function get_testing_data(Request $request)
|
||||||
{
|
{
|
||||||
$expectedUser = env('API_AUTH_USER');
|
$expectedUser = env('API_AUTH_USER');
|
||||||
$expectedPw = env('API_AUTH_PW');
|
$expectedPw = env('API_AUTH_PW');
|
||||||
$header_auth = $request->header('Authorization');
|
$header_auth = $request->header('Authorization');
|
||||||
$header_user = $request->header('User-Name');
|
$header_user = $request->header('User-Name');
|
||||||
$header_pass = $request->header('User-Pass');
|
$header_pass = $request->header('User-Pass');
|
||||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
$expectedToken = $expectedUser.':'.$expectedPw;
|
||||||
|
|
||||||
if ("Bearer " . $expectedToken != $header_auth)
|
if ('Bearer '.$expectedToken != $header_auth) {
|
||||||
{
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => 'Invalid authorization token!'
|
'status_description' => 'Invalid authorization token!',
|
||||||
], 403);
|
], 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$header_user)
|
if (! $header_user) {
|
||||||
{
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => 'Invalid user name found!'
|
'status_description' => 'Invalid user name found!',
|
||||||
], 400);
|
], 400);
|
||||||
}
|
} elseif (! $header_pass) {
|
||||||
else if (!$header_pass)
|
|
||||||
{
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => 'Invalid password found!'
|
'status_description' => 'Invalid password found!',
|
||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$existUser = User::where('name', $header_user)->first();
|
$existUser = User::where('name', $header_user)->first();
|
||||||
$existPlant = "All Plants";
|
$existPlant = 'All Plants';
|
||||||
|
|
||||||
if (!$existUser)
|
if (! $existUser) {
|
||||||
{
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => 'Unknown user name found!'
|
'status_description' => 'Unknown user name found!',
|
||||||
], 400);
|
], 400);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$codeExist = Plant::where('id', $existUser->plant_id)->first();
|
$codeExist = Plant::where('id', $existUser->plant_id)->first();
|
||||||
if ($codeExist) {
|
if ($codeExist) {
|
||||||
$existPlant = $codeExist->code;
|
$existPlant = $codeExist->code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Retrieve the user by email
|
// Retrieve the user by email
|
||||||
//$user = User::where('email', $email)->first();
|
// $user = User::where('email', $email)->first();
|
||||||
if (Hash::check($header_pass, $existUser->password)) {
|
if (Hash::check($header_pass, $existUser->password)) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'created_at' => $existUser->created_at->format('Y-m-d H:i:s') ?? "",
|
'created_at' => $existUser->created_at->format('Y-m-d H:i:s') ?? '',
|
||||||
'updated_at' => $existUser->updated_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') ?? "",
|
'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 ?? "",
|
'plant' => (string) $existPlant ?? '',
|
||||||
'email' => $existUser->email ?? "",
|
'email' => $existUser->email ?? '',
|
||||||
'roles' => $existUser->roles()->pluck('name')->toArray()
|
'roles' => $existUser->roles()->pluck('name')->toArray(),
|
||||||
], 200);
|
], 200);
|
||||||
} else {
|
} else {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => 'Password does not match!'
|
'status_description' => 'Password does not match!',
|
||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user