Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Prevent user from changing the user id in this url(localhost:8000/accounts/profile/<user_id>/)
- def prevent_changing_user_id(function):
- def wrap(request, *args, **kwargs):
- from apps.accounts.views import edit_user_profile
- from apps.accounts.models import UserProfile
- if request.LANGUAGE_CODE == 'en-us':
- lang = 'en'
- else:
- lang = (request.LANGUAGE_CODE)
- # print(lang)
- user = request.user
- user_id = request.user.id
- match = UserProfile.objects.filter(user_id=user_id).exists()
- if match:
- uuid = UserProfile.objects.get(user_id=user_id)
- url_path = '/'+ lang +'/accounts/profile/user/id/'+ str(user_id) +'/unique/id/'+ str(uuid.profile_uuid) +'/'
- else:
- uuid = None
- url_path = '/'+ lang +'/accounts/profile/user/id/'+ str(user_id) + '/' # +'/unique/id/'+ str(uuid.profile_uuid) +'/'
- if user_id is not None:
- if request.path != url_path:
- # print(url_path)
- from django.http import HttpResponseRedirect
- return HttpResponseRedirect(url_path)
- else:
- return function(request, *args, **kwargs)
- else:
- raise PermissionDenied
- wrap.__doc__ = function.__doc__
- wrap.__name__ = function.__name__
- return wrap
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement