split signup forms working again
This commit is contained in:
@ -70,21 +70,6 @@ class UserPreferenceForm(forms.ModelForm):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class AllAuthSignupForm(forms.Form):
|
|
||||||
captcha = hCaptchaField()
|
|
||||||
terms = forms.BooleanField(label=_('Accept Terms and Privacy'))
|
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
|
||||||
super(AllAuthSignupForm, self).__init__(**kwargs)
|
|
||||||
if settings.PRIVACY_URL == '' and settings.TERMS_URL == '':
|
|
||||||
self.fields.pop('terms')
|
|
||||||
if settings.HCAPTCHA_SECRET == '':
|
|
||||||
self.fields.pop('captcha')
|
|
||||||
|
|
||||||
def signup(self, request, user):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class UserNameForm(forms.ModelForm):
|
class UserNameForm(forms.ModelForm):
|
||||||
prefix = 'name'
|
prefix = 'name'
|
||||||
|
|
||||||
@ -464,6 +449,21 @@ class SpaceJoinForm(forms.Form):
|
|||||||
token = forms.CharField()
|
token = forms.CharField()
|
||||||
|
|
||||||
|
|
||||||
|
class AllAuthSignupForm(forms.Form):
|
||||||
|
captcha = hCaptchaField()
|
||||||
|
terms = forms.BooleanField(label=_('Accept Terms and Privacy'))
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super(AllAuthSignupForm, self).__init__(**kwargs)
|
||||||
|
if settings.PRIVACY_URL == '' and settings.TERMS_URL == '':
|
||||||
|
self.fields.pop('terms')
|
||||||
|
if settings.HCAPTCHA_SECRET == '':
|
||||||
|
self.fields.pop('captcha')
|
||||||
|
|
||||||
|
def signup(self, request, user):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class UserCreateForm(forms.Form):
|
class UserCreateForm(forms.Form):
|
||||||
name = forms.CharField(label='Username')
|
name = forms.CharField(label='Username')
|
||||||
password = forms.CharField(
|
password = forms.CharField(
|
||||||
|
@ -141,17 +141,17 @@ class ShoppingListTable(tables.Table):
|
|||||||
|
|
||||||
class InviteLinkTable(tables.Table):
|
class InviteLinkTable(tables.Table):
|
||||||
link = tables.TemplateColumn(
|
link = tables.TemplateColumn(
|
||||||
"<a href='{% url 'view_signup' record.uuid %}' >" + _('Link') + "</a>"
|
"<input value='{{ request.scheme }}://{{ request.get_host }}{% url 'view_signup' record.uuid %}' class='form-control' />"
|
||||||
|
)
|
||||||
|
delete_link = tables.TemplateColumn(
|
||||||
|
"<a href='{% url 'delete_invite_link' record.pk %}' >" + _('Delete') + "</a>", verbose_name=_('Delete')
|
||||||
)
|
)
|
||||||
# delete = tables.TemplateColumn(
|
|
||||||
# "<a href='{% url 'delete_invite_link' record.pk %}' >" + _('Delete') + "</a>"
|
|
||||||
# )
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = InviteLink
|
model = InviteLink
|
||||||
template_name = 'generic/table_template.html'
|
template_name = 'generic/table_template.html'
|
||||||
fields = (
|
fields = (
|
||||||
'username', 'group', 'valid_until', 'created_by', 'created_at'
|
'username', 'group', 'valid_until',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
{% load django_tables2 %}
|
||||||
{% load crispy_forms_filters %}
|
{% load crispy_forms_filters %}
|
||||||
{% load static %}
|
{% load static %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
@ -90,18 +91,19 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if u.user != request.user %}
|
{% if u.user != request.user %}
|
||||||
<div class="input-group mb-3">
|
<div class="input-group mb-3">
|
||||||
<select v-model="users['{{ u.pk }}']" class="custom-select form-control" style="height: 44px">
|
<select v-model="users['{{ u.pk }}']" class="custom-select form-control"
|
||||||
<option>{% trans 'admin' %}</option>
|
style="height: 44px">
|
||||||
<option>{% trans 'user' %}</option>
|
<option>{% trans 'admin' %}</option>
|
||||||
<option>{% trans 'guest' %}</option>
|
<option>{% trans 'user' %}</option>
|
||||||
<option>{% trans 'remove' %}</option>
|
<option>{% trans 'guest' %}</option>
|
||||||
</select>
|
<option>{% trans 'remove' %}</option>
|
||||||
<span class="input-group-append">
|
</select>
|
||||||
|
<span class="input-group-append">
|
||||||
<a class="btn btn-warning"
|
<a class="btn btn-warning"
|
||||||
:href="editUserUrl({{ u.pk }}, {{ u.space.pk }})" >{% trans 'Update' %}</a>
|
:href="editUserUrl({{ u.pk }}, {{ u.space.pk }})">{% trans 'Update' %}</a>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
{% trans 'You cannot edit yourself.' %}
|
{% trans 'You cannot edit yourself.' %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -115,6 +117,17 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col col-md-12">
|
||||||
|
<h4>{% trans 'Invite Links' %}</h4>
|
||||||
|
{% render_table invite_links %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block script %}
|
{% block script %}
|
||||||
|
@ -245,7 +245,7 @@ class InviteLinkCreate(GroupRequiredMixin, CreateView):
|
|||||||
except (SMTPException, BadHeaderError, TimeoutError):
|
except (SMTPException, BadHeaderError, TimeoutError):
|
||||||
messages.add_message(self.request, messages.ERROR, _('Email to user could not be send, please share link manually.'))
|
messages.add_message(self.request, messages.ERROR, _('Email to user could not be send, please share link manually.'))
|
||||||
|
|
||||||
return HttpResponseRedirect(reverse('index'))
|
return HttpResponseRedirect(reverse('view_space'))
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(InviteLinkCreate, self).get_context_data(**kwargs)
|
context = super(InviteLinkCreate, self).get_context_data(**kwargs)
|
||||||
|
@ -3,6 +3,7 @@ import re
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
|
from allauth.account.forms import SignupForm
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth import update_session_auth_hash
|
from django.contrib.auth import update_session_auth_hash
|
||||||
@ -25,13 +26,13 @@ from rest_framework.authtoken.models import Token
|
|||||||
from cookbook.filters import RecipeFilter
|
from cookbook.filters import RecipeFilter
|
||||||
from cookbook.forms import (CommentForm, Recipe, RecipeBookEntryForm, User,
|
from cookbook.forms import (CommentForm, Recipe, RecipeBookEntryForm, User,
|
||||||
UserCreateForm, UserNameForm, UserPreference,
|
UserCreateForm, UserNameForm, UserPreference,
|
||||||
UserPreferenceForm, SpaceJoinForm, SpaceCreateForm)
|
UserPreferenceForm, SpaceJoinForm, SpaceCreateForm, AllAuthSignupForm)
|
||||||
from cookbook.helper.permission_helper import group_required, share_link_valid, has_group_permission
|
from cookbook.helper.permission_helper import group_required, share_link_valid, has_group_permission
|
||||||
from cookbook.models import (Comment, CookLog, InviteLink, MealPlan,
|
from cookbook.models import (Comment, CookLog, InviteLink, MealPlan,
|
||||||
RecipeBook, RecipeBookEntry, ViewLog, ShoppingList, Space, Keyword, RecipeImport, Unit,
|
RecipeBook, RecipeBookEntry, ViewLog, ShoppingList, Space, Keyword, RecipeImport, Unit,
|
||||||
Food)
|
Food)
|
||||||
from cookbook.tables import (CookLogTable, RecipeTable, RecipeTableSmall,
|
from cookbook.tables import (CookLogTable, RecipeTable, RecipeTableSmall,
|
||||||
ViewLogTable)
|
ViewLogTable, InviteLinkTable)
|
||||||
from cookbook.views.data import Object
|
from cookbook.views.data import Object
|
||||||
from recipes.version import BUILD_REF, VERSION_NUMBER
|
from recipes.version import BUILD_REF, VERSION_NUMBER
|
||||||
|
|
||||||
@ -444,23 +445,23 @@ def signup(request, token):
|
|||||||
messages.add_message(request, messages.SUCCESS, _('Successfully joined space.'))
|
messages.add_message(request, messages.SUCCESS, _('Successfully joined space.'))
|
||||||
return HttpResponseRedirect(reverse('index'))
|
return HttpResponseRedirect(reverse('index'))
|
||||||
else:
|
else:
|
||||||
request.session['signup_token'] = token
|
request.session['signup_token'] = str(token)
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
updated_request = request.POST.copy()
|
updated_request = request.POST.copy()
|
||||||
if link.username != '':
|
if link.username != '':
|
||||||
updated_request.update({'name': link.username})
|
updated_request.update({'username': link.username})
|
||||||
|
|
||||||
form = UserCreateForm(updated_request)
|
form = SignupForm(data=updated_request)
|
||||||
|
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
if form.cleaned_data['password'] != form.cleaned_data['password_confirm']: # noqa: E501
|
if form.cleaned_data['password1'] != form.cleaned_data['password_confirm']: # noqa: E501
|
||||||
form.add_error('password', _('Passwords dont match!'))
|
form.add_error('password1', _('Passwords dont match!'))
|
||||||
else:
|
else:
|
||||||
user = User(username=form.cleaned_data['name'], )
|
user = User(username=form.cleaned_data['username'], )
|
||||||
try:
|
try:
|
||||||
validate_password(form.cleaned_data['password'], user=user)
|
validate_password(form.cleaned_data['password1'], user=user)
|
||||||
user.set_password(form.cleaned_data['password'])
|
user.set_password(form.cleaned_data['password1'])
|
||||||
user.save()
|
user.save()
|
||||||
messages.add_message(request, messages.SUCCESS, _('User has been created, please login!'))
|
messages.add_message(request, messages.SUCCESS, _('User has been created, please login!'))
|
||||||
|
|
||||||
@ -477,7 +478,7 @@ def signup(request, token):
|
|||||||
for m in e:
|
for m in e:
|
||||||
form.add_error('password', m)
|
form.add_error('password', m)
|
||||||
else:
|
else:
|
||||||
form = UserCreateForm()
|
form = SignupForm()
|
||||||
|
|
||||||
if link.username != '':
|
if link.username != '':
|
||||||
form.fields['name'].initial = link.username
|
form.fields['name'].initial = link.username
|
||||||
@ -505,7 +506,10 @@ def space(request):
|
|||||||
|
|
||||||
counts.recipes_no_keyword = Recipe.objects.filter(keywords=None, space=request.space).count()
|
counts.recipes_no_keyword = Recipe.objects.filter(keywords=None, space=request.space).count()
|
||||||
|
|
||||||
return render(request, 'space.html', {'space_users': space_users, 'counts': counts})
|
invite_links = InviteLinkTable(InviteLink.objects.filter(valid_until__gte=datetime.today(), used_by=None, space=request.space).all())
|
||||||
|
RequestConfig(request, paginate={'per_page': 25}).configure(invite_links)
|
||||||
|
|
||||||
|
return render(request, 'space.html', {'space_users': space_users, 'counts': counts, 'invite_links': invite_links})
|
||||||
|
|
||||||
|
|
||||||
# TODO super hacky and quick solution, safe but needs rework
|
# TODO super hacky and quick solution, safe but needs rework
|
||||||
|
Reference in New Issue
Block a user