def setUp(self): # User that has agreed to TOS self.user1 = get_runtime_user_model().objects.create_user('user1', '*****@*****.**', 'user1pass') # User that has not yet agreed to TOS self.user2 = get_runtime_user_model().objects.create_user('user2', '*****@*****.**', 'user2pass') self.user3 = get_runtime_user_model().objects.create_user('user3', '*****@*****.**', 'user3pass') self.tos1 = TermsOfService.objects.create( content="first edition of the terms of service", active=True ) self.tos2 = TermsOfService.objects.create( content="second edition of the terms of service", active=False ) self.login_url = getattr(settings, 'LOGIN_URL', '/login/') UserAgreement.objects.create( terms_of_service=self.tos1, user=self.user1 ) self.redirect_page = '{0}?{1}={2}'.format( reverse('tos_check_tos'), REDIRECT_FIELD_NAME, reverse('index'), )
def setUp(self): # User that has agreed to TOS self.user1 = get_runtime_user_model().objects.create_user( 'user1', '*****@*****.**', 'user1pass') # User that has not yet agreed to TOS self.user2 = get_runtime_user_model().objects.create_user( 'user2', '*****@*****.**', 'user2pass') self.user3 = get_runtime_user_model().objects.create_user( 'user3', '*****@*****.**', 'user3pass') self.tos1 = TermsOfService.objects.create( content="first edition of the terms of service", active=True) self.tos2 = TermsOfService.objects.create( content="second edition of the terms of service", active=False) self.login_url = getattr(settings, 'LOGIN_URL', '/login/') UserAgreement.objects.create(terms_of_service=self.tos1, user=self.user1) self.redirect_page = '{0}?{1}={2}'.format( reverse('tos_check_tos'), REDIRECT_FIELD_NAME, reverse('index'), )
def setUp(self): self.user1 = get_runtime_user_model().objects.create_user("user1", "*****@*****.**", "user1pass") self.user2 = get_runtime_user_model().objects.create_user("user2", "*****@*****.**", "user2pass") self.user3 = get_runtime_user_model().objects.create_user("user3", "*****@*****.**", "user3pass") self.tos1 = TermsOfService.objects.create(content="first edition of the terms of service", active=True) self.tos2 = TermsOfService.objects.create(content="second edition of the terms of service", active=False)
def setUp(self): self.user1 = get_runtime_user_model().objects.create_user( 'user1', '*****@*****.**', 'user1pass') self.user2 = get_runtime_user_model().objects.create_user( 'user2', '*****@*****.**', 'user2pass') self.user3 = get_runtime_user_model().objects.create_user( 'user3', '*****@*****.**', 'user3pass') self.tos1 = TermsOfService.objects.create( content="first edition of the terms of service", active=True) self.tos2 = TermsOfService.objects.create( content="second edition of the terms of service", active=False)
def setUp(self): self.user1 = get_runtime_user_model().objects.create_user( 'user1', '*****@*****.**', 'user1pass') self.user2 = get_runtime_user_model().objects.create_user( 'user2', '*****@*****.**', 'user2pass') self.tos1 = TermsOfService.objects.create( content="first edition of the terms of service", active=True) self.tos2 = TermsOfService.objects.create( content="second edition of the terms of service", active=False) self.login_url = getattr(settings, 'LOGIN_URL', '/login/') UserAgreement.objects.create(terms_of_service=self.tos1, user=self.user1)
def check_tos(request, template_name='tos/tos_check.html', redirect_field_name=REDIRECT_FIELD_NAME,): redirect_to = _redirect_to(request.POST.get(redirect_field_name, request.GET.get(redirect_field_name, ''))) tos = TermsOfService.objects.get_current_tos() if request.method == "POST": if request.POST.get("accept", "") == "accept": user = get_runtime_user_model().objects.get(pk=request.session['tos_user']) user.backend = request.session['tos_backend'] # Save the user agreement to the new TOS UserAgreement.objects.create(terms_of_service=tos, user=user) # Log the user in auth_login(request, user) if request.session.test_cookie_worked(): request.session.delete_test_cookie() return HttpResponseRedirect(redirect_to) else: messages.error( request, _(u"You cannot login without agreeing to the terms of this site.") ) return render_to_response(template_name, { 'tos': tos, redirect_field_name: redirect_to, }, RequestContext(request))
def check_tos(request, template_name='tos/tos_check.html', redirect_field_name=REDIRECT_FIELD_NAME,): redirect_to = _redirect_to(request.POST.get(redirect_field_name, request.GET.get(redirect_field_name, ''))) tos = TermsOfService.objects.get_current_tos() if request.method == "POST": if request.POST.get("accept", "") == "accept": user = get_runtime_user_model().objects.get(pk=request.session['tos_user']) user.backend = request.session['tos_backend'] # Save the user agreement to the new TOS UserAgreement.objects.get_or_create(terms_of_service=tos, user=user) # Log the user in auth_login(request, user) if request.session.test_cookie_worked(): request.session.delete_test_cookie() return HttpResponseRedirect(redirect_to) else: messages.error( request, _(u"You cannot login without agreeing to the terms of this site.") ) return render(request, template_name, { 'tos': tos, 'redirect_field_name': redirect_field_name, 'next': redirect_to, })
def setUp(self): self.user1 = get_runtime_user_model().objects.create_user('user1', '*****@*****.**', 'user1pass') self.user2 = get_runtime_user_model().objects.create_user('user2', '*****@*****.**', 'user2pass') self.tos1 = TermsOfService.objects.create( content="first edition of the terms of service", active=True ) self.tos2 = TermsOfService.objects.create( content="second edition of the terms of service", active=False ) self.login_url = getattr(settings, 'LOGIN_URL', '/login/') UserAgreement.objects.create( terms_of_service=self.tos1, user=self.user1 )
def check_tos( request, template_name='tos/tos_check.html', redirect_field_name=REDIRECT_FIELD_NAME, ): redirect_to = _redirect_to( request.POST.get(redirect_field_name, request.GET.get(redirect_field_name, ''))) tos = TermsOfService.objects.get_current_tos() if request.method == "POST": if request.POST.get("accept", "") == "accept": user = get_runtime_user_model().objects.get( pk=request.session['tos_user']) user.backend = request.session['tos_backend'] # Save the user agreement to the new TOS UserAgreement.objects.create(terms_of_service=tos, user=user) # Update the cache cache = get_cache(getattr(settings, 'TOS_CACHE_NAME', 'default')) key_version = cache.get('django:tos:key_version') user_id = int(request.session['_auth_user_id']) cache.set('django:tos:agreed:{0}'.format(user_id), True, version=key_version) # Log the user in auth_login(request, user) if request.session.test_cookie_worked(): request.session.delete_test_cookie() return HttpResponseRedirect(redirect_to) else: messages.error( request, _(u"You cannot login without agreeing to the terms of this site." )) if DJANGO_VERSION >= (1, 10, 0): return render(request, template_name, { 'tos': tos, redirect_field_name: redirect_to, }) else: return render_to_response(template_name, { 'tos': tos, redirect_field_name: redirect_to, }, RequestContext(request))