Some code cleanup [skip ci]

This commit is contained in:
James Cole
2016-12-28 18:49:30 +01:00
parent 866a7d7401
commit 7ee650ba7a
3 changed files with 24 additions and 19 deletions

View File

@@ -71,19 +71,8 @@ class LoginController extends Controller
return $this->sendLoginResponse($request);
}
// check if user is blocked:
$errorMessage = '';
/** @var User $foundUser */
$foundUser = User::where('email', $credentials['email'])->where('blocked', 1)->first();
if (!is_null($foundUser)) {
// user exists, but is blocked:
$code = strlen(strval($foundUser->blocked_code)) > 0 ? $foundUser->blocked_code : 'general_blocked';
$errorMessage = strval(trans('firefly.' . $code . '_error', ['email' => $credentials['email']]));
}
$errorMessage = $this->getBlockedError($credentials['email']);
// 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.
if (!$lockedOut) {
$this->incrementLoginAttempts($request);
}
@@ -148,4 +137,23 @@ class LoginController extends Controller
]
);
}
/**
* @param string $email
*
* @return string
*/
private function getBlockedError(string $email): string
{
// check if user is blocked:
$errorMessage = '';
/** @var User $foundUser */
$foundUser = User::where('email', $email)->where('blocked', 1)->first();
if (!is_null($foundUser)) {
// user exists, but is blocked:
$code = strlen(strval($foundUser->blocked_code)) > 0 ? $foundUser->blocked_code : 'general_blocked';
$errorMessage = strval(trans('firefly.' . $code . '_error', ['email' => $email]));
}
return $errorMessage;
}
}