update
This commit is contained in:
@ -51,56 +51,72 @@ class LoginController extends Controller
|
||||
return "email";
|
||||
}
|
||||
|
||||
// public function login(Request $req)
|
||||
// {
|
||||
// $this->validateLogin($req);
|
||||
|
||||
// if (method_exists($this, "hasTooManyLoginAttempts") && $this->hasTooManyLoginAttempts($req)) {
|
||||
// $this->fireLockoutEvent($req);
|
||||
|
||||
// return $this->sendLockoutResponse($req);
|
||||
// }
|
||||
|
||||
// if ($this->guard()->validate($this->credentials($req))) {
|
||||
// $user = $this->guard()->getLastAttempted();
|
||||
|
||||
// if ($user->dlt != null) {
|
||||
// $this->incrementLoginAttempts($req);
|
||||
// throw ValidationException::withMessages([
|
||||
// $this->username() => [trans("auth.failed")],
|
||||
// ]);
|
||||
// }
|
||||
// if ($user->status != Users::STATUS_ACTIVE) {
|
||||
// $this->incrementLoginAttempts($req);
|
||||
|
||||
// throw ValidationException::withMessages([
|
||||
// $this->username() => __("Your account not active, please contact admin."),
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// if ($this->attemptLogin($req)) {
|
||||
// return $this->sendLoginResponse($req);
|
||||
// }
|
||||
// }
|
||||
|
||||
// $this->incrementLoginAttempts($req);
|
||||
|
||||
// return $this->sendFailedLoginResponse($req);
|
||||
// }
|
||||
public function login(Request $req)
|
||||
{
|
||||
$this->validateLogin($req);
|
||||
|
||||
// If the class is using the ThrottlesLogins trait, we can automatically throttle
|
||||
// the login attempts for this application. We'll key this by the username and
|
||||
// the IP address of the client making these requests into this application.
|
||||
if (
|
||||
method_exists($this, "hasTooManyLoginAttempts") &&
|
||||
$this->hasTooManyLoginAttempts($req)
|
||||
) {
|
||||
if (method_exists($this, "hasTooManyLoginAttempts") && $this->hasTooManyLoginAttempts($req)) {
|
||||
$this->fireLockoutEvent($req);
|
||||
|
||||
return $this->sendLockoutResponse($req);
|
||||
}
|
||||
|
||||
if ($this->guard()->validate($this->credentials($req))) {
|
||||
$user = $this->guard()->getLastAttempted();
|
||||
if ($user->dlt != null) {
|
||||
$this->incrementLoginAttempts($req);
|
||||
throw ValidationException::withMessages([
|
||||
$this->username() => [trans("auth.failed")],
|
||||
]);
|
||||
}
|
||||
if ($user->status != Users::STATUS_ACTIVE) {
|
||||
// Increment the failed login attempts and redirect back to the
|
||||
// login form with an error message.
|
||||
$this->incrementLoginAttempts($req);
|
||||
// return redirect()
|
||||
// ->back()
|
||||
// ->withInput($req->only($this->username(), 'remember'))
|
||||
// ->withErrors(['active' => 'You must be active to login.']);
|
||||
throw ValidationException::withMessages([
|
||||
$this->username() => __(
|
||||
"Your account not active, please contact admin."
|
||||
),
|
||||
]);
|
||||
}
|
||||
// Cari user yang belum dihapus (dlt == null)
|
||||
$user = Users::where("email", $req->email)
|
||||
->whereNull("dlt")
|
||||
->first();
|
||||
|
||||
if ($this->attemptLogin($req)) {
|
||||
return $this->sendLoginResponse($req);
|
||||
}
|
||||
if (!$user || !\Hash::check($req->password, $user->password)) {
|
||||
$this->incrementLoginAttempts($req);
|
||||
return $this->sendFailedLoginResponse($req);
|
||||
}
|
||||
|
||||
// If the login attempt was unsuccessful we will increment the number of attempts
|
||||
// to login and redirect the user back to the login form. Of course, when this
|
||||
// user surpasses their maximum number of attempts they will get locked out.
|
||||
$this->incrementLoginAttempts($req);
|
||||
if ($user->status != Users::STATUS_ACTIVE) {
|
||||
$this->incrementLoginAttempts($req);
|
||||
throw ValidationException::withMessages([
|
||||
$this->username() => __("Your account not active, please contact admin."),
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->sendFailedLoginResponse($req);
|
||||
// Login manual
|
||||
$this->guard()->login($user);
|
||||
|
||||
return $this->sendLoginResponse($req);
|
||||
}
|
||||
|
||||
protected function validateLogin(Request $req)
|
||||
@ -139,9 +155,7 @@ class LoginController extends Controller
|
||||
} elseif ($user->role == Users::ROLE_CHECKER) {
|
||||
return redirect(route("view_user_checker"));
|
||||
} elseif ($user->role == Users::ROLE_CLIENT_ADMIN) {
|
||||
return redirect(
|
||||
route("view_user_client_transaction_add") . "?rdl=1"
|
||||
);
|
||||
return redirect(route("view_user_client_transaction_add") . "?rdl=1");
|
||||
} elseif ($user->role == Users::ROLE_SPECIAL_TRACKING) {
|
||||
return redirect(route("view_dashboard"));
|
||||
} elseif ($user->role == Users::ROLE_FINANCE) {
|
||||
@ -166,9 +180,7 @@ class LoginController extends Controller
|
||||
if ($response = $this->loggedOut($req)) {
|
||||
return $response;
|
||||
}
|
||||
return $req->wantsJson()
|
||||
? new JsonResponse([], 204)
|
||||
: redirect(route("login_admin"));
|
||||
return $req->wantsJson() ? new JsonResponse([], 204) : redirect(route("login_admin"));
|
||||
} elseif ($user->role == Users::ROLE_FINANCE) {
|
||||
$this->guard()->logout();
|
||||
$req->session()->invalidate();
|
||||
@ -176,9 +188,7 @@ class LoginController extends Controller
|
||||
if ($response = $this->loggedOut($req)) {
|
||||
return $response;
|
||||
}
|
||||
return $req->wantsJson()
|
||||
? new JsonResponse([], 204)
|
||||
: redirect(route("login_admin"));
|
||||
return $req->wantsJson() ? new JsonResponse([], 204) : redirect(route("login_admin"));
|
||||
} elseif ($user->role == Users::ROLE_VENDOR) {
|
||||
$this->guard()->logout();
|
||||
$req->session()->invalidate();
|
||||
@ -186,9 +196,7 @@ class LoginController extends Controller
|
||||
if ($response = $this->loggedOut($req)) {
|
||||
return $response;
|
||||
}
|
||||
return $req->wantsJson()
|
||||
? new JsonResponse([], 204)
|
||||
: redirect(route("login_vendor"));
|
||||
return $req->wantsJson() ? new JsonResponse([], 204) : redirect(route("login_vendor"));
|
||||
} elseif ($user->role == Users::ROLE_CHECKER) {
|
||||
$this->guard()->logout();
|
||||
$req->session()->invalidate();
|
||||
@ -196,9 +204,7 @@ class LoginController extends Controller
|
||||
if ($response = $this->loggedOut($req)) {
|
||||
return $response;
|
||||
}
|
||||
return $req->wantsJson()
|
||||
? new JsonResponse([], 204)
|
||||
: redirect(route("login_checker"));
|
||||
return $req->wantsJson() ? new JsonResponse([], 204) : redirect(route("login_checker"));
|
||||
} elseif ($user->role == Users::ROLE_CLIENT_ADMIN) {
|
||||
$this->guard()->logout();
|
||||
$req->session()->invalidate();
|
||||
@ -206,9 +212,7 @@ class LoginController extends Controller
|
||||
if ($response = $this->loggedOut($req)) {
|
||||
return $response;
|
||||
}
|
||||
return $req->wantsJson()
|
||||
? new JsonResponse([], 204)
|
||||
: redirect(route("login_client"));
|
||||
return $req->wantsJson() ? new JsonResponse([], 204) : redirect(route("login_client"));
|
||||
} elseif ($user->role == Users::ROLE_SPECIAL_TRACKING) {
|
||||
$this->guard()->logout();
|
||||
$req->session()->invalidate();
|
||||
@ -216,9 +220,7 @@ class LoginController extends Controller
|
||||
if ($response = $this->loggedOut($req)) {
|
||||
return $response;
|
||||
}
|
||||
return $req->wantsJson()
|
||||
? new JsonResponse([], 204)
|
||||
: redirect(route("login_admin"));
|
||||
return $req->wantsJson() ? new JsonResponse([], 204) : redirect(route("login_admin"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user