Skip to content

Commit

Permalink
add(#50): local_user decorator
Browse files Browse the repository at this point in the history
local_user만 접근 가능한 데코레이터 생성
  • Loading branch information
Charmull committed Aug 20, 2021
1 parent 9083593 commit b8913f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions user/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,17 @@ def wrap(request, *args, **kwargs):
path = request.get_full_path()

return redirect("/profile/login/?next="+ path)
return wrap


# 로컬 유저만 접근할 수 있도록 하는 데코레이터
# 소셜 유저일 경우 mypage로 이동시키게 하기 (현재 password change만이 소셜 유저가 접근 불가능한 기능이기 때문)
def local_user(function):
@wraps(function)
def wrap(request, *args, **kwargs):
if request.user.is_social == False and request.user.is_ToS == True:
return function(request, *args, **kwargs)
else:
return redirect("profile:mypage")

return wrap
4 changes: 2 additions & 2 deletions user/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from .forms import CustomSetPasswordForm

# ----------------------smtp-------------------------------
from .decorators import allowed_user, required_login
from .decorators import allowed_user, required_login, local_user


# ----login 관련----
Expand Down Expand Up @@ -381,8 +381,8 @@ def profile_modify(request):
return render(request, 'profile/profile_update.html', ctx)

# TODO : 기존과 같은 비밀번호로 바꿔도 바뀜...
# TODO : local user만 가능하도록 decorator 만들어주기
@required_login
@local_user
def password_change(request):
if request.method == 'POST':
form = LocalPasswordChangeForm(request.user, request.POST)
Expand Down

0 comments on commit b8913f8

Please sign in to comment.