Exemple #1
0
    def form_valid(self, form):

        self.object = form.save()
        set_current_account(self.request, self.object)
        data = {'status': 'success'}

        if self.object.enforce_2fa and not self.request.user.is_verified() \
                or 'from_social_login' in self.request.session and not self.object.enable_social_logins:
            data['reload'] = True
            data['url'] = '#'

        # delete 2FA settings for all users when 2FA is de-activated
        if 'enforce_2fa' in form.changed_data and not self.object.enforce_2fa \
                and settings.T2FA_CLEAR_USER_CONFIGS:

            for member in self.object.memberships.all():
                u = member.user
                logger.warn(
                    "deleting 2FA configuration for user `%s`: totp=%i phones=%i bak=%i"
                    % (member.user.email, u.totpdevice_set.count(),
                       u.phonedevice_set.count(), u.staticdevice_set.count()))
                u.totpdevice_set.all().delete()
                u.phonedevice_set.all().delete()
                u.staticdevice_set.all().delete()

        return self.render_to_json_response(data)
Exemple #2
0
 def setUp(self):
     self.create_init_data()
     self.news = NewsFactory(account=self.account)
     self.client.login(username=self.admin.email, password='******')
     self.session = self.client.session
     set_current_account(self, self.account)
     self.session.save()
Exemple #3
0
 def setUp(self):
     self.create_init_data()
     self.meeting = Meeting.objects.latest('pk')
     self.client.login(username=self.admin.email, password='******')
     self.session = self.client.session
     set_current_account(self, self.account)
     self.session.save()
 def setUp(self):
     self.create_init_data()
     self.committee = Committee.objects.latest('pk')
     self.membership.committees.add(self.committee)
     self.client.login(username=self.admin.email, password='******')
     self.session = self.client.session
     set_current_account(self, self.account)
     self.session.save()
 def setUp(self):
     self.create_init_data()
     self.login_member()
     request = RequestFactory().get('/{}/dashboard/'.format(self.account.url))
     request.session = {}
     set_current_account(request, self.account)
     request.user = self.user
     request.resolver_match = ResolverMatch(self.setUp, [], {}, app_names=['dashboard'])
     self.c = RequestContext(request)
Exemple #6
0
 def post(self, request, *args, **kwargs):
     if self.request.is_ajax() and 'account_id' in self.request.POST:
         account = get_object_or_404(Account,
                                     id=self.request.POST.get('account_id'))
         set_current_account(request, account)
         Membership.objects.filter(
             user=self.request.user,
             account=account).update(last_login=timezone.now())
         url = reverse('dashboard:dashboard', kwargs={'url': account.url})
         data = json.dumps({'url': url})
         kwargs['content_type'] = 'application/json'
         return HttpResponse(data, kwargs)
Exemple #7
0
 def form_valid(self, form):
     self.object = form.save()
     set_current_account(self.request, self.object)
     data = {'status': 'success'}
     return self.render_to_json_response(data)
 def login_admin2(self):
     self.assertTrue(self.client.login(username=self.admin2.email, password='******'),
                     msg="Can't login admin2 username={0}, password=admin".format(self.admin2.email))
     self.session = self.client.session
     set_current_account(self, self.account2)
     self.session.save()
 def login_member(self, email=None):
     email = email or self.user.email
     self.assertTrue(self.client.login(username=email, password='******'), msg="Can't login username={0}, password=member".format(email))
     self.session = self.client.session
     set_current_account(self, self.account)
     self.session.save()
 def login_admin(self):
     self.client.login(username=self.admin.email, password='******')
     self.session = self.client.session
     set_current_account(self, self.account)
     self.session.save()