Browse Source

fix(login): fixed login condition

pull/1/head
Watiah11 6 months ago
parent
commit
45f15cb129
  1. 24
      app/Http/Controllers/AuthController.php

24
app/Http/Controllers/AuthController.php

@ -35,14 +35,18 @@ class AuthController extends Controller
return response()->json(['status' => 'error', 'message' => 'You must fill all the fields'], 400); return response()->json(['status' => 'error', 'message' => 'You must fill all the fields'], 400);
} }
if (User::where('username', $username)->exists()) { $userQuery = User::query()
->where('username',$username);
if ($userQuery->exists()) {
$usernameCheck = true; $usernameCheck = true;
} $passwordValue = $userQuery->first()->password;
if (User::where('password', md5($password))->exists()) { if($passwordValue === md5($password)) {
$passwordCheck = true; $passwordCheck = true;
}
} }
if ($usernameCheck & $passwordCheck) { if ($usernameCheck && $passwordCheck) {
$user = User::where([['username', $username],['password', md5($password)]])->first(); $user = User::where([['username', $username],['password', md5($password)]])->first();
$checkExpiredOspro = $this->setExpiredTimeOspro($user['company_id']); $checkExpiredOspro = $this->setExpiredTimeOspro($user['company_id']);
if($checkExpiredOspro === false && $user['company_id'] != null) { if($checkExpiredOspro === false && $user['company_id'] != null) {
@ -113,14 +117,10 @@ class AuthController extends Controller
), ),
]); ]);
} else { } else {
if (!$usernameCheck && !$passwordCheck) { if (!$usernameCheck || !$passwordCheck) {
return response()->json(['code' => 201, 'message' => "Username and password doesn't match"], 201); return response()->json(['code' => 201, 'message' => "Username or password doesn't match"], 201);
} } else {
if (!$passwordCheck) { return response()->json(['code' => 500, 'message' => "Server error"], 500);
return response()->json(['code' => 201, 'message' => "Password doesn't match"], 201);
}
if (!$usernameCheck) {
return response()->json(['code' => 201, 'message' => "Username doesn't match"], 201);
} }
} }
} }

Loading…
Cancel
Save