2016-07-29 05:17:34 +00:00
|
|
|
from django.views.generic import TemplateView, CreateView, FormView, DetailView, UpdateView,\
|
|
|
|
ListView
|
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
|
|
|
from django.http import HttpResponseRedirect
|
2016-07-27 05:08:45 +00:00
|
|
|
from django.shortcuts import render
|
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
|
|
|
from django.core.urlresolvers import reverse_lazy, reverse
|
|
|
|
from django.contrib.auth import authenticate, login
|
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
|
|
from django.conf import settings
|
2016-07-27 05:08:45 +00:00
|
|
|
from django.contrib import messages
|
2016-07-19 06:07:49 +00:00
|
|
|
|
2016-07-27 05:08:45 +00:00
|
|
|
|
|
|
|
from membership.models import CustomUser, StripeCustomer
|
|
|
|
from utils.stripe_utils import StripeUtils
|
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
|
|
|
from utils.views import PasswordResetViewMixin, PasswordResetConfirmViewMixin
|
2016-07-27 05:08:45 +00:00
|
|
|
from utils.forms import PasswordResetRequestForm
|
2016-07-29 05:17:34 +00:00
|
|
|
from utils.mailer import BaseEmail
|
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
|
|
|
|
2016-07-27 05:08:45 +00:00
|
|
|
from .forms import LoginForm, SignupForm, DonationForm, DonationBillingForm
|
|
|
|
from .models import Donation, DonatorStatus
|
2016-07-19 06:07:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LandingView(TemplateView):
|
|
|
|
template_name = "nosystemd/landing.html"
|
|
|
|
|
2016-07-29 05:17:34 +00:00
|
|
|
def get_context_data(self, *args, **kwargs):
|
2016-07-31 23:58:43 +00:00
|
|
|
|
|
|
|
allow_donation = self.request.user.is_anonymous() or \
|
|
|
|
(self.request.user.is_authenticated() and
|
|
|
|
not DonatorStatus.objects.filter(user=self.request.user).exists())
|
|
|
|
|
2016-07-29 05:17:34 +00:00
|
|
|
total_donations_amount = Donation.get_total_donations_amount()
|
|
|
|
context = {
|
2016-07-31 23:58:43 +00:00
|
|
|
'total_donations_amount': total_donations_amount,
|
|
|
|
'allow_donation': allow_donation
|
2016-07-29 05:17:34 +00:00
|
|
|
}
|
|
|
|
return context
|
|
|
|
|
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
|
|
|
|
2016-07-19 06:07:49 +00:00
|
|
|
class LoginView(FormView):
|
|
|
|
template_name = "nosystemd/login.html"
|
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
|
|
|
form_class = LoginForm
|
|
|
|
success_url = reverse_lazy('nosystemd:landing')
|
|
|
|
|
2016-07-29 05:17:34 +00:00
|
|
|
def get_success_url(self):
|
|
|
|
next_url = self.request.session.get('next', self.success_url)
|
|
|
|
return next_url
|
|
|
|
|
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 form_valid(self, form):
|
|
|
|
email = form.cleaned_data.get('email')
|
|
|
|
password = form.cleaned_data.get('password')
|
|
|
|
auth_user = authenticate(email=email, password=password)
|
|
|
|
|
|
|
|
if auth_user:
|
|
|
|
login(self.request, auth_user)
|
|
|
|
return HttpResponseRedirect(self.get_success_url())
|
|
|
|
|
|
|
|
return HttpResponseRedirect(self.get_success_url())
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
2016-07-29 05:17:34 +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
|
|
|
if self.request.user.is_authenticated():
|
|
|
|
return HttpResponseRedirect(reverse('nosystemd:landing'))
|
2016-07-29 05:17:34 +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
|
|
|
return super(LoginView, self).get(request, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class SignupView(CreateView):
|
|
|
|
template_name = 'nosystemd/signup.html'
|
|
|
|
model = CustomUser
|
|
|
|
form_class = SignupForm
|
|
|
|
|
|
|
|
def get_success_url(self):
|
2016-07-29 05:17:34 +00:00
|
|
|
next_url = self.request.POST.get('next', reverse('nosystemd:login'))
|
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
|
|
|
return next_url
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
name = form.cleaned_data.get('name')
|
|
|
|
email = form.cleaned_data.get('email')
|
|
|
|
password = form.cleaned_data.get('password')
|
|
|
|
|
|
|
|
CustomUser.register(name, password, email)
|
|
|
|
auth_user = authenticate(email=email, password=password)
|
|
|
|
login(self.request, auth_user)
|
|
|
|
|
|
|
|
return HttpResponseRedirect(self.get_success_url())
|
|
|
|
|
|
|
|
|
|
|
|
class PasswordResetView(PasswordResetViewMixin):
|
|
|
|
template_name = 'nosystemd/reset_password.html'
|
|
|
|
success_url = reverse_lazy('nosystemd:login')
|
|
|
|
form_class = PasswordResetRequestForm
|
|
|
|
template_email_path = 'nosystemd/emails/'
|
|
|
|
|
|
|
|
|
|
|
|
class PasswordResetConfirmView(PasswordResetConfirmViewMixin):
|
|
|
|
template_name = 'nosystemd/confirm_reset_password.html'
|
|
|
|
success_url = reverse_lazy('nosystemd:login')
|
|
|
|
|
|
|
|
|
|
|
|
class DonationView(LoginRequiredMixin, FormView):
|
|
|
|
template_name = 'nosystemd/donation.html'
|
2016-07-27 05:08:45 +00:00
|
|
|
form_class = DonationBillingForm
|
2016-07-29 05:17:34 +00:00
|
|
|
success_url = reverse_lazy('nosystemd:make_donation')
|
|
|
|
|
|
|
|
def get_login_url(self):
|
|
|
|
return "%s?next=%s" % (reverse('nosystemd:signup'),
|
|
|
|
reverse('nosystemd:make_donation'))
|
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 get_context_data(self, **kwargs):
|
|
|
|
context = super(DonationView, self).get_context_data(**kwargs)
|
|
|
|
context.update({
|
|
|
|
'stripe_key': settings.STRIPE_API_PUBLIC_KEY
|
|
|
|
})
|
|
|
|
|
|
|
|
return context
|
|
|
|
|
2016-07-29 05:17:34 +00:00
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
|
2016-08-05 06:00:44 +00:00
|
|
|
# if DonatorStatus.objects.filter(user=self.request.user).exists():
|
|
|
|
# messages.success(self.request, 'Your already are a monthly contributor')
|
|
|
|
# return HttpResponseRedirect(reverse_lazy('nosystemd:donations'))
|
2016-07-29 05:17:34 +00:00
|
|
|
|
|
|
|
return self.render_to_response(self.get_context_data())
|
|
|
|
|
2016-07-27 05:08:45 +00:00
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
|
form = self.get_form()
|
|
|
|
|
|
|
|
if form.is_valid():
|
|
|
|
context = self.get_context_data()
|
|
|
|
token = form.cleaned_data.get('token')
|
|
|
|
donation_amount = form.cleaned_data.get('donation_amount')
|
|
|
|
|
|
|
|
# Get or create stripe customer
|
|
|
|
customer = StripeCustomer.get_or_create(email=self.request.user.email,
|
|
|
|
token=token)
|
|
|
|
if not customer:
|
|
|
|
form.add_error("__all__", "Invalid credit card")
|
|
|
|
return self.render_to_response(self.get_context_data(form=form))
|
|
|
|
|
|
|
|
# Create Billing Address
|
|
|
|
billing_address = form.save()
|
|
|
|
|
|
|
|
# Make stripe charge to a customer
|
|
|
|
stripe_utils = StripeUtils()
|
|
|
|
stripe_utils.CURRENCY = 'usd'
|
|
|
|
charge_response = stripe_utils.make_charge(amount=donation_amount,
|
|
|
|
customer=customer.stripe_id)
|
|
|
|
charge = charge_response.get('response_object')
|
|
|
|
|
|
|
|
# Check if the payment was approved
|
|
|
|
if not charge:
|
|
|
|
context.update({
|
|
|
|
'paymentError': charge_response.get('error'),
|
|
|
|
'form': form
|
|
|
|
})
|
|
|
|
return render(request, self.template_name, context)
|
|
|
|
|
|
|
|
# Create a donation
|
|
|
|
charge = charge_response.get('response_object')
|
|
|
|
donation_data = request.POST.copy()
|
|
|
|
donation_data.update({
|
|
|
|
'cc_brand': charge.source.brand,
|
|
|
|
'stripe_charge_id': charge.id,
|
|
|
|
'last4': charge.source.last4,
|
|
|
|
'billing_address': billing_address.id,
|
|
|
|
'donator': customer.id,
|
|
|
|
'donation': donation_amount
|
|
|
|
})
|
|
|
|
donation_form = DonationForm(donation_data)
|
|
|
|
if donation_form.is_valid():
|
2016-08-05 06:00:44 +00:00
|
|
|
|
|
|
|
# reactivate donation status
|
|
|
|
donation = donation_form.save()
|
|
|
|
|
|
|
|
try:
|
|
|
|
donator_status = DonatorStatus.objects.get(user=self.request.user)
|
|
|
|
donator_status.set_active()
|
|
|
|
except DonatorStatus.DoesNotExist:
|
|
|
|
pass
|
|
|
|
|
2016-07-27 05:08:45 +00:00
|
|
|
donation = donation_form.save()
|
2016-07-29 05:17:34 +00:00
|
|
|
|
|
|
|
context = {
|
|
|
|
'donation': donation,
|
|
|
|
'base_url': "{0}://{1}".format(request.scheme, request.get_host())
|
|
|
|
|
|
|
|
}
|
|
|
|
email_data = {
|
|
|
|
'subject': 'Your donation have been charged',
|
|
|
|
'to': request.user.email,
|
|
|
|
'context': context,
|
|
|
|
'template_name': 'donation_charge',
|
|
|
|
'template_path': 'nosystemd/emails/'
|
|
|
|
}
|
|
|
|
email = BaseEmail(**email_data)
|
|
|
|
email.send()
|
|
|
|
|
2016-07-27 05:08:45 +00:00
|
|
|
return HttpResponseRedirect(reverse('nosystemd:donations',
|
|
|
|
kwargs={'pk': donation.id}))
|
|
|
|
else:
|
|
|
|
self.form_invalid(donation_form)
|
|
|
|
|
|
|
|
else:
|
|
|
|
return self.form_invalid(form)
|
|
|
|
|
|
|
|
|
|
|
|
class DonationDetailView(LoginRequiredMixin, DetailView):
|
|
|
|
template_name = "nosystemd/donation_detail.html"
|
|
|
|
context_object_name = "donation"
|
|
|
|
login_url = reverse_lazy('nosystemd:login')
|
|
|
|
model = Donation
|
|
|
|
|
|
|
|
|
2016-07-29 05:17:34 +00:00
|
|
|
class DonationListView(LoginRequiredMixin, ListView):
|
|
|
|
template_name = "nosystemd/donations.html"
|
|
|
|
context_object_name = "donations"
|
|
|
|
login_url = reverse_lazy('nosystemd:login')
|
|
|
|
model = Donation
|
2016-07-31 23:58:43 +00:00
|
|
|
paginate_by = 10
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(DonationListView, self).get_context_data(**kwargs)
|
|
|
|
|
|
|
|
status = None
|
|
|
|
try:
|
|
|
|
status = self.request.user.donatorstatus
|
|
|
|
except DonatorStatus.DoesNotExist:
|
|
|
|
pass
|
|
|
|
|
|
|
|
context.update({
|
|
|
|
'donator_status': status
|
|
|
|
})
|
|
|
|
return context
|
2016-07-29 05:17:34 +00:00
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
queryset = super(DonationListView, self).get_queryset()
|
|
|
|
queryset = queryset.filter(donator__user=self.request.user)
|
|
|
|
return queryset
|
|
|
|
|
|
|
|
|
2016-07-27 05:08:45 +00:00
|
|
|
class DonatorStatusDetailView(LoginRequiredMixin, TemplateView):
|
|
|
|
template_name = "nosystemd/donator_status.html"
|
|
|
|
login_url = reverse_lazy('nosystemd:login')
|
|
|
|
model = DonatorStatus
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(DonatorStatusDetailView, self).get_context_data(**kwargs)
|
|
|
|
context.update({
|
|
|
|
'donator_status': self.request.user.donatorstatus
|
|
|
|
if self.request.user.donatorstatus else None
|
|
|
|
})
|
|
|
|
return context
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
if not request.user.donatorstatus:
|
|
|
|
HttpResponseRedirect('nosystemd:landing')
|
|
|
|
return super(DonatorStatusDetailView, self).get(request, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class ChangeDonatorStatusDetailView(LoginRequiredMixin, UpdateView):
|
|
|
|
template_name = "nosystemd/donator_status.html"
|
|
|
|
context_object_name = "donator_status"
|
|
|
|
login_url = reverse_lazy('nosystemd:login')
|
|
|
|
model = DonatorStatus
|
|
|
|
|
|
|
|
def get_object(self, queryset=None):
|
|
|
|
return self.request.user.donatorstatus
|
|
|
|
|
|
|
|
def post(self, *args, **kwargs):
|
|
|
|
donator_status = self.get_object()
|
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
|
|
|
|
2016-07-27 05:08:45 +00:00
|
|
|
donator_status.status = DonatorStatus.ACTIVE \
|
|
|
|
if donator_status.status == DonatorStatus.CANCELED else DonatorStatus.CANCELED
|
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
|
|
|
|
2016-07-27 05:08:45 +00:00
|
|
|
donator_status.save()
|
|
|
|
messages.success(self.request, 'Your monthly donation status has been changed.')
|
2016-07-31 23:58:43 +00:00
|
|
|
return HttpResponseRedirect(reverse_lazy('nosystemd:donations'))
|