Каркас Laravel-приложения: Breeze+Sanctum, схема БД, модели, Docker
Laravel 13 в laravel-app/, Breeze (Blade) для сессионного логина + Sanctum для API-токенов (задел под Vue/Flutter на этапе 3). Схема Postgres перенесена из сырого SQL в Laravel-миграции (владелец схемы теперь Laravel, Go-сервисы как читали/писали эти таблицы, так и продолжают). Роли/категории/ операторы условий — закрытые PHP-enum'ы (UserRole, DeviceCategory, ConditionOperator); action_type правил намеренно остаётся строкой — открытый, управляемый данными список, а не код. Сидер device_types с growbox-типами как пример данных, не бизнес-логика. Docker: один контейнер (php-fpm + nginx через supervisord, multi-stage сборка vendor/assets). Образ пока не --no-dev — сидер использует fake() для демо-аккаунта. Проверено: миграции применяются на реальном Postgres (в докере и локально), дефолтные тесты Breeze проходят (25/25), Breeze-логин подтверждён вживую через браузер, Sanctum корректно отдаёт 401 на защищённый /api/user без токена.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Events\PasswordReset;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class NewPasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset view.
|
||||
*/
|
||||
public function create(Request $request): View
|
||||
{
|
||||
return view('auth.reset-password', ['request' => $request]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming new password request.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'token' => ['required'],
|
||||
'email' => ['required', 'email'],
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
// Here we will attempt to reset the user's password. If it is successful we
|
||||
// will update the password on an actual user model and persist it to the
|
||||
// database. Otherwise we will parse the error and return the response.
|
||||
$status = Password::reset(
|
||||
$request->only('email', 'password', 'password_confirmation', 'token'),
|
||||
function (User $user) use ($request) {
|
||||
$user->forceFill([
|
||||
'password' => Hash::make($request->password),
|
||||
'remember_token' => Str::random(60),
|
||||
])->save();
|
||||
|
||||
event(new PasswordReset($user));
|
||||
}
|
||||
);
|
||||
|
||||
// If the password was successfully reset, we will redirect the user back to
|
||||
// the application's home authenticated view. If there is an error we can
|
||||
// redirect them back to where they came from with their error message.
|
||||
return $status == Password::PASSWORD_RESET
|
||||
? redirect()->route('login')->with('status', __($status))
|
||||
: back()->withInput($request->only('email'))
|
||||
->withErrors(['email' => __($status)]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user