mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-18 13:15:31 +00:00
Fixes checking invite validity
This commit is contained in:
parent
81e60cea16
commit
9102d81767
2 changed files with 7 additions and 5 deletions
|
@ -173,7 +173,7 @@ class ViewActions(TestCase):
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 302)
|
||||||
self.assertEqual(models.SiteInvite.objects.get().times_used, 1)
|
self.assertEqual(models.SiteInvite.objects.get().times_used, 1)
|
||||||
|
|
||||||
# invalid invite
|
# invite already used to max capacity
|
||||||
request = self.factory.post(
|
request = self.factory.post(
|
||||||
'register/',
|
'register/',
|
||||||
{
|
{
|
||||||
|
@ -182,7 +182,8 @@ class ViewActions(TestCase):
|
||||||
'email': 'aa@bb.ccc',
|
'email': 'aa@bb.ccc',
|
||||||
'invite_code': 'testcode'
|
'invite_code': 'testcode'
|
||||||
})
|
})
|
||||||
response = actions.register(request)
|
with self.assertRaises(PermissionDenied):
|
||||||
|
response = actions.register(request)
|
||||||
self.assertEqual(models.User.objects.count(), 3)
|
self.assertEqual(models.User.objects.count(), 3)
|
||||||
|
|
||||||
# bad invite code
|
# bad invite code
|
||||||
|
@ -380,7 +381,7 @@ class ViewActions(TestCase):
|
||||||
def test_untag(self):
|
def test_untag(self):
|
||||||
''' remove a tag from a book '''
|
''' remove a tag from a book '''
|
||||||
tag = models.Tag.objects.create(name='A Tag!?')
|
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)
|
user=self.local_user, book=self.book, tag=tag)
|
||||||
request = self.factory.post(
|
request = self.factory.post(
|
||||||
'', {
|
'', {
|
||||||
|
|
|
@ -30,7 +30,6 @@ def user_login(request):
|
||||||
''' authenticate user login '''
|
''' authenticate user login '''
|
||||||
login_form = forms.LoginForm(request.POST)
|
login_form = forms.LoginForm(request.POST)
|
||||||
|
|
||||||
print(login_form.data)
|
|
||||||
localname = login_form.data['localname']
|
localname = login_form.data['localname']
|
||||||
username = '%s@%s' % (localname, DOMAIN)
|
username = '%s@%s' % (localname, DOMAIN)
|
||||||
password = login_form.data['password']
|
password = login_form.data['password']
|
||||||
|
@ -60,6 +59,8 @@ def register(request):
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
|
|
||||||
invite = get_object_or_404(models.SiteInvite, code=invite_code)
|
invite = get_object_or_404(models.SiteInvite, code=invite_code)
|
||||||
|
if not invite.valid():
|
||||||
|
raise PermissionDenied
|
||||||
else:
|
else:
|
||||||
invite = None
|
invite = None
|
||||||
|
|
||||||
|
@ -74,7 +75,7 @@ def register(request):
|
||||||
|
|
||||||
# check localname and email uniqueness
|
# check localname and email uniqueness
|
||||||
if models.User.objects.filter(localname=localname).first():
|
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
|
errors = True
|
||||||
|
|
||||||
if errors:
|
if errors:
|
||||||
|
|
Loading…
Reference in a new issue