sayali #9
@@ -20,7 +20,7 @@ class AuthController extends Controller
|
||||
try {
|
||||
// Validate incoming request data
|
||||
$validator = Validator::make($request->all(), [
|
||||
'email_address' => 'required|email',
|
||||
'email' => 'required|email',
|
||||
'password' => 'required',
|
||||
]);
|
||||
|
||||
@@ -32,26 +32,26 @@ class AuthController extends Controller
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
// $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_address', $request->email_address)->whereNull('deleted_at')->first();
|
||||
$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_address);
|
||||
Log::error('Entered Password is wrong for ' . $request->email);
|
||||
return jsonResponseWithErrorMessageApi(__('auth.incorrect_password'), 403);
|
||||
}
|
||||
|
||||
// Attempt to authenticate the user
|
||||
$credentials = [
|
||||
'email_address' => $request->email_address,
|
||||
'email' => $request->email,
|
||||
'password' => $request->password,
|
||||
];
|
||||
|
||||
@@ -69,14 +69,11 @@ class AuthController extends Controller
|
||||
}
|
||||
|
||||
// Authentication failed
|
||||
return jsonResponseWithErrorMessageApi(__('auth.authentication_failed'), 401);
|
||||
|
||||
} catch (QueryException $e) {
|
||||
}
|
||||
catch (QueryException $e) {
|
||||
Log::error('Customer Login Failed: ' . $e->getMessage());
|
||||
return jsonResponseWithErrorMessageApi(__('auth.authentication_failed'), 401);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Unexpected error during login: ' . $e->getMessage());
|
||||
return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,12 +6,21 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Tymon\JWTAuth\Contracts\JWTSubject;
|
||||
|
||||
class User extends Authenticatable
|
||||
class User extends Authenticatable implements JWTSubject
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
public function getJWTIdentifier()
|
||||
{
|
||||
return $this->getKey();
|
||||
}
|
||||
|
||||
public function getJWTCustomClaims()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user