megahunt.test/app/Http/Controllers/PublicUserController.php

33 lines
727 B
PHP
Raw Permalink Normal View History

2024-08-29 11:48:29 +02:00
<?php
namespace App\Http\Controllers;
2024-08-30 01:28:17 +02:00
use App\Http\Requests\LoginRequest;
2024-08-30 00:46:03 +02:00
use App\Http\Requests\RegisterRequest;
2024-08-30 01:28:17 +02:00
use App\Services\UserService;
2024-08-29 11:48:29 +02:00
class PublicUserController extends Controller
{
2024-08-30 01:28:17 +02:00
public function __construct(
private UserService $userService
2024-08-30 09:40:57 +02:00
) {}
2024-08-30 01:28:17 +02:00
2024-08-30 00:46:03 +02:00
public function register(RegisterRequest $request)
2024-08-29 11:48:29 +02:00
{
2024-08-30 01:28:17 +02:00
$this->userService->create($request->all());
2024-08-29 11:48:29 +02:00
}
2024-08-29 12:34:01 +02:00
2024-08-30 01:28:17 +02:00
public function login(LoginRequest $request)
2024-08-29 12:34:01 +02:00
{
2024-08-30 09:40:57 +02:00
if (! $this->userService->login($request->all())) {
2024-08-29 12:34:01 +02:00
return response()
->json('bad_password', 400);
}
}
2024-08-29 13:10:02 +02:00
2024-08-30 01:28:17 +02:00
public function reset(LoginRequest $request)
2024-08-29 13:10:02 +02:00
{
2024-08-30 03:31:22 +02:00
$this->userService->setPassword($request->all());
2024-08-29 13:10:02 +02:00
}
2024-08-29 11:48:29 +02:00
}