Files
sam-manage/app/Http/Middleware/EnsurePasswordChanged.php
kent 7ea8997927 feat: 최초 로그인 시 비밀번호 변경 강제 기능
- User 모델에 must_change_password 필드 추가
- UserService: createUser(), resetPassword()에서 플래그 설정
- ProfileService: changePassword()에서 플래그 해제
- EnsurePasswordChanged 미들웨어 추가
- 인증 라우트에 password.changed 미들웨어 적용
- 프로필 페이지에 비밀번호 변경 필요 알림 추가

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-01 23:44:56 +09:00

40 lines
1.2 KiB
PHP

<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class EnsurePasswordChanged
{
/**
* 비밀번호 변경이 필요한 사용자를 프로필 페이지로 리다이렉트
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
$user = $request->user();
// 로그인한 사용자가 비밀번호 변경이 필요한 경우
if ($user && $user->must_change_password) {
// 프로필 관련 라우트는 허용 (무한 리다이렉트 방지)
if ($request->routeIs('profile.*')) {
return $next($request);
}
// 로그아웃 라우트는 허용
if ($request->routeIs('logout')) {
return $next($request);
}
// 그 외 모든 요청은 프로필 페이지로 리다이렉트
return redirect()->route('profile.index')
->with('warning', '보안을 위해 비밀번호를 변경해주세요.');
}
return $next($request);
}
}