2016-04-07 05:26:50 +00:00
|
|
|
from django import forms
|
2018-07-07 19:29:44 +00:00
|
|
|
from django.contrib.auth import authenticate
|
2016-04-07 05:26:50 +00:00
|
|
|
from django.core.mail import EmailMultiAlternatives
|
2018-07-07 19:29:44 +00:00
|
|
|
from django.template.loader import render_to_string
|
2016-04-09 18:00:16 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2018-07-07 19:29:44 +00:00
|
|
|
|
2016-06-21 05:10:38 +00:00
|
|
|
from membership.models import CustomUser
|
2018-07-07 19:29:44 +00:00
|
|
|
from .models import ContactMessage, BillingAddress, UserBillingAddress
|
2017-07-16 11:05:55 +00:00
|
|
|
|
|
|
|
|
2016-04-26 06:16:03 +00:00
|
|
|
# from utils.fields import CountryField
|
2016-04-23 07:22:44 +00:00
|
|
|
|
|
|
|
|
Created signup view. Added login after signup.Added signup url to nosystem app urls.py. Added logout view, Added logout button on nabber, Added password reset form, Added password view , Added password reset html, Added password reset email for nosystemd app. Added confirm_reset_password.html, Added confirm_ reset password view, Added confirm reset password form, Fixed reset password token generation, Started donation view, Added donation view, Added donation.html, Added donation form, Adding donation.js lib in order to capture stripe payments for nosystem app.
2016-07-22 06:24:32 +00:00
|
|
|
class SignupFormMixin(forms.ModelForm):
|
|
|
|
confirm_password = forms.CharField(widget=forms.PasswordInput())
|
|
|
|
password = forms.CharField(widget=forms.PasswordInput())
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = CustomUser
|
|
|
|
fields = ['name', 'email', 'password']
|
|
|
|
widgets = {
|
2017-09-24 10:24:38 +00:00
|
|
|
'name': forms.TextInput(
|
|
|
|
attrs={'placeholder': _('Enter your name or company name')}),
|
Created signup view. Added login after signup.Added signup url to nosystem app urls.py. Added logout view, Added logout button on nabber, Added password reset form, Added password view , Added password reset html, Added password reset email for nosystemd app. Added confirm_reset_password.html, Added confirm_ reset password view, Added confirm reset password form, Fixed reset password token generation, Started donation view, Added donation view, Added donation.html, Added donation form, Adding donation.js lib in order to capture stripe payments for nosystem app.
2016-07-22 06:24:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def clean_confirm_password(self):
|
|
|
|
password = self.cleaned_data.get('password')
|
|
|
|
confirm_password = self.cleaned_data.get('confirm_password')
|
|
|
|
if not confirm_password == password:
|
|
|
|
raise forms.ValidationError("Passwords don't match")
|
|
|
|
return confirm_password
|
|
|
|
|
|
|
|
|
2016-07-19 06:07:49 +00:00
|
|
|
class LoginFormMixin(forms.Form):
|
|
|
|
email = forms.CharField(widget=forms.EmailInput())
|
|
|
|
password = forms.CharField(widget=forms.PasswordInput())
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
fields = ['email', 'password']
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
email = self.cleaned_data.get('email')
|
|
|
|
password = self.cleaned_data.get('password')
|
|
|
|
is_auth = authenticate(email=email, password=password)
|
|
|
|
if not is_auth:
|
2017-08-29 12:18:41 +00:00
|
|
|
raise forms.ValidationError(
|
2017-09-24 10:24:38 +00:00
|
|
|
_("Your username and/or password were incorrect."))
|
2016-07-19 06:07:49 +00:00
|
|
|
return self.cleaned_data
|
|
|
|
|
|
|
|
def clean_email(self):
|
|
|
|
email = self.cleaned_data.get('email')
|
|
|
|
try:
|
|
|
|
CustomUser.objects.get(email=email)
|
|
|
|
return email
|
|
|
|
except CustomUser.DoesNotExist:
|
2017-09-24 10:24:38 +00:00
|
|
|
raise forms.ValidationError(_("User does not exist"))
|
|
|
|
|
|
|
|
|
|
|
|
class ResendActivationEmailForm(forms.Form):
|
|
|
|
email = forms.CharField(widget=forms.EmailInput())
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
fields = ['email']
|
|
|
|
|
|
|
|
def clean_email(self):
|
|
|
|
email = self.cleaned_data.get('email')
|
|
|
|
try:
|
|
|
|
c = CustomUser.objects.get(email=email)
|
|
|
|
if c.validated == 1:
|
2018-07-07 19:30:40 +00:00
|
|
|
raise forms.ValidationError(
|
|
|
|
_("The account is already active."))
|
2017-09-24 10:24:38 +00:00
|
|
|
return email
|
|
|
|
except CustomUser.DoesNotExist:
|
|
|
|
raise forms.ValidationError(_("User does not exist"))
|
2016-07-19 06:07:49 +00:00
|
|
|
|
|
|
|
|
2016-06-21 05:10:38 +00:00
|
|
|
class PasswordResetRequestForm(forms.Form):
|
|
|
|
email = forms.CharField(widget=forms.EmailInput())
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
fields = ['email']
|
|
|
|
|
|
|
|
def clean_email(self):
|
|
|
|
email = self.cleaned_data.get('email')
|
|
|
|
try:
|
|
|
|
CustomUser.objects.get(email=email)
|
|
|
|
return email
|
|
|
|
except CustomUser.DoesNotExist:
|
2017-09-24 10:24:38 +00:00
|
|
|
raise forms.ValidationError(_("User does not exist"))
|
2016-06-21 05:10:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SetPasswordForm(forms.Form):
|
|
|
|
"""
|
|
|
|
A form that lets a user change set their password without entering the old
|
|
|
|
password
|
|
|
|
"""
|
|
|
|
error_messages = {
|
2017-09-24 10:24:38 +00:00
|
|
|
'password_mismatch': _("The two password fields didn't match."),
|
2016-06-21 05:10:38 +00:00
|
|
|
}
|
2017-09-24 10:24:38 +00:00
|
|
|
new_password1 = forms.CharField(label=_("New password"),
|
2016-06-21 05:10:38 +00:00
|
|
|
widget=forms.PasswordInput)
|
2017-09-24 10:24:38 +00:00
|
|
|
new_password2 = forms.CharField(label=_("New password confirmation"),
|
2016-06-21 05:10:38 +00:00
|
|
|
widget=forms.PasswordInput)
|
|
|
|
|
|
|
|
def clean_new_password2(self):
|
|
|
|
password1 = self.cleaned_data.get('new_password1')
|
|
|
|
password2 = self.cleaned_data.get('new_password2')
|
|
|
|
if password1 and password2:
|
|
|
|
if password1 != password2:
|
|
|
|
raise forms.ValidationError(
|
|
|
|
self.error_messages['password_mismatch'],
|
2017-07-16 11:05:55 +00:00
|
|
|
code='password_mismatch', )
|
2016-06-21 05:10:38 +00:00
|
|
|
return password2
|
|
|
|
|
|
|
|
|
2017-04-23 21:31:05 +00:00
|
|
|
class EditCreditCardForm(forms.Form):
|
|
|
|
token = forms.CharField(widget=forms.HiddenInput())
|
|
|
|
|
|
|
|
|
2016-04-26 06:16:03 +00:00
|
|
|
class BillingAddressForm(forms.ModelForm):
|
2017-05-11 05:11:33 +00:00
|
|
|
token = forms.CharField(widget=forms.HiddenInput(), required=False)
|
2017-10-26 22:43:07 +00:00
|
|
|
card = forms.CharField(widget=forms.HiddenInput(), required=False)
|
2016-04-23 07:22:44 +00:00
|
|
|
|
|
|
|
class Meta:
|
2016-04-26 06:16:03 +00:00
|
|
|
model = BillingAddress
|
2017-08-29 12:18:41 +00:00
|
|
|
fields = ['cardholder_name', 'street_address',
|
2019-12-17 16:05:02 +00:00
|
|
|
'city', 'postal_code', 'country', 'vat_number']
|
2016-04-23 07:22:44 +00:00
|
|
|
labels = {
|
2017-07-15 22:09:37 +00:00
|
|
|
'cardholder_name': _('Cardholder Name'),
|
2016-04-23 07:22:44 +00:00
|
|
|
'street_address': _('Street Address'),
|
|
|
|
'city': _('City'),
|
|
|
|
'postal_code': _('Postal Code'),
|
|
|
|
'Country': _('Country'),
|
2019-12-17 16:05:02 +00:00
|
|
|
'VAT Number': _('VAT Number')
|
2016-04-23 07:22:44 +00:00
|
|
|
}
|
2016-04-07 05:26:50 +00:00
|
|
|
|
|
|
|
|
2017-09-08 18:16:29 +00:00
|
|
|
class BillingAddressFormSignup(BillingAddressForm):
|
|
|
|
name = forms.CharField(label=_('Name'))
|
|
|
|
email = forms.EmailField(label=_('Email Address'))
|
|
|
|
field_order = ['name', 'email']
|
|
|
|
|
2018-07-05 08:00:12 +00:00
|
|
|
class Meta:
|
|
|
|
model = BillingAddress
|
|
|
|
fields = ['name', 'email', 'cardholder_name', 'street_address',
|
2019-12-17 16:05:02 +00:00
|
|
|
'city', 'postal_code', 'country', 'vat_number']
|
2018-07-05 08:00:12 +00:00
|
|
|
labels = {
|
|
|
|
'name': 'Name',
|
|
|
|
'email': _('Email'),
|
|
|
|
'cardholder_name': _('Cardholder Name'),
|
|
|
|
'street_address': _('Street Address'),
|
|
|
|
'city': _('City'),
|
|
|
|
'postal_code': _('Postal Code'),
|
|
|
|
'Country': _('Country'),
|
2019-12-17 16:05:02 +00:00
|
|
|
'vat_number': _('VAT Number')
|
2018-07-05 08:00:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def clean_email(self):
|
|
|
|
email = self.cleaned_data.get('email')
|
|
|
|
try:
|
|
|
|
CustomUser.objects.get(email=email)
|
|
|
|
raise forms.ValidationError(
|
2018-07-07 19:30:40 +00:00
|
|
|
_("The email %(email)s is already registered with us. "
|
|
|
|
"Please reset your password and access your account.") %
|
|
|
|
{'email': email}
|
2018-07-05 08:00:12 +00:00
|
|
|
)
|
|
|
|
except CustomUser.DoesNotExist:
|
|
|
|
return email
|
|
|
|
|
2017-09-08 18:16:29 +00:00
|
|
|
|
2016-10-14 04:33:48 +00:00
|
|
|
class UserBillingAddressForm(forms.ModelForm):
|
|
|
|
user = forms.ModelChoiceField(queryset=CustomUser.objects.all(),
|
2017-06-29 14:34:40 +00:00
|
|
|
widget=forms.HiddenInput())
|
|
|
|
|
2016-10-14 04:33:48 +00:00
|
|
|
class Meta:
|
|
|
|
model = UserBillingAddress
|
2017-08-29 12:18:41 +00:00
|
|
|
fields = ['cardholder_name', 'street_address',
|
|
|
|
'city', 'postal_code', 'country', 'user']
|
2016-10-14 04:33:48 +00:00
|
|
|
labels = {
|
2017-08-29 12:18:41 +00:00
|
|
|
'cardholder_name': _('Cardholder Name'),
|
2016-10-28 16:25:09 +00:00
|
|
|
'street_address': _('Street Building'),
|
2016-10-14 04:33:48 +00:00
|
|
|
'city': _('City'),
|
|
|
|
'postal_code': _('Postal Code'),
|
|
|
|
'Country': _('Country'),
|
2019-12-21 04:35:58 +00:00
|
|
|
'vat_number': _('VAT Number'),
|
2016-10-14 04:33:48 +00:00
|
|
|
}
|
|
|
|
|
2017-06-29 14:34:40 +00:00
|
|
|
|
2016-04-07 05:26:50 +00:00
|
|
|
class ContactUsForm(forms.ModelForm):
|
|
|
|
error_css_class = 'autofocus'
|
|
|
|
|
|
|
|
class Meta:
|
2016-04-10 21:12:43 +00:00
|
|
|
model = ContactMessage
|
2016-04-07 05:26:50 +00:00
|
|
|
fields = ['name', 'email', 'phone_number', 'message']
|
|
|
|
widgets = {
|
|
|
|
'name': forms.TextInput(attrs={'class': u'form-control'}),
|
|
|
|
'email': forms.TextInput(attrs={'class': u'form-control'}),
|
|
|
|
'phone_number': forms.TextInput(attrs={'class': u'form-control'}),
|
|
|
|
'message': forms.Textarea(attrs={'class': u'form-control'}),
|
|
|
|
}
|
2016-04-09 18:00:16 +00:00
|
|
|
labels = {
|
|
|
|
'name': _('Name'),
|
|
|
|
'email': _('Email'),
|
|
|
|
'phone_number': _('Phone number'),
|
|
|
|
'message': _('Message'),
|
|
|
|
}
|
2016-04-07 05:26:50 +00:00
|
|
|
|
2017-04-23 21:31:05 +00:00
|
|
|
def send_email(self, email_to='info@digitalglarus.ch'):
|
2017-08-29 12:18:41 +00:00
|
|
|
text_content = render_to_string(
|
|
|
|
'emails/contact.txt', {'data': self.cleaned_data})
|
|
|
|
html_content = render_to_string(
|
|
|
|
'emails/contact.html', {'data': self.cleaned_data})
|
2016-04-07 05:26:50 +00:00
|
|
|
email = EmailMultiAlternatives('Subject', text_content)
|
|
|
|
email.attach_alternative(html_content, "text/html")
|
2017-04-23 21:31:05 +00:00
|
|
|
email.to = [email_to]
|
2016-04-07 05:26:50 +00:00
|
|
|
email.send()
|