Skip to content

Commit

Permalink
Added preregister for provider and updated mail templates
Browse files Browse the repository at this point in the history
  • Loading branch information
jjoseba committed Mar 12, 2024
1 parent bb982e9 commit 3886f69
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 59 deletions.
2 changes: 1 addition & 1 deletion authentication/models/preregister.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def send_email(self):
@staticmethod
def create_user_and_preregister(account):
if not account.owner:
account.owner = User.objects.create_user(email=account.email, first_name=account.display_name)
account.owner = User.objects.create_user(email=account.email, first_name=account.display_name, is_active=True)
account.save()

PreRegisteredUser.objects.create(
Expand Down
1 change: 0 additions & 1 deletion authentication/views/preregister.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def form_valid(self, form):
class ResendPreregisterEmailAction(RedirectURLMixin, View):
def post(self, request, *args, **kwargs):
prereg_user = PreRegisteredUser.objects.get(id=self.kwargs.get('token'))
print(prereg_user)
prereg_user.send_email()
messages.success(self.request, _('Email de prerregistro reenviado'))

Expand Down
7 changes: 2 additions & 5 deletions helpers/mailing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@


def send_template_email(title, destination, template_name, template_params):
print("AAAAAA")
print(template_params)
print(template_name)
msg_plain = render_to_string('email/%s.txt' % template_name, template_params)
msg_html = render_to_string('email/%s.html' % template_name, template_params)
print("BBBBB")
send_mail(
title,
msg_plain,
settings.EMAIL_SEND_FROM,
[destination],
html_message=msg_html,
)
fail_silently=False
)
15 changes: 14 additions & 1 deletion market/forms/account.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django import forms
from django.utils.translation import gettext as _

from authentication.models import User
from helpers.forms.BootstrapForm import BootstrapForm
from market.models import Account
from django.utils.translation import gettext as _


class AccountForm(forms.ModelForm, BootstrapForm):
Expand All @@ -20,3 +21,15 @@ class Meta:
class CreateAccountFormMixin(forms.Form):

create_preregister = forms.BooleanField(required=False, initial=True, label=_('Crear usuaria y mandar email de prerregistro'))

def clean(self):
cleaned_data = super().clean()
preregister = cleaned_data.get('create_preregister')
email = cleaned_data.get('email')

if preregister and email:
# If the user should be created, we need to check if no user exists already with that email
if User.objects.filter(email=email).exists():
self.add_error('email', _('Ya existe un usuario registrado con este email.'))

return cleaned_data
9 changes: 9 additions & 0 deletions market/views/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.views.generic import ListView, CreateView, UpdateView, DetailView
from django_filters import FilterSet

from authentication.models.preregister import PreRegisteredUser
from core.forms.galleryform import PhotoGalleryForm
from core.forms.social_profiles import SocialProfileForm, ProviderSocialProfileForm
from core.mixins.AjaxTemplateResponseMixin import AjaxTemplateResponseMixin
Expand Down Expand Up @@ -120,6 +121,14 @@ def get_initial(self):
'longitude': self.node.longitude,
}

def form_valid(self, form):
response = super().form_valid(form)
preregister = form.cleaned_data['create_preregister']
if preregister:
PreRegisteredUser.create_user_and_preregister(self.object)
return response


def get_success_url(self):
messages.success(self.request, _('Proveedora añadida correctamente.'))
return self.reverse('market:provider_list')
Expand Down
14 changes: 7 additions & 7 deletions templates/common/email/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<head>
<title>{% block title %}{% endblock title %}</title>
<!--[if !mso]><!-- -->
<!--[if !mso]>-->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!--<![endif]-->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Expand Down Expand Up @@ -116,7 +116,7 @@
<table role="presentation" cellpadding="0" cellspacing="0" style="border-collapse:collapse;border-spacing:0px;" align="center" border="0">
<tbody>
<tr>
<td style="width:270px;"><img alt="" title="" height="auto" src="https://topolio.s3-eu-west-1.amazonaws.com/uploads/5ab135c7c6089/1521563628.jpg" style="border:none;border-radius:0px;display:block;font-size:13px;outline:none;text-decoration:none;width:100%;height:auto;" width="270"></td>
<td style="width:270px;"><img alt="" title="" height="auto" src="{% settings_value 'BASESITE_URL' %}{% static 'imgs/brand.png' %}" style="border:none;border-radius:0px;display:block;font-size:13px;outline:none;text-decoration:none;width:100%;height:auto;" width="270"></td>
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -149,7 +149,7 @@ <h1 style="font-family: &apos;Cabin&apos;, sans-serif; color: #FFFFFF; font-size
</table>
<!--[if mso | IE]> </td></tr></table> <![endif]-->
<!--[if mso | IE]> <table role="presentation" border="0" cellpadding="0" cellspacing="0" width="600" align="center" style="width:600px;"> <tr> <td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"> <![endif]-->
<table role="presentation" cellpadding="0" cellspacing="0" style="background:#DBD0DF;font-size:0px;width:100%;" border="0">
<table role="presentation" cellpadding="0" cellspacing="0" style="background:#9258af;color:#fff;font-size:0px;width:100%;" border="0">
<tbody>
<tr>
<td>
Expand All @@ -164,7 +164,7 @@ <h1 style="font-family: &apos;Cabin&apos;, sans-serif; color: #FFFFFF; font-size
<tbody>
<tr>
<td style="word-wrap:break-word;font-size:0px;padding:0px 20px 0px 20px;" align="left">
<div style="cursor:auto;color:#000000;font-family:Lato, Tahoma, sans-serif;font-size:14px;line-height:22px;text-align:left;">
<div style="cursor:auto;color:#fff;font-family:Lato, Tahoma, sans-serif;font-size:14px;line-height:22px;text-align:left;">
{% block content %}

{% endblock content %}
Expand Down Expand Up @@ -229,7 +229,7 @@ <h1 style="font-family: &apos;Cabin&apos;, sans-serif; color: #FFFFFF; font-size
<td style="word-wrap:break-word;font-size:0px;padding:0px 20px 0px 20px;" align="left">
<div style="cursor:auto;color:#000000;font-family:Lato, Tahoma, sans-serif;font-size:14px;line-height:22px;text-align:left;">
<h2 style="color: #757575; line-height: 100%;">Aplicaci&#xF3;n m&#xF3;vil</h2>
<p>&#xBF;Sab&#xED;as que hay una app desde la que gestionar tus movimientos con la moneda social de forma m&#xE1;s c&#xF3;moda? &#xA1;Pru&#xE9;bala!</p>
<p>&#xBF;Sab&#xED;as que hay una app desde la que acceder al Mercado Social de forma m&#xE1;s c&#xF3;moda? &#xA1;Pru&#xE9;bala!</p>
</div>
</td>
</tr>
Expand All @@ -238,7 +238,7 @@ <h2 style="color: #757575; line-height: 100%;">Aplicaci&#xF3;n m&#xF3;vil</h2>
<table role="presentation" cellpadding="0" cellspacing="0" style="border-collapse:separate;" align="center" border="0">
<tbody>
<tr>
<td style="border:none;border-radius:24px;color:#fff;cursor:auto;padding:10px 25px;" align="center" valign="middle" bgcolor="#653776"><a href="https://play.google.com/store/apps/details?id=net.mercadosocial.moneda" style="text-decoration:none;background:#653776;color:#fff;font-family:Ubuntu, Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-size:18px;font-weight:normal;line-height:120%;text-transform:none;margin:0px;" target="_blank">Descarga en Google Play</a></td>
<td style="border:none;border-radius:28px;color:#fff;cursor:auto;padding:12px 25px;" align="center" valign="middle" bgcolor="#f78154"><a href="https://play.google.com/store/apps/details?id=net.mercadosocial.moneda" style="text-decoration:none;color:#fff;font-family:Nimbus Sans L,Tahoma Impact, Helvetica, Arial, sans-serif;text-transform:uppercase;font-size:16px;font-weight:bolder;line-height:120%;margin:0px;" target="_blank">Descarga en Google Play</a></td>
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -314,7 +314,7 @@ <h2 style="color: #757575; line-height: 100%;">Aplicaci&#xF3;n m&#xF3;vil</h2>
<tr>
<td style="word-wrap:break-word;font-size:0px;padding:0px 20px 0px 20px;" align="left">
<div style="cursor:auto;color:#949494;font-family:Lato, Tahoma, sans-serif;font-size:14px;line-height:22px;text-align:left;">
<p><span style="font-size:12px;">Mercado Social de Madrid, 2018&#xA0;&#xA0;</span></p>
<p><span style="font-size:12px;">Mercado Social, 2024&#xA0;&#xA0;</span></p>
</div>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion templates/common/email/button.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<table role="presentation" cellpadding="0" cellspacing="0" style="border-collapse:separate;" align="center" border="0">
<tbody>
<tr>
<td style="border:none;border-radius:24px;color:#fff;cursor:auto;padding:10px 25px;" align="center" valign="middle" bgcolor="#A7CE05"><a href="{{link_href}}" style="text-decoration:none;background:#A7CE05;color:#fff;font-family:Ubuntu, Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-size:18px;font-weight:normal;line-height:120%;text-transform:none;margin:0px;" target="_blank">{{link_text}}</a></td>
<td style="border:none;border-radius:28px;color:#fff;cursor:auto;padding:12px 25px;" align="center" valign="middle" bgcolor="#b6b10a"><a href="https://{% settings_value 'BASESITE_URL' %}{{link_href}}" style="text-decoration:none;color:#fff;font-family:Nimbus Sans L,Tahoma Impact, Helvetica, Arial, sans-serif;text-transform:uppercase;font-size:16px;font-weight:bolder;line-height:120%;text-transform:uppercase;margin:0px;" target="_blank">{{link_text}}</a></td>
</tr>
</tbody>
</table>
2 changes: 0 additions & 2 deletions templates/consumer/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ <h3 class="mb-0"><a href="{% market_url 'market:consumer_list' %}">Consumidoras<
<form method="post" class="post-form gallery-form p-4 mt-3" enctype="multipart/form-data">
{% csrf_token %}
{{ form.node }}
{{form.errors}}

{% include 'consumer/form.html' %}

<div class="mt-3 card bg-warning p-3 mx-auto" style="max-width:30rem;">
Expand Down
11 changes: 5 additions & 6 deletions templates/email/consumer_preregister.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@

{% block content %}

<h2 style="color: #757575; line-height: 100%;">Hola, {{account.display_name}}!</h2>
<h2 style="color: #f78154; line-height: 100%;">Hola, {{account.display_name}}!</h2>


<p>Recibes este email porque has sido dada de alta recientemente para utilizar etics, la app del Mercado Social de Madrid.</p>
<p>Recibes este email porque has sido dada de alta recientemente para utilizar la app del Mercado Social.</p>
<p>Solo falta un último paso, que es que cuentes con una manera de acceder a tu área privada.</p>
<p>Introduce el nombre de usuario y contraseña que utilizarás a partir de ahora en la app para gestionar tus compras en etics y la información de tu perfil en el siguiente enlace: {% settings_value 'BASESITE_URL' %}{% url 'auth:preregister' token %}</p>
<p>Introduce la contraseña que utilizarás a partir de ahora en la app para gestionar la información de tu perfil en el siguiente enlace: {% settings_value 'BASESITE_URL' %}{% url 'auth:preregister' token %}</p>
<p></p>
<p>Desde ese momento, podrás acceder a tu panel de usuario y configurar el perfil de tu entidad y tus ofertas, así como gestionar tu uso de la moneda social.</p>
<p>Desde ese momento, podrás acceder a tu panel de usuario y configurar tu perfil, así como acceder a las últimas noticias u obtener tu carnet de socia.</p>
<p></p>

{% endblock%}

{% block call_button %}

{% url 'auth:preregister' token as link %}
{% settings_value 'BASESITE_URL' as basesite %}

{% include 'common/email/button.html' with link_text='Registro' link_href=basesite|add:link %}
{% include 'common/email/button.html' with link_text='Completar Registro' link_href=link %}
{% endblock call_button %}
27 changes: 27 additions & 0 deletions templates/email/provider_preregister.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% extends 'common/email/base.html' %}
{% load settings_value %}

{% block title %}Registro{% endblock %}

{% block maintitle %}Bienvenid@!{% endblock %}

{% block content %}

<h2 style="color: #f78154; line-height: 100%;">Hola, {{account.display_name}}!</h2>


<p>Recibes este email porque has sido dada de alta recientemente para utilizar la app del Mercado Social.</p>
<p>Solo falta un último paso, que es que cuentes con una manera de acceder a tu área privada.</p>
<p>Introduce la contraseña que utilizarás a partir de ahora en la app para gestionar la información de tu perfil en el siguiente enlace: {% settings_value 'BASESITE_URL' %}{% url 'auth:preregister' token %}</p>
<p></p>
<p>Desde ese momento, podrás acceder a tu panel de usuario y configurar el perfil de tu entidad y tus ofertas, así como ver las ventajas y validar carnets de socias.</p>
<p></p>

{% endblock%}

{% block call_button %}

{% url 'auth:preregister' token as link %}

{% include 'common/email/button.html' with link_text='Completar Registro' link_href=link %}
{% endblock call_button %}
14 changes: 14 additions & 0 deletions templates/email/provider_preregister.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% load settings_value %}

Bienvenid@ al Mercado Social!
Hola, {{account.display_name}}!
Recibes este email porque has sido dada de alta recientemente para utilizar la app del Mercado Social de Madrid.
Solo falta un último paso, que es que cuentes con una manera de acceder a tu área privada.
Introduce la contraseña que utilizarás a partir de ahora en la app para gestionar la información de tu perfil en el siguiente enlace: {% settings_value 'BASESITE_URL' %}{% url 'auth:preregister' token %}

Desde ese momento, podrás acceder a tu panel de usuario y configurar el perfil de tu entidad y tus ofertas, así como gestionar tu uso de la moneda social.


Aplicación móvil
¿Sabías que hay una app desde la que acceder al Mercado Social de forma más cómoda? ¡Pruébala!
Enlace a la app: https://play.google.com/store/apps/details?id=net.mercadosocial.moneda
16 changes: 1 addition & 15 deletions templates/provider/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,8 @@
{% include 'common/social_links.html' with obj=object %}
{% if request.user.is_superuser %}
<hr class="mt-4">
<h4 class="mb-3">Usuario</h4>
<span class="primary-title"><strong>Número de socia:</strong></span>
<span class="text-primary"><strong>Número de socia:</strong></span>
{{object.member_id|default_if_none:'-'}}<br>
{% if preregister_user %}
<span class="primary-title"><strong>Prerregistro: </strong></span> aún no se ha creado usuario<br>
<span class="primary-title"><strong>Enlace: </strong></span>
<a href="{% settings_value 'BASESITE_URL' %}{% url 'preregister' preregister_user.id %}" style="color:blue;" target="_blank">
{% settings_value 'BASESITE_URL' %}{% url 'preregister' preregister_user.id %}</a>
{% else %}
<span class="primary-title"><strong>Username:</strong></span>
{{ object.user.username }}<br>
<span class="primary-title"><strong>Último acceso:</strong></span>
{% if entity.user.last_login %} Hace {{object.user.last_login|timesince}}{% else %} Nunca {% endif %}

{% endif %}

{% endif %}
</div>

Expand Down
5 changes: 4 additions & 1 deletion templates/provider/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
{% include 'provider/row_display.html' %}
<td>{{ item.cif }}</td>
<td>{{ item.owner|default_if_none:'-' }}</td>

<td>
<strong>{{item.offers.all.count}} </strong> oferta(s) publicada(s)<br>
{% if item.benefit %}<i class="material-icons text-success">local_activity</i> Ventajas {%else %} <i class="material-icons text-muted">local_activity</i> Sin ventajas {% endif %}
</td>
<td class="table-actions">
<a class="btn btn-outline-primary" href="{% market_url 'market:edit_provider' item.pk %}" data-toggle="tooltip" data-placement="bottom" title="Editar"><i class="material-icons">mode_edit</i></a>
<a class="btn btn-outline-primary" href="{% market_url 'offers:entity_offers' item.pk %}" data-toggle="tooltip" data-placement="bottom" title="Ver ofertas"><i class="material-icons">shopping_basket</i></a>
Expand Down
11 changes: 1 addition & 10 deletions templates/provider/row_display.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,10 @@
</div>
{% if request.user.is_superuser or request.user.is_staff %}
<span class="account-status">
{% if item.owner %}
{% if item.owner.is_guest_account %}
<i class="material-icons" data-toggle="tooltip" data-placement="bottom" title="Invitada">card_membership</i>
{% else %}
<i class="material-icons" data-toggle="tooltip" data-placement="bottom" title="Registrada">done_all</i>
{% endif %}
{% else %}
<i class="material-icons" data-toggle="tooltip" data-placement="bottom" title="Pendiente registro">schedule</i>
{% endif %}
{% include 'user/status_circle.html' with user=item.owner %}
</span>
{% endif %}


{% if hide_address %}
<h5 class="mt-2 mb-0"> {{item.name}}</h5>
{% else %}
Expand Down
10 changes: 1 addition & 9 deletions templates/user/row_display.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
{% if user.is_guest_account %}
<i class="material-icons" data-toggle="tooltip" data-placement="bottom" title="Invitada">card_membership</i>
{% else %}
{% if user.is_preregistered %}
<i class="material-icons" data-toggle="tooltip" data-placement="bottom" title="Pendiente registro">schedule</i>
{% else %}
<i class="material-icons" data-toggle="tooltip" data-placement="bottom" title="Registrada">done_all</i>
{% endif %}
{% endif %}
{% include 'user/status_circle.html' %}
<span class="text-muted" >{{user}}</span>
Loading

0 comments on commit 3886f69

Please sign in to comment.