From 6d029fdeb53ebcf05649c16cb177a0b5fbf4af05 Mon Sep 17 00:00:00 2001 From: Levi Date: Thu, 16 Jun 2016 01:04:48 -0500 Subject: [PATCH 1/3] Added cron to send email and fixing settings error --- dynamicweb/settings/base.py | 1 + dynamicweb/settings/prod.py | 2 ++ dynamicweb/urls.py | 2 +- email_cron | 3 +++ hosting/admin.py | 8 +++--- hosting/templates/emails/new_booked_vm.html | 2 +- hosting/templates/emails/new_booked_vm.txt | 4 +-- hosting/templates/emails/vm_charged.html | 2 +- hosting/templates/emails/vm_charged.txt | 2 +- .../templates/emails/vm_status_changed.html | 2 +- .../templates/emails/vm_status_changed.txt | 2 +- hosting/test_views.py | 8 +++--- hosting/views.py | 25 +++++++++++++------ .../cms/ungleichch/base_ungleich.html | 2 +- utils/mailer.py | 2 +- 15 files changed, 42 insertions(+), 25 deletions(-) create mode 100644 email_cron diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index ab2d6763..e31cbef3 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -55,6 +55,7 @@ INSTALLED_APPS = ( 'easy_thumbnails', 'utils', 'stored_messages', + 'mailer', 'mptt', 'parler', 'taggit', diff --git a/dynamicweb/settings/prod.py b/dynamicweb/settings/prod.py index 1588b5c3..36d625c6 100644 --- a/dynamicweb/settings/prod.py +++ b/dynamicweb/settings/prod.py @@ -8,6 +8,8 @@ ADMINS = ( ) # ('Sanghee Kim', 'sanghee.kim@ungleich.ch'), +EMAIL_BACKEND = "mailer.backend.DbBackend" + #MANAGERS = ADMINS REGISTRATION_MESSAGE['message'] = REGISTRATION_MESSAGE['message'].format(host='digitalglarus.ungleich.ch',slug='{slug}') diff --git a/dynamicweb/urls.py b/dynamicweb/urls.py index 0e2e2196..a732934e 100644 --- a/dynamicweb/urls.py +++ b/dynamicweb/urls.py @@ -25,7 +25,7 @@ urlpatterns += i18n_patterns('', url(r'^digitalglarus/login/', include(membership_urls)), url(r'^digitalglarus/', include('digitalglarus.urls', namespace="digitalglarus")), - url(r'^blog/', include('ungleich.urls', namespace='ungleich')), + # url(r'^blog/', include('ungleich.urls', namespace='ungleich')), url(r'^ungleich_page/', include('ungleich_page.urls', namespace='ungleich_page'), name='ungleich_page'), diff --git a/email_cron b/email_cron new file mode 100644 index 00000000..559fd565 --- /dev/null +++ b/email_cron @@ -0,0 +1,3 @@ +* * * * * (cd /home/app/app/; /usr/bin/python3 manage.py send_mail) +0,20,40 * * * * (cd /home/app/app/; /usr/bin/python3 manage.py retry_deferred) +0 0 * * * (cd /home/app/app/; /usr/bin/python3 manage.py purge_mail_log 7) \ No newline at end of file diff --git a/hosting/admin.py b/hosting/admin.py index 8c9d59da..640878f5 100644 --- a/hosting/admin.py +++ b/hosting/admin.py @@ -32,10 +32,11 @@ class HostingOrderAdmin(admin.ModelAdmin): context = { 'order': obj, - 'vm': obj.vm_plan + 'vm': obj.vm_plan, + 'base_url': "{0}://{1}".format(request.scheme, request.get_host()) } email_data = { - 'subject': 'New VM request', + 'subject': 'Your VM plan has been charged', 'to': obj.customer.user.email, 'context': context, 'template_name': 'vm_charged', @@ -75,7 +76,8 @@ class VirtualMachinePlanAdmin(admin.ModelAdmin): email = self.email(obj) if 'status' in form.changed_data: context = { - 'vm': obj + 'vm': obj, + 'base_url': "{0}://{1}".format(request.scheme, request.get_host()) } email_data = { 'subject': 'Your VM has been activated', diff --git a/hosting/templates/emails/new_booked_vm.html b/hosting/templates/emails/new_booked_vm.html index a36f12a8..651e1c54 100644 --- a/hosting/templates/emails/new_booked_vm.html +++ b/hosting/templates/emails/new_booked_vm.html @@ -114,7 +114,7 @@
My Account
- View Invoice + View Invoice diff --git a/hosting/templates/emails/new_booked_vm.txt b/hosting/templates/emails/new_booked_vm.txt index 3f32d12a..651e1c54 100644 --- a/hosting/templates/emails/new_booked_vm.txt +++ b/hosting/templates/emails/new_booked_vm.txt @@ -101,7 +101,7 @@ Your virtual machine {{vm.name}} subscription has been charged,
- We are going to contact you as soon your virtual machine has been activated. + we are going to contact you as soon your virtual machine has been activated.
You can view your invoice clicking on the button below. @@ -114,7 +114,7 @@
My Account
- View Invoice + View Invoice diff --git a/hosting/templates/emails/vm_charged.html b/hosting/templates/emails/vm_charged.html index 3f0f5f8f..ff3508d9 100644 --- a/hosting/templates/emails/vm_charged.html +++ b/hosting/templates/emails/vm_charged.html @@ -110,7 +110,7 @@
My Account
- View Invoice + View Invoice diff --git a/hosting/templates/emails/vm_charged.txt b/hosting/templates/emails/vm_charged.txt index 3f0f5f8f..ff3508d9 100644 --- a/hosting/templates/emails/vm_charged.txt +++ b/hosting/templates/emails/vm_charged.txt @@ -110,7 +110,7 @@
My Account
- View Invoice + View Invoice diff --git a/hosting/templates/emails/vm_status_changed.html b/hosting/templates/emails/vm_status_changed.html index 96261f44..fd10182a 100644 --- a/hosting/templates/emails/vm_status_changed.html +++ b/hosting/templates/emails/vm_status_changed.html @@ -111,7 +111,7 @@
My Account
- VM Dashboard + VM Dashboard diff --git a/hosting/templates/emails/vm_status_changed.txt b/hosting/templates/emails/vm_status_changed.txt index 96261f44..fd10182a 100644 --- a/hosting/templates/emails/vm_status_changed.txt +++ b/hosting/templates/emails/vm_status_changed.txt @@ -111,7 +111,7 @@
My Account
- VM Dashboard + VM Dashboard diff --git a/hosting/test_views.py b/hosting/test_views.py index 0e9c7626..b2deb6d7 100644 --- a/hosting/test_views.py +++ b/hosting/test_views.py @@ -10,7 +10,7 @@ from model_mommy import mommy from membership.models import CustomUser, StripeCustomer from .models import VirtualMachineType, HostingOrder, VirtualMachinePlan from .views import DjangoHostingView, RailsHostingView, NodeJSHostingView, LoginView, SignupView, \ - PaymentVMView, OrdersHostingDetailView, OrdersHostingListView, VirtualMachineDetailView, \ + PaymentVMView, OrdersHostingDetailView, OrdersHostingListView, VirtualMachineView, \ VirtualMachinesPlanListView from utils.tests import BaseTestCase @@ -172,16 +172,16 @@ class PaymentVMViewTest(BaseTestCase): settings.STRIPE_API_PUBLIC_KEY) -class VirtualMachineDetailViewTest(BaseTestCase): +class VirtualMachineViewTest(BaseTestCase): def setUp(self): - super(VirtualMachineDetailViewTest, self).setUp() + super(VirtualMachineViewTest, self).setUp() self.stripe_customer = mommy.make(StripeCustomer, user=self.customer) self.vm = mommy.make(VirtualMachinePlan) self.order = mommy.make(HostingOrder, customer=self.stripe_customer, vm_plan=self.vm) self.url = reverse('hosting:virtual_machines', kwargs={'pk': self.vm.id}) - self.view = VirtualMachineDetailView() + self.view = VirtualMachineView() self.expected_template = 'hosting/virtual_machine_detail.html' def url_resolve_to_view_correctly(self): diff --git a/hosting/views.py b/hosting/views.py index eca04023..ca591c45 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -285,13 +285,26 @@ class PaymentVMView(LoginRequiredMixin, FormView): # Send notification to ungleich as soon as VM has been booked # TODO send email using celery + + from django.core.mail import send_mail + + send_mail( + 'Subject here', + 'Here is the message.', + 'levinoelvm@gmail.com', + ['levinoelvm@gmail.com'], + fail_silently=False, + ) + context = { 'vm': plan, - 'order': order + 'order': order, + 'base_url': "{0}://{1}".format(request.scheme, request.get_host()) + } email_data = { 'subject': 'New VM request', - 'to': 'info@ungleich.ch', + 'to': request.user.email, 'context': context, 'template_name': 'new_booked_vm', 'template_path': 'emails/' @@ -299,11 +312,6 @@ class PaymentVMView(LoginRequiredMixin, FormView): email = BaseEmail(**email_data) email.send() - # request.session.update({ - # 'charge': charge, - # 'order': order.id, - # 'billing_address': billing_address.id - # }) return HttpResponseRedirect(reverse('hosting:orders', kwargs={'pk': order.id})) else: return self.form_invalid(form) @@ -368,7 +376,8 @@ class VirtualMachineView(LoginRequiredMixin, UpdateView): vm.cancel_plan() context = { - 'vm': vm + 'vm': vm, + 'base_url': "{0}://{1}".format(self.request.scheme, self.request.get_host()) } email_data = { 'subject': 'Virtual machine plan canceled', diff --git a/ungleich/templates/cms/ungleichch/base_ungleich.html b/ungleich/templates/cms/ungleichch/base_ungleich.html index 833b2111..6f70a4a8 100644 --- a/ungleich/templates/cms/ungleichch/base_ungleich.html +++ b/ungleich/templates/cms/ungleichch/base_ungleich.html @@ -1,4 +1,4 @@ -{% load cms_tags menu_tags sekizai_tags staticfiles bootstrap3 %} +{% load i18n cms_tags menu_tags sekizai_tags staticfiles bootstrap3 %} diff --git a/utils/mailer.py b/utils/mailer.py index 130b74ee..0afa60b7 100644 --- a/utils/mailer.py +++ b/utils/mailer.py @@ -21,7 +21,7 @@ class BaseEmail(object): self.email = EmailMultiAlternatives(self.subject, text_content) self.email.attach_alternative(html_content, "text/html") - self.email.to = ['info@digitalglarus.ch'] + self.email.to = ['levinoelvm@gmail.com'] def send(self): self.email.send() From a41b75935c0c9374379f422b5d89efef23ba68a7 Mon Sep 17 00:00:00 2001 From: Levi Date: Thu, 16 Jun 2016 01:19:40 -0500 Subject: [PATCH 2/3] revert django-mailer configuration --- dynamicweb/settings/base.py | 1 - dynamicweb/settings/prod.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index e31cbef3..ab2d6763 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -55,7 +55,6 @@ INSTALLED_APPS = ( 'easy_thumbnails', 'utils', 'stored_messages', - 'mailer', 'mptt', 'parler', 'taggit', diff --git a/dynamicweb/settings/prod.py b/dynamicweb/settings/prod.py index 36d625c6..0d77d1ab 100644 --- a/dynamicweb/settings/prod.py +++ b/dynamicweb/settings/prod.py @@ -8,7 +8,7 @@ ADMINS = ( ) # ('Sanghee Kim', 'sanghee.kim@ungleich.ch'), -EMAIL_BACKEND = "mailer.backend.DbBackend" +EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' #MANAGERS = ADMINS From d8150b65932153510f70b1c42e341e233ed4b6f4 Mon Sep 17 00:00:00 2001 From: Levi Date: Tue, 21 Jun 2016 00:10:38 -0500 Subject: [PATCH 3/3] Created reset password email, Added forgot password view, Added forgot password form, Added set new password form, Added set new password view, fixed signup response issue, fixed main menu ungleich button redirect to django-hosting --- email_cron | 3 - hosting/forms.py | 8 +- hosting/static/hosting/css/landing-page.css | 6 ++ .../emails/password_reset_email.html | 13 +++ .../templates/emails/password_reset_email.txt | 13 +++ hosting/templates/hosting/base_short.html | 2 +- .../hosting/confirm_reset_password.html | 38 +++++++++ hosting/templates/hosting/login.html | 10 +++ hosting/templates/hosting/reset_password.html | 29 +++++++ hosting/templates/hosting/signup.html | 4 +- hosting/urls.py | 5 +- hosting/views.py | 81 ++++++++++++++++--- utils/forms.py | 43 ++++++++++ 13 files changed, 235 insertions(+), 20 deletions(-) delete mode 100644 email_cron create mode 100644 hosting/templates/emails/password_reset_email.html create mode 100644 hosting/templates/emails/password_reset_email.txt create mode 100644 hosting/templates/hosting/confirm_reset_password.html create mode 100644 hosting/templates/hosting/reset_password.html diff --git a/email_cron b/email_cron deleted file mode 100644 index 559fd565..00000000 --- a/email_cron +++ /dev/null @@ -1,3 +0,0 @@ -* * * * * (cd /home/app/app/; /usr/bin/python3 manage.py send_mail) -0,20,40 * * * * (cd /home/app/app/; /usr/bin/python3 manage.py retry_deferred) -0 0 * * * (cd /home/app/app/; /usr/bin/python3 manage.py purge_mail_log 7) \ No newline at end of file diff --git a/hosting/forms.py b/hosting/forms.py index c6537355..8007b2f4 100644 --- a/hosting/forms.py +++ b/hosting/forms.py @@ -4,7 +4,7 @@ from django.contrib.auth import authenticate from utils.stripe_utils import StripeUtils -from .models import HostingOrder +from .models import HostingOrder, VirtualMachinePlan class HostingOrderAdminForm(forms.ModelForm): @@ -17,6 +17,10 @@ class HostingOrderAdminForm(forms.ModelForm): customer = self.cleaned_data.get('customer') vm_plan = self.cleaned_data.get('vm_plan') + if vm_plan.status == VirtualMachinePlan.CANCELED_STATUS: + raise forms.ValidationError("""You can't make a charge over + a canceled virtual machine plan""") + # Make a charge to the customer stripe_utils = StripeUtils() charge_response = stripe_utils.make_charge(customer=customer.stripe_id, @@ -53,7 +57,7 @@ class HostingUserLoginForm(forms.Form): CustomUser.objects.get(email=email) return email except CustomUser.DoesNotExist: - raise forms.ValidationError("User does not exists") + raise forms.ValidationError("User does not exist") else: return email diff --git a/hosting/static/hosting/css/landing-page.css b/hosting/static/hosting/css/landing-page.css index fc0b98f2..166a8241 100644 --- a/hosting/static/hosting/css/landing-page.css +++ b/hosting/static/hosting/css/landing-page.css @@ -83,6 +83,12 @@ h6 { height: 100%; } +.intro-reset-password { + background: url(../img/signup-bg.png) no-repeat center center; + background-size: cover; + height: 100%; +} + .intro-message > h1 { margin: 0; font-weight: 400; diff --git a/hosting/templates/emails/password_reset_email.html b/hosting/templates/emails/password_reset_email.html new file mode 100644 index 00000000..682834f5 --- /dev/null +++ b/hosting/templates/emails/password_reset_email.html @@ -0,0 +1,13 @@ +{% load i18n %}{% autoescape off %} +{% blocktrans %}You're receiving this email because you requested a password reset for your user account at {{ site_name }}.{% endblocktrans %} + +{% trans "Please go to the following page and choose a new password:" %} + {% block reset_link %} + {{ base_url }}{% url 'hosting:reset_password_confirm' uidb64=uid token=token %} + {% endblock %} + +{% trans "Thanks for using our site!" %} + +{% blocktrans %}The {{ site_name }} team{% endblocktrans %} + +{% endautoescape %} \ No newline at end of file diff --git a/hosting/templates/emails/password_reset_email.txt b/hosting/templates/emails/password_reset_email.txt new file mode 100644 index 00000000..682834f5 --- /dev/null +++ b/hosting/templates/emails/password_reset_email.txt @@ -0,0 +1,13 @@ +{% load i18n %}{% autoescape off %} +{% blocktrans %}You're receiving this email because you requested a password reset for your user account at {{ site_name }}.{% endblocktrans %} + +{% trans "Please go to the following page and choose a new password:" %} + {% block reset_link %} + {{ base_url }}{% url 'hosting:reset_password_confirm' uidb64=uid token=token %} + {% endblock %} + +{% trans "Thanks for using our site!" %} + +{% blocktrans %}The {{ site_name }} team{% endblocktrans %} + +{% endautoescape %} \ No newline at end of file diff --git a/hosting/templates/hosting/base_short.html b/hosting/templates/hosting/base_short.html index 5c6110c5..5f0604a7 100644 --- a/hosting/templates/hosting/base_short.html +++ b/hosting/templates/hosting/base_short.html @@ -53,7 +53,7 @@ - +