Merge pull request 'sayali' (#11) from sayali into main

Reviewed-on: Nikhil.Kadam/vib360#11
This commit is contained in:
2025-03-11 14:48:35 +00:00
2 changed files with 57 additions and 11 deletions

View File

@@ -18,38 +18,29 @@ class AuthController extends Controller
public function login(Request $request)
{
try {
// Validate incoming request data
$validator = Validator::make($request->all(), [
'email' => 'required|email',
'password' => 'required',
]);
// Check if validation failed
if ($validator->fails()) {
$validationErrors = $validator->errors()->all();
Log::error("Login validation error: " . implode(", ", $validationErrors));
return jsonResponseWithErrorMessageApi($validationErrors, 403);
}
// Check if the user is soft-deleted
// $isDelete = User::where('email_address', $request->email_address)->onlyTrashed()->first();
// if ($isDelete) {
// return jsonResponseWithErrorMessageApi(__('auth.deleted_user_by_admin'), 403);
// }
// Check if the user exists and is not soft-deleted
$isExistEmail = User::where('email', $request->email)->first();
if ($isExistEmail == null) {
return jsonResponseWithErrorMessageApi(__('auth.incorrect_email'), 403);
}
// Check if the entered password matches the stored password
if ($isExistEmail && !(Hash::check($request->password, $isExistEmail->password))) {
Log::error('Entered Password is wrong for ' . $request->email);
return jsonResponseWithErrorMessageApi(__('auth.incorrect_password'), 403);
}
// Attempt to authenticate the user
$credentials = [
'email' => $request->email,
'password' => $request->password,
@@ -68,7 +59,6 @@ class AuthController extends Controller
return jsonResponseWithSuccessMessage(__('auth.data_fetched_successfully'), $response, 200);
}
// Authentication failed
}
catch (QueryException $e) {

View File

@@ -0,0 +1,56 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Tymon\JWTAuth\Facades\JWTAuth;
use Tymon\JWTAuth\Exceptions\JWTException;
use Illuminate\Support\Facades\Session;
class CheckUserStatus
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
// Check if the custom access-token header is present
if (!$request->hasHeader('access-token')) {
return response()->json([
'status' => 'error',
'status_code' => 401,
'message' => 'Access token not provided'
], 401);
}
// Retrieve the token from the custom access-token header
$token = $request->header('access-token');
try {
// Attempt to authenticate the user based on the token
$user = JWTAuth::setToken($token)->authenticate();
if (!$user || $user->authority !== 'CUSTOMER_USER') {
return response()->json([
'status' => 'error',
'status_code' => 403,
'message' => 'Unauthorized access'
], 403);
}
Session::flash('vendorToken', $token);
} catch (JWTException $e) {
return response()->json([
'status' => 'error',
'status_code' => 401,
'message' => 'Invalid token'
], 401);
}
return $next($request);
}
}