Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Sep 19, 2023
1 parent 4af152f commit b0d989e
Show file tree
Hide file tree
Showing 29 changed files with 144 additions and 168 deletions.
3 changes: 2 additions & 1 deletion app/Concerns/MustSetInitialPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public function hasSetPassword(): bool
return ! \is_null($this->password_set_at);
}

public function markPasswordAsSet(): bool
public function setPassword(string $password): bool
{
return $this->forceFill([
'password' => Hash::make($password),
'email_verified_at' => now(),
'password_set_at' => now(),
])->save();
Expand Down
2 changes: 0 additions & 2 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,5 @@ protected function schedule(Schedule $schedule): void
protected function commands(): void
{
$this->load(__DIR__ . '/Commands');

require base_path('routes/console.php');
}
}
7 changes: 1 addition & 6 deletions app/Http/Controllers/Auth/AuthenticatedSessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,8 @@ public function store(LoginRequest $request): RedirectResponse
$request->authenticate();

$request->session()->regenerate();
$redirect = RouteServiceProvider::HOME;
$redirect = match ($request->get('from', '')) {
'championship-page' => RouteServiceProvider::CHAMPIONSHIP,
default => $redirect ,
};

return redirect()->intended($redirect);
return redirect()->intended(RouteServiceProvider::getDashboardUrl());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public function store(Request $request): RedirectResponse

$request->session()->put('auth.password_confirmed_at', time());

return redirect()->intended(RouteServiceProvider::HOME);
return redirect()->intended(RouteServiceProvider::getDashboardUrl());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class EmailVerificationNotificationController extends Controller
public function store(Request $request): RedirectResponse
{
if ($request->user()->hasVerifiedEmail()) {
return redirect()->intended(RouteServiceProvider::HOME);
return redirect()->intended(RouteServiceProvider::getDashboardUrl());
}

$request->user()->sendEmailVerificationNotification();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class EmailVerificationPromptController extends Controller
public function __invoke(Request $request): RedirectResponse|Response
{
return $request->user()->hasVerifiedEmail()
? redirect()->intended(RouteServiceProvider::HOME)
? redirect()->intended(RouteServiceProvider::getDashboardUrl())
: Inertia::render('Auth/VerifyEmail', ['status' => session('status')]);
}
}
40 changes: 0 additions & 40 deletions app/Http/Controllers/Auth/PasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
use App\Models\User;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rules\Password;
use Inertia\Inertia;

class PasswordController extends Controller
{
Expand All @@ -31,42 +29,4 @@ public function update(Request $request): RedirectResponse

return back();
}

public function setInitialPassword(User $user, Request $request): \Inertia\Response
{
if (! $request->hasValidSignature()) {
abort(Response::HTTP_FORBIDDEN, __('auth.welcome.invalid_signature'));
}

if (\is_null($user)) {
abort(Response::HTTP_FORBIDDEN, __('auth.welcome.no_user'));
}

if ($user->hasSetPassword()) {
abort(Response::HTTP_FORBIDDEN, __('auth.welcome.already_used'));
}

return Inertia::render('Auth/SetInitialPassword', [
'user' => $user,
'token' => sha1($user->email),
]);
}

public function storeInitialPassword(Request $request, User $user): RedirectResponse
{
if ($request->token !== sha1($user->email)) {
abort(401);
}
$validated = $request->validate([
'password' => ['required', Password::defaults(), 'confirmed'],
]);

$user->update([
'password' => Hash::make($validated['password']),
]);
$user->markPasswordAsSet();

return redirect()->route('login')
->with('success', __('user.messages.set_initial_password_success'));
}
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/Auth/VerifyEmailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class VerifyEmailController extends Controller
public function __invoke(EmailVerificationRequest $request): RedirectResponse
{
if ($request->user()->hasVerifiedEmail()) {
return redirect()->intended(RouteServiceProvider::HOME . '?verified=1');
return redirect()->intended(RouteServiceProvider::getDashboardUrl() . '?verified=1');
}

if ($request->user()->markEmailAsVerified()) {
Expand All @@ -29,6 +29,6 @@ public function __invoke(EmailVerificationRequest $request): RedirectResponse
}
}

return redirect()->intended(RouteServiceProvider::HOME . '?verified=1');
return redirect()->intended(RouteServiceProvider::getDashboardUrl() . '?verified=1');
}
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/Dashboard/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use App\Http\Controllers\Controller;
use App\Http\Requests\Project\StoreRequest;
use App\Http\Resources\ProjectCardsResource;
use App\Http\Resources\ProjectCardResource;
use App\Models\Activity;
use App\Models\County;
use App\Models\Project;
Expand All @@ -24,7 +24,7 @@ public function index(Request $request)
$projectStatus = $request->get('project_status');

return Inertia::render('AdminOng/Projects/Projects', [
'query' => ProjectCardsResource::collection(
'query' => ProjectCardResource::collection(
Project::query()
->where('organization_id', auth()->user()->organization_id)
->when($projectStatus, function (Builder $query, $projectStatus) {
Expand Down
62 changes: 62 additions & 0 deletions app/Http/Controllers/Dashboard/WelcomeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Dashboard;

use App\Http\Controllers\Controller;
use App\Models\User;
use Closure;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Validation\Rules\Password;
use Inertia\Inertia;
use Inertia\Response as InertiaResponse;

class WelcomeController extends Controller
{
public function __construct()
{
$this->middleware(function (Request $request, Closure $next) {
abort_unless(
$request->hasValidSignature(),
Response::HTTP_FORBIDDEN,
__('auth.welcome.invalid_signature')
);

abort_unless(
$request->user,
Response::HTTP_FORBIDDEN,
__('auth.welcome.no_user')
);

abort_if(
$request->user->hasSetPassword(),
Response::HTTP_FORBIDDEN,
__('auth.welcome.already_used')
);

return $next($request);
});
}

public function create(Request $request, User $user): InertiaResponse
{
return Inertia::render('Auth/Welcome', [
'email' => $user->email,
]);
}

public function store(Request $request, User $user): RedirectResponse
{
$attributes = $request->validate([
'password' => ['required', 'confirmed', Password::defaults()],
]);

$user->setPassword($attributes['password']);

return redirect()->route('login')
->with('success', __('user.messages.set_initial_password_success'));
}
}
17 changes: 9 additions & 8 deletions app/Http/Controllers/EvolutionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
use App\Models\ActivityDomain;
use App\Models\County;
use Inertia\Inertia;
use Inertia\Response;

class EvolutionController extends Controller
{
public function index()
public function __invoke(): Response
{
$donations = 102030;
$amount = 122345;
Expand Down Expand Up @@ -132,22 +133,22 @@ public function index()
'first_page_url' => 'http://bursabinelui.test/articole?page=1',
'from' => 1,
'last_page' => 2,
'last_page_url'=> 'http://bursabinelui.test/articole?page=2',
'last_page_url' => 'http://bursabinelui.test/articole?page=2',
'links' => [
[
'url' => 'http://bursabinelui.test/articole?page=1',
'label' => '1',
'active' => true,
],
[
'url'=> 'http://bursabinelui.test/articole?page=2',
'label'=> '2',
'active'=> false,
'url' => 'http://bursabinelui.test/articole?page=2',
'label' => '2',
'active' => false,
],
],
'next_page_url'=> 'http://bursabinelui.test/articole?page=1',
'path'=> 'http://bursabinelui.test/articole',
'per_page' =>15,
'next_page_url' => 'http://bursabinelui.test/articole?page=1',
'path' => 'http://bursabinelui.test/articole',
'per_page' => 15,
'prev_page_url' => null,
'to' => 15,
'total' => 20,
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace App\Http\Controllers;

use App\Http\Resources\BCRProjectCardsResource;
use App\Http\Resources\ProjectCardsResource;
use App\Http\Resources\BCRProjectCardResource;
use App\Http\Resources\ProjectCardResource;
use App\Models\Article;
use App\Models\Organization;
use App\Models\Project;
Expand All @@ -26,14 +26,14 @@ public function index()
->isApproved()
->count(),

'projects' => ProjectCardsResource::collection(
'projects' => ProjectCardResource::collection(
Project::publish()
->inRandomOrder()
->limit(12)
->get()
),

'bcr_projects' => BCRProjectCardsResource::collection(
'bcr_projects' => BCRProjectCardResource::collection(
Project::publish()
// TODO: ->whereOrganizationIsBCR()
->limit(12)
Expand Down
7 changes: 1 addition & 6 deletions app/Http/Livewire/Welcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\ValidationException;
use Livewire\Component;

Expand Down Expand Up @@ -70,11 +69,7 @@ public function handle(): ?LoginResponse
]);
}

$this->user->update([
'password' => Hash::make(data_get($this->form->getState(), 'password')),
]);

$this->user->markPasswordAsSet();
$this->user->setPassword(data_get($this->form->getState(), 'password'));

Filament::auth()->login($this->user);

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function handle(Request $request, Closure $next, string ...$guards): Resp

foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return redirect(RouteServiceProvider::HOME);
return redirect(RouteServiceProvider::getDashboardUrl());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Vite;

class BCRProjectCardsResource extends JsonResource
class BCRProjectCardResource extends JsonResource
{
public static $wrap = null;

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Resources/Organizations/ShowOrganizationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Http\Resources\Organizations;

use App\Http\Resources\ProjectCardsResource;
use App\Http\Resources\ProjectCardResource;
use App\Models\Project;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
Expand Down Expand Up @@ -32,7 +32,7 @@ public function toArray(Request $request): array
'status' => $this->status,
'eu_platesc_merchant_id' => filled($this->eu_platesc_merchant_id),
'eu_platesc_private_key' => filled($this->eu_platesc_private_key),
'projects' => ProjectCardsResource::collection(
'projects' => ProjectCardResource::collection(
$this->projects->map(function (Project $project) {
$project->setRelation('organization', $this);

Expand Down
2 changes: 1 addition & 1 deletion app/Notifications/Ngo/WelcomeNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function toMail(object $notifiable): MailMessage
'app' => config('app.name'),
]))
->action(__('auth.welcome.submit'), URL::signedRoute(
'ngo.user.welcome',
'dashboard.auth.welcome',
['user' => $notifiable->id]
));
}
Expand Down
Loading

0 comments on commit b0d989e

Please sign in to comment.