Skip to content

Commit

Permalink
#142 - Fix issues with password reset email
Browse files Browse the repository at this point in the history
  • Loading branch information
jjoseba committed May 23, 2024
1 parent 94f357e commit 3fbf970
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
31 changes: 15 additions & 16 deletions api/views/auth.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging

from django.contrib.auth import get_user_model, logout, login
Expand All @@ -15,7 +16,6 @@

logger = logging.getLogger(__name__)


User = get_user_model()


Expand Down Expand Up @@ -74,7 +74,6 @@ def post(self, request, *args, **kwargs):
token, created = APIToken.objects.get_or_create(user=user)
login(request, user)


# RESPONSE RETROCOMPATIBLE, PENDING REFACTOR
account = Account.objects.get(owner=user)
is_provider = isinstance(account, Provider)
Expand Down Expand Up @@ -122,22 +121,22 @@ def delete(self, request, format=None):
user = APIToken.objects.get(pk=request.user.auth_token).user
user.delete()
logout(request)
return Response(status=status.HTTP_200_OK, data={'response': _('Usuario eliminado con éxito.')} )
return Response(status=status.HTTP_200_OK, data={'response': _('Usuario eliminado con éxito.')})


class ResetPasswordView(APIView):
permission_classes = (AllowAny,)

def post(self, request, *args, **kwargs):
email = request.data.get('email')
logger.info(f"Starting reset password process for email [{email}]")
try:
User.objects.get(email=email)
reset_form = PasswordReset(request.data)
if reset_form.is_valid():
permission_classes = (AllowAny,)

def post(self, request, *args, **kwargs):
email = request.data.get('email')
logger.info(f"Starting reset password process for email [{email}]")
try:
User.objects.get(email=email)
reset_form = PasswordReset(request.data)
if reset_form.is_valid():
reset_form.save()
return Response(status=status.HTTP_200_OK, data={})
else:
return Response(status=status.HTTP_400_BAD_REQUEST, data=reset_form.errors)
except User.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)
else:
return Response(status=status.HTTP_400_BAD_REQUEST, data={'message': json.dumps(reset_form.errors)})
except User.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)
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: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>
<td style="border:none;border-radius:28px;color:#fff;cursor:auto;padding:12px 25px;" align="center" valign="middle" bgcolor="#b6b10a"><a href="{% 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>
3 changes: 0 additions & 3 deletions templates/email/password_reset.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
{% with site_name as 'Mercado Social' %}
{% blocktranslate %}You're receiving this email because you requested a password reset for your user account at {{ site_name }}.{% endblocktranslate %}
{% endwith %}
</p>
<p>
{% translate 'Your username, in case you’ve forgotten:' %} {{ user.get_username }}
</p>
{% translate "Thanks for using our site!" %}
{% endautoescape %}
Expand Down

0 comments on commit 3fbf970

Please sign in to comment.