initial commit
This commit is contained in:
commit
0c42bef077
109 changed files with 16545 additions and 0 deletions
22
app/Livewire/Actions/Logout.php
Normal file
22
app/Livewire/Actions/Logout.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class Logout
|
||||
{
|
||||
/**
|
||||
* Log the current user out of the application.
|
||||
*/
|
||||
public function __invoke()
|
||||
{
|
||||
Auth::guard('web')->logout();
|
||||
|
||||
Session::invalidate();
|
||||
Session::regenerateToken();
|
||||
|
||||
return redirect('/');
|
||||
}
|
||||
}
|
||||
58
app/Livewire/Auth/PasswordReset.php
Normal file
58
app/Livewire/Auth/PasswordReset.php
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire\Auth;
|
||||
|
||||
use App\Livewire\Forms\PasswordResetForm;
|
||||
use App\Mail\PasswordResetNewUser;
|
||||
use App\Models\User;
|
||||
use App\Models\UserProfile;
|
||||
use Exception;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Component;
|
||||
use function Laravel\Prompts\error;
|
||||
|
||||
class PasswordReset extends Component
|
||||
{
|
||||
public PasswordResetForm $form;
|
||||
public string $token;
|
||||
|
||||
public function mount($token)
|
||||
{
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
#[Layout('components.layouts.auth')]
|
||||
public function resetPassword()
|
||||
{
|
||||
logger()->info("Validating password reset...");
|
||||
logger()->info($this->form);
|
||||
$validated = $this->form->validate();
|
||||
|
||||
logger()->info("Validated password reset", $validated);
|
||||
|
||||
$status = Password::reset(array_merge($validated, ['token' => $this->token]),
|
||||
function (User $user, string $password) {
|
||||
$user->forceFill([
|
||||
'password' => Hash::make($password),
|
||||
])->save();
|
||||
});
|
||||
|
||||
if ($status === Password::PASSWORD_RESET) {
|
||||
//Mail::to($user->email)->send(new PasswordResetNewUser($user));
|
||||
return redirect()->route('login');
|
||||
}
|
||||
|
||||
logger()->error("Password reset failed", $status);
|
||||
$this->addError('email', 'The provided credentials do not match our records.');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('pages.auth.reset-password');
|
||||
}
|
||||
}
|
||||
38
app/Livewire/Auth/RegisterUser.php
Normal file
38
app/Livewire/Auth/RegisterUser.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire\Auth;
|
||||
|
||||
use App\Livewire\Forms\RegisterUserForm;
|
||||
use App\Mail\PasswordResetNewUser;
|
||||
use App\Models\User;
|
||||
use App\Models\UserProfile;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Log\Logger;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\View\View;
|
||||
use Livewire\Component;
|
||||
|
||||
class RegisterUser extends Component
|
||||
{
|
||||
public RegisterUserForm $form;
|
||||
|
||||
public function register()
|
||||
{
|
||||
logger()->info("Validating...");
|
||||
logger()->info($this->form->toArray());
|
||||
$validated = $this->form->validate();
|
||||
|
||||
logger()->info("Validated", $validated);
|
||||
$user = User::create($this->form->all());
|
||||
UserProfile::create(["user_id" => $user->id]);
|
||||
|
||||
Mail::to($user->email)->send(new PasswordResetNewUser($user));
|
||||
logger()->info("New user registered: " . $user->email);
|
||||
return redirect()->route('login');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('pages.auth.register');
|
||||
}
|
||||
}
|
||||
20
app/Livewire/Forms/MovieListForm.php
Normal file
20
app/Livewire/Forms/MovieListForm.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire\Forms;
|
||||
|
||||
use Livewire\Form;
|
||||
|
||||
class MovieListForm extends Form
|
||||
{
|
||||
public string $name = "";
|
||||
public bool $is_public = false;
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'is_public' => ['required', 'boolean'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
11
app/Livewire/Forms/MovieSearchForm.php
Normal file
11
app/Livewire/Forms/MovieSearchForm.php
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire\Forms;
|
||||
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Form;
|
||||
|
||||
class MovieSearchForm extends Form
|
||||
{
|
||||
//
|
||||
}
|
||||
21
app/Livewire/Forms/PasswordResetForm.php
Normal file
21
app/Livewire/Forms/PasswordResetForm.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire\Forms;
|
||||
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Form;
|
||||
|
||||
class PasswordResetForm extends Form
|
||||
{
|
||||
public string $email = "";
|
||||
public string $password = "";
|
||||
public string $password_confirmation = "";
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'email' => ['required', 'email', 'exists:users,email'],
|
||||
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
||||
];
|
||||
}
|
||||
}
|
||||
20
app/Livewire/Forms/RegisterUserForm.php
Normal file
20
app/Livewire/Forms/RegisterUserForm.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire\Forms;
|
||||
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Form;
|
||||
|
||||
class RegisterUserForm extends Form
|
||||
{
|
||||
public string $email = "";
|
||||
public string $username = "";
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
"email" => ["required", "email", "unique:users,email"],
|
||||
"username" => ["required", "unique:users,username"],
|
||||
];
|
||||
}
|
||||
}
|
||||
58
app/Livewire/MovieList.php
Normal file
58
app/Livewire/MovieList.php
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Livewire\Forms\MovieListForm;
|
||||
use App\Models\Interfaces\MovieDbInterface;
|
||||
use App\Models\MovieList as MovieListModel;
|
||||
use Livewire\Component;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class MovieList extends Component
|
||||
{
|
||||
public int $id;
|
||||
public string $query;
|
||||
public MovieListModel $list;
|
||||
public $movies = [];
|
||||
public MovieListForm $form;
|
||||
|
||||
public function mount($id): void
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
public function getList()
|
||||
{
|
||||
$list = MovieListModel::with('movies')
|
||||
->find($this->id);
|
||||
|
||||
if ($list) {
|
||||
$this->list = $list;
|
||||
$this->movies = $list->movies;
|
||||
} else {
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
|
||||
public function addMovie(MovieDbInterface $movie_db)
|
||||
{
|
||||
$this->resetErrorBag();
|
||||
|
||||
try {
|
||||
$movie = $movie_db->search($this->query);
|
||||
} catch (NotFoundHttpException $e) {
|
||||
$this->addError('query', 'Movie not found');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->list->movies()->syncWithoutDetaching($movie->id);
|
||||
$this->getList();
|
||||
$this->form->reset();
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.movie-list');
|
||||
}
|
||||
}
|
||||
39
app/Livewire/MovieLists.php
Normal file
39
app/Livewire/MovieLists.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Livewire\Forms\MovieListForm;
|
||||
use App\Models\MovieList;
|
||||
use Livewire\Component;
|
||||
|
||||
class MovieLists extends Component
|
||||
{
|
||||
public MovieListForm $form;
|
||||
public $lists = [];
|
||||
|
||||
public function addList(): void
|
||||
{
|
||||
if (!auth()->check()) {
|
||||
$this->redirectRoute('login');
|
||||
return;
|
||||
}
|
||||
|
||||
$user = auth()->user();
|
||||
$validated = $this->form->validate();
|
||||
MovieList::create(array_merge($validated, ["user_id" => $user->id]));
|
||||
|
||||
$this->getLists();
|
||||
$this->form->reset();
|
||||
}
|
||||
|
||||
public function getLists()
|
||||
{
|
||||
$this->lists = MovieList::all();
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$this->getLists();
|
||||
return view('livewire.lists');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue