パスワード変更機能を追加

- バックエンド: POST /api/auth/change-password/ エンドポイントを追加
- フロントエンド: /settings/password ページを追加(現在のPW確認・8文字バリデーション)
- Navbar: ログアウトボタン横に鍵アイコンでパスワード変更リンクを追加

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Akira
2026-02-25 09:51:03 +09:00
parent a010ece7ed
commit 407d915b35
3 changed files with 173 additions and 2 deletions

View File

@@ -19,6 +19,28 @@ from django.urls import path, include
from rest_framework.routers import DefaultRouter
from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView
from apps.fields.views import OfficialKyosaiFieldViewSet, OfficialChusankanFieldViewSet
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
from rest_framework.permissions import IsAuthenticated
class ChangePasswordView(APIView):
permission_classes = [IsAuthenticated]
def post(self, request):
user = request.user
current_password = request.data.get('current_password', '')
new_password = request.data.get('new_password', '')
if not current_password or not new_password:
return Response({'error': '現在のパスワードと新しいパスワードを入力してください'}, status=status.HTTP_400_BAD_REQUEST)
if not user.check_password(current_password):
return Response({'error': '現在のパスワードが正しくありません'}, status=status.HTTP_400_BAD_REQUEST)
if len(new_password) < 8:
return Response({'error': 'パスワードは8文字以上にしてください'}, status=status.HTTP_400_BAD_REQUEST)
user.set_password(new_password)
user.save()
return Response({'status': 'ok'})
master_router = DefaultRouter()
master_router.register(r'kyosai-fields', OfficialKyosaiFieldViewSet, basename='kyosai-field')
@@ -32,5 +54,6 @@ urlpatterns = [
path('api/reports/', include('apps.reports.urls')),
path('api/auth/jwt/create/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
path('api/auth/jwt/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
path('api/auth/change-password/', ChangePasswordView.as_view(), name='change-password'),
path('api/mail/', include('apps.mail.urls')),
]