Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
QUEUE_CONNECTION=database
SESSION_DRIVER=database
SESSION_LIFETIME=120
REMEMBER_ME=4320
Expand Down
19 changes: 10 additions & 9 deletions app/Http/Controllers/Api/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,49 +26,50 @@ public function login(Request $request)
'email' => 'required|email',
'password' => 'required'
]);

if ($validateUser->fails()) {
return response()->json([
'status' => false,
'message' => __('Validation Error!'),
'errors' => $validateUser->errors()
], 401);
}

// Normalize email to lowercase
$credentials = [
'email' => strtolower($request->input('email')),
'password' => $request->input('password')
];

// Attempt authentication
if (!Auth::attempt($credentials)) {
return response()->json([
'status' => false,
'message' => __('Email & Password do not match our records.'),
], 401);
}

// Get the authenticated user
$user = Auth::user();

// Define the roles to check
$allowedRoles = [
'Super Admin',
'Municipality - Super Admin',
'Municipality - Building Surveyor',
'Municipality - Infrastructure Department',
'Service Provider - Emptying Operator'
'Service Provider - Emptying Operator',
'Municipality - Map Viewer',
];

// Check if the user has any of the allowed roles
if (!$user->hasAnyRole($allowedRoles)) {
return response()->json([
'status' => false,
'message' => __('Unauthorized: You do not have the required role to log in.'),
], 403);
}

// Generate the token and return success response
return response()->json([
'status' => true,
Expand All @@ -94,7 +95,7 @@ public function login(Request $request)
], 500);
}
}


public function logout()
{
Expand Down
25 changes: 12 additions & 13 deletions app/Http/Controllers/Api/BuildingSurveyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,26 @@ public function getWardWms(){
public function getRoadWms(){
return $this->getWmsLink("roads");
}



public function getBuildingCodes()
{
try {
try {
$buildingCodes = Building::whereNull('deleted_at')->pluck('bin');

if ($buildingCodes->isEmpty()) {
return response()->json([
'status' => 404,
'message' => __('No building codes found.'),
], 404);
}

return response()->json([
'status' => 200,
'message' => __('Building codes fetched successfully.'),
'data' => $buildingCodes,

]);
} catch(\Exception $e) {
return response()->json([
Expand All @@ -71,21 +71,21 @@ public function getBuildingCodes()

public function getSewerCodes()
{
try {
try {
$sewerCodes = SewerLine::whereNull('deleted_at')->pluck('code');

if ($sewerCodes->isEmpty()) {
return response()->json([
'status' => 404,
'message' => __('No sewer codes found.'),
], 404);
}

return response()->json([
'status' => 200,
'message' => __('Sewer codes fetched successfully.'),
'data' => $sewerCodes,

]);
} catch(\Exception $e) {
return response()->json([
Expand Down Expand Up @@ -113,10 +113,9 @@ public function saveBuilding(BuildingSurveyRequest $request){
try {
if ($request->validated()){
$buildingSurvey = BuildingSurvey::create($request->all());

$buildingSurvey->user_id= Auth::id();
$kml = $request->kml;

if (!$kml) {
if ($buildingSurvey){
$buildingSurvey->forceDelete();
Expand Down Expand Up @@ -200,7 +199,7 @@ public function saveContainment(ContainmentSurveyRequest $request){
'message' => __('Service Providers'),
];
}

/**
* Get link of specified layer
*
Expand Down
Loading