Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.63.x [ Do not merge ] #3

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion allauth/account/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,10 @@ def send_account_already_exists_mail(self, email):
"signup_url": signup_url,
"password_reset_url": password_reset_url,
}
self.send_mail("account/email/account_already_exists", email, ctx)
if app_settings.SIGNUP_WITH_PASSWORD:
self.send_mail("account/email/account_already_exists", email, ctx)
else:
self.send_mail("account/email/account_already_exists_nopass", email, ctx)

def send_confirmation_mail(self, request, emailconfirmation, signup):
activate_url = self.get_email_confirmation_url(request, emailconfirmation)
Expand Down
4 changes: 4 additions & 0 deletions allauth/account/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@ def LOGIN_BY_CODE_MAX_ATTEMPTS(self):
def LOGIN_BY_CODE_TIMEOUT(self):
return self._setting("LOGIN_BY_CODE_TIMEOUT", 3 * 60)

@property
def SIGNUP_WITH_PASSWORD(self):
return self._setting("SIGNUP_WITH_PASSWORD", True)


_app_settings = AppSettings("ACCOUNT_")

Expand Down
29 changes: 22 additions & 7 deletions allauth/account/internal/flows/login_by_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ def request_login_code(request, email):
"email": email,
"failed_attempts": 0,
}

email_sent = messages.SUCCESS
if not users:
send_unknown_account_mail(request, email)
if app_settings.EMAIL_UNKNOWN_ACCOUNTS:
send_unknown_account_mail(request, email)
else:
email_sent = messages.ERROR
else:
user = users[0]
code = adapter.generate_login_code()
Expand All @@ -39,12 +44,22 @@ def request_login_code(request, email):
)

request.session[LOGIN_CODE_SESSION_KEY] = pending_login
adapter.add_message(
request,
messages.SUCCESS,
"account/messages/login_code_sent.txt",
{"email": email},
)
if email_sent == messages.SUCCESS:
adapter.add_message(
request,
email_sent,
"account/messages/login_code_sent.txt",
{"email": email},
)
return True
else:
adapter.add_message(
request,
email_sent,
"account/messages/login_code_failed.txt",
{"email": email},
)
return False


def get_pending_login(request, peek=False):
Expand Down
8 changes: 6 additions & 2 deletions allauth/account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,12 @@ def get_form_class(self):
return get_form_class(app_settings.FORMS, "request_login_code", self.form_class)

def form_valid(self, form):
flows.login_by_code.request_login_code(self.request, form.cleaned_data["email"])
return super().form_valid(form)
if flows.login_by_code.request_login_code(
self.request, form.cleaned_data["email"]
):
return super().form_valid(form)
else:
return HttpResponseRedirect(reverse("account_request_login_code"))

def get_success_url(self):
if self.request.user.is_authenticated:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "account/email/base_message.txt" %}
{% load i18n %}

{% block content %}{% autoescape off %}{% blocktrans %}You are receiving this email because you or someone else tried to signup for an
account using email address:

{{ email }}

However, an account using that email address already exists.
You can safely ignore this message if you have signed-up using a different authentication method.

{% endblocktrans %}{% endautoescape %}{% endblock content %}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}Account Already Exists{% endblocktrans %}
{% endautoescape %}
2 changes: 2 additions & 0 deletions allauth/templates/account/messages/login_code_failed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% load i18n %}
{% blocktrans %}Failed to send sign-in code to {{email}}.{% endblocktrans %}