Some code cleanup [skip ci]

This commit is contained in:
James Cole 2016-12-28 18:49:30 +01:00
parent 866a7d7401
commit 7ee650ba7a
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
3 changed files with 24 additions and 19 deletions

View File

@ -18,7 +18,6 @@ use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Requests\AttachmentFormRequest; use FireflyIII\Http\Requests\AttachmentFormRequest;
use FireflyIII\Models\Attachment; use FireflyIII\Models\Attachment;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface; use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
use Log;
use Preferences; use Preferences;
use Response; use Response;
use Session; use Session;
@ -28,6 +27,8 @@ use View;
/** /**
* Class AttachmentController * Class AttachmentController
* *
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) // it's 13.
*
* @package FireflyIII\Http\Controllers * @package FireflyIII\Http\Controllers
*/ */
class AttachmentController extends Controller class AttachmentController extends Controller
@ -54,7 +55,7 @@ class AttachmentController extends Controller
/** /**
* @param Attachment $attachment * @param Attachment $attachment
* *
* @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory * @return View
*/ */
public function delete(Attachment $attachment) public function delete(Attachment $attachment)
{ {
@ -98,9 +99,6 @@ class AttachmentController extends Controller
$content = $repository->getContent($attachment); $content = $repository->getContent($attachment);
$quoted = sprintf('"%s"', addcslashes(basename($attachment->filename), '"\\')); $quoted = sprintf('"%s"', addcslashes(basename($attachment->filename), '"\\'));
Log::debug('Send file to user', ['file' => $quoted, 'size' => strlen($content)]);
return response($content, 200) return response($content, 200)
->header('Content-Description', 'File Transfer') ->header('Content-Description', 'File Transfer')
->header('Content-Type', 'application/octet-stream') ->header('Content-Type', 'application/octet-stream')
@ -112,7 +110,6 @@ class AttachmentController extends Controller
->header('Pragma', 'public') ->header('Pragma', 'public')
->header('Content-Length', strlen($content)); ->header('Content-Length', strlen($content));
} }
throw new FireflyException('Could not find the indicated attachment. The file is no longer there.'); throw new FireflyException('Could not find the indicated attachment. The file is no longer there.');
} }
@ -144,7 +141,6 @@ class AttachmentController extends Controller
{ {
$image = 'images/page_green.png'; $image = 'images/page_green.png';
if ($attachment->mime == 'application/pdf') { if ($attachment->mime == 'application/pdf') {
$image = 'images/page_white_acrobat.png'; $image = 'images/page_white_acrobat.png';
} }

View File

@ -71,19 +71,8 @@ class LoginController extends Controller
return $this->sendLoginResponse($request); return $this->sendLoginResponse($request);
} }
// check if user is blocked: $errorMessage = $this->getBlockedError($credentials['email']);
$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']]));
}
// 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) { if (!$lockedOut) {
$this->incrementLoginAttempts($request); $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;
}
} }

View File

@ -47,6 +47,7 @@ class PasswordController extends Controller
/** /**
* Send a reset link to the given user. * Send a reset link to the given user.
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's 7 but ok
* *
* @param \Illuminate\Http\Request $request * @param \Illuminate\Http\Request $request
* *