2016-04-07 05:26:50 +00:00
|
|
|
from django import forms
|
2016-10-14 04:33:48 +00:00
|
|
|
from .models import ContactMessage, BillingAddress, UserBillingAddress
|
2016-04-07 05:26:50 +00:00
|
|
|
from django.template.loader import render_to_string
|
|
|
|
from django.core.mail import EmailMultiAlternatives
|
2016-04-09 18:00:16 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2016-07-19 06:07:49 +00:00
|
|
|
from django.contrib.auth import authenticate
|
2016-06-21 05:10:38 +00:00
|
|
|
from membership.models import CustomUser
|
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 = {
|
|
|
|
'name': forms.TextInput(attrs={'placeholder': 'Enter your name or company name'}),
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
|
|
|
raise forms.ValidationError("Your username and/or password were incorrect.")
|
|
|
|
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:
|
|
|
|
raise forms.ValidationError("User does not exist")
|
|
|
|
else:
|
|
|
|
return email
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
raise forms.ValidationError("User does not exist")
|
|
|
|
else:
|
|
|
|
return email
|
|
|
|
|
|
|
|
|
|
|
|
class SetPasswordForm(forms.Form):
|
|
|
|
"""
|
|
|
|
A form that lets a user change set their password without entering the old
|
|
|
|
password
|
|
|
|
"""
|
|
|
|
error_messages = {
|
|
|
|
'password_mismatch': ("The two password fields didn't match."),
|
|
|
|
}
|
|
|
|
new_password1 = forms.CharField(label=("New password"),
|
|
|
|
widget=forms.PasswordInput)
|
|
|
|
new_password2 = forms.CharField(label=("New password confirmation"),
|
|
|
|
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'],
|
|
|
|
code='password_mismatch',)
|
|
|
|
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)
|
2016-04-23 07:22:44 +00:00
|
|
|
|
|
|
|
class Meta:
|
2016-04-26 06:16:03 +00:00
|
|
|
model = BillingAddress
|
|
|
|
fields = ['street_address', 'city', 'postal_code', 'country']
|
2016-04-23 07:22:44 +00:00
|
|
|
labels = {
|
|
|
|
'street_address': _('Street Address'),
|
|
|
|
'city': _('City'),
|
|
|
|
'postal_code': _('Postal Code'),
|
|
|
|
'Country': _('Country'),
|
|
|
|
}
|
2016-04-07 05:26:50 +00:00
|
|
|
|
|
|
|
|
2016-10-14 04:33:48 +00:00
|
|
|
class UserBillingAddressForm(forms.ModelForm):
|
|
|
|
user = forms.ModelChoiceField(queryset=CustomUser.objects.all(),
|
|
|
|
widget=forms.HiddenInput())
|
|
|
|
class Meta:
|
|
|
|
model = UserBillingAddress
|
|
|
|
fields = ['street_address', 'city', 'postal_code', 'country', 'user']
|
|
|
|
labels = {
|
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'),
|
|
|
|
}
|
|
|
|
|
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'):
|
2016-04-07 05:26:50 +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})
|
|
|
|
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()
|