我有一个项目,用户可以使用密码访问房间,如何创建会话以在首次通过后记住该用户,我还想设置该会话的到期日期。也许您知道实现该目标的不同方法>
views.py
try:
room_type = getattr(Room.objects.get(invite_url=uuid), 'room_type')
except ValueError:
raise Http404
if room_type == 'private':
if request.method == 'POST':
user = request.user.username
form_auth = AuthRoomForm(request.POST)
if form_auth.is_valid():
try:
room_pass = getattr(Room.objects.get(invite_url=uuid), 'room_pass')
except ValueError:
raise Http404
password2 = form_auth.cleaned_data.get('password2')
if room_pass != password2:
messages.error(request, 'Doesn\'t match')
return HttpResponseRedirect(request.get_full_path())
else:
# messages.success(request, 'match')
user = CustomUser.objects.get(username=user)
try:
room = get_object_or_404(Room, invite_url=uuid)
except ValueError:
raise Http404
assign_perm('pass_perm',user, room)
if user.has_perm('pass_perm', room):
# return HttpResponseRedirect(Room.get_absolute_url(room))
return join_room(request,uuid)
else:
return HttpResponse('Problem issues')
else:
form_auth = AuthRoomForm()
return render(request,'rooms/auth_join.html', {'form_auth':form_auth})
else:
return HttpResponse('this work on private room only')