Skip to content

Commit

Permalink
Get rid of LoginAttemptRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
range-of-motion committed Dec 29, 2023
1 parent 4810d1b commit b855cc0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 32 deletions.
23 changes: 13 additions & 10 deletions app/Http/Controllers/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@
namespace App\Http\Controllers;

use App\Actions\StoreSpaceInSessionAction;
use App\Models\LoginAttempt;
use App\Models\User;
use App\Repositories\LoginAttemptRepository;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
private $loginAttemptRepository;

public function __construct(LoginAttemptRepository $loginAttemptRepository)
{
$this->loginAttemptRepository = $loginAttemptRepository;
}

public function index()
{
return view('login');
Expand All @@ -32,7 +25,12 @@ public function store(Request $request)
) {
$user = Auth::user();

$this->loginAttemptRepository->create($user->id, $request->ip(), false);
LoginAttempt::query()
->create([
'user_id' => $user->id,
'ip' => $request->ip(),
'failed' => false,
]);

(new StoreSpaceInSessionAction())->execute($user->spaces[0]->id);

Expand All @@ -41,7 +39,12 @@ public function store(Request $request)
if ($request->input('email')) {
$user = User::where('email', $request->input('email'))->first();

$this->loginAttemptRepository->create($user ? $user->id : null, $request->ip(), true);
LoginAttempt::query()
->create([
'user_id' => $user ? $user->id : null,
'ip' => $request->ip(),
'failed' => true,
]);
}

$request->flash();
Expand Down
12 changes: 7 additions & 5 deletions app/Http/Controllers/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,22 @@
use App\Actions\StoreSpaceInSessionAction;
use App\Actions\SendVerificationMailAction;
use App\Models\Currency;
use App\Models\LoginAttempt;
use App\Models\User;
use Illuminate\Http\Request;
// use App\Http\Controllers\Controller;

use App\Repositories\LoginAttemptRepository;
use App\Repositories\SpaceRepository;
use Illuminate\Support\Facades\Auth;

class RegisterController extends Controller
{
private $spaceRepository;
private $loginAttemptRepository;

public function __construct(
SpaceRepository $spaceRepository,
LoginAttemptRepository $loginAttemptRepository
) {
$this->spaceRepository = $spaceRepository;
$this->loginAttemptRepository = $loginAttemptRepository;
}

public function index()
Expand Down Expand Up @@ -54,7 +51,12 @@ public function store(Request $request)

Auth::loginUsingId($user->id);

$this->loginAttemptRepository->create($user->id, $request->ip(), false);
LoginAttempt::query()
->create([
'user_id' => $user->id,
'ip' => $request->ip(),
'failed' => false,
]);

(new StoreSpaceInSessionAction())->execute($user->spaces[0]->id);

Expand Down
17 changes: 0 additions & 17 deletions app/Repositories/LoginAttemptRepository.php

This file was deleted.

0 comments on commit b855cc0

Please sign in to comment.