feat(accounts): 实现用户资料与认证页面
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
"""认证与当前用户资料页面。"""
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.shortcuts import redirect, render
|
||||
|
||||
from .forms import UserProfileForm
|
||||
from .services import get_or_create_profile
|
||||
|
||||
|
||||
@login_required
|
||||
def profile(request):
|
||||
"""读取或更新当前用户自己的资料,不接受目标用户参数。"""
|
||||
|
||||
user_profile = get_or_create_profile(request.user)
|
||||
if request.method == "POST":
|
||||
form = UserProfileForm(request.POST, instance=user_profile)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
messages.success(request, "个人资料已保存。")
|
||||
return redirect("accounts:profile")
|
||||
else:
|
||||
form = UserProfileForm(instance=user_profile)
|
||||
return render(request, "accounts/profile.html", {"form": form})
|
||||
Reference in New Issue
Block a user