Fixes checking invite validity

This commit is contained in:
Mouse Reeve 2021-01-04 11:14:10 -08:00
parent 81e60cea16
commit 9102d81767
2 changed files with 7 additions and 5 deletions

View file

@ -173,7 +173,7 @@ class ViewActions(TestCase):
self.assertEqual(response.status_code, 302)
self.assertEqual(models.SiteInvite.objects.get().times_used, 1)
# invalid invite
# invite already used to max capacity
request = self.factory.post(
'register/',
{
@ -182,6 +182,7 @@ class ViewActions(TestCase):
'email': 'aa@bb.ccc',
'invite_code': 'testcode'
})
with self.assertRaises(PermissionDenied):
response = actions.register(request)
self.assertEqual(models.User.objects.count(), 3)
@ -380,7 +381,7 @@ class ViewActions(TestCase):
def test_untag(self):
''' remove a tag from a book '''
tag = models.Tag.objects.create(name='A Tag!?')
user_tag = models.UserTag.objects.create(
models.UserTag.objects.create(
user=self.local_user, book=self.book, tag=tag)
request = self.factory.post(
'', {

View file

@ -30,7 +30,6 @@ def user_login(request):
''' authenticate user login '''
login_form = forms.LoginForm(request.POST)
print(login_form.data)
localname = login_form.data['localname']
username = '%s@%s' % (localname, DOMAIN)
password = login_form.data['password']
@ -60,6 +59,8 @@ def register(request):
raise PermissionDenied
invite = get_object_or_404(models.SiteInvite, code=invite_code)
if not invite.valid():
raise PermissionDenied
else:
invite = None
@ -74,7 +75,7 @@ def register(request):
# check localname and email uniqueness
if models.User.objects.filter(localname=localname).first():
form.add_error('localname', 'User with this username already exists')
form.errors['localname'] = ['User with this username already exists']
errors = True
if errors: