Skip to content
Merged
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
4 changes: 2 additions & 2 deletions mailauth/contrib/user/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ class AbstractEmailUser(AbstractUser):
email = CIEmailField(_('email address'), unique=True, db_index=True)
"""The field is unique and case insensitive to serve as a better username."""

# Salt for the session hash replacing the password in this function.
session_salt = models.CharField(
max_length=12, editable=False,
default=get_random_string,
)
"""Salt for the session hash replacing the password in this function."""

def has_usable_password(self):
return False
Expand All @@ -63,7 +63,7 @@ class Meta(AbstractUser.Meta):
abstract = True

def get_session_auth_hash(self):
"""Return an HMAC of the session_salt field."""
"""Return an HMAC of the :attr:`.session_salt` field."""
key_salt = "mailauth.contrib.user.models.EmailUserManager.get_session_auth_hash"
if not self.session_salt:
raise ValueError("'session_salt' must be set")
Expand Down
6 changes: 6 additions & 0 deletions mailauth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ def form_valid(self, form):
def get_success_url(self):
return resolve_url(self.success_url)

def get_initial(self):
return {
self.redirect_field_name: self.request.GET.get(self.redirect_field_name),
**super().get_initial(),
}


INTERNAL_LOGIN_URL_TOKEN = 'login-token'

Expand Down
11 changes: 11 additions & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
from django.urls import reverse

from mailauth.views import LoginView


class TestLoginView:

def test_get_initial(self, rf):
view = LoginView()
view.request = rf.get("/", data={"next": "foo/bar"})

assert view.get_initial() == {"next": "foo/bar"}


class TestLoginTokenView:

Expand Down