-
Notifications
You must be signed in to change notification settings - Fork 17
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
Feature/exclude user from drip #171
Conversation
1cabb45
to
1289ef4
Compare
1289ef4
to
280e1d6
Compare
280e1d6
to
923c048
Compare
drip/tokens.py
Outdated
user = User.objects.get(pk=uid) | ||
except (TypeError, ValueError, OverflowError, User.DoesNotExist): | ||
user = None | ||
if user is None or not custom_token_generator.check_token(user, token): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need (user is None) here because if it's None it will return the user at the end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job!!!!
Approved with comments
Build hash value ignoring login_timestamp and password for keeping it valid over time | ||
""" | ||
email_field = user.get_email_field_name() | ||
email = getattr(user, email_field, "") or "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm asking because I'm not sure: do you need the or ""
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copy this code directly from Django source code but I remove the time check. I will leave it as it is right now.
email = getattr(user, email_field, "") or "" | ||
return f"{user.pk}{timestamp}{email}" | ||
|
||
def check_token(self, user: Optional[AbstractBaseUser], token: Optional[str]) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a suggestion: I would change the name by something like token_is_correct
just to be more easy to read in the place you use. But is a minor suggestion you can ignore it if you want
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only override already existing class methods in PasswordResetTokenGenerator
class.
if getattr(settings, "DRIP_UNSUBSCRIBE_USERS", False): | ||
urlpatterns += [ | ||
re_path( | ||
r"^drip/(?P<drip_uidb64>\w+)/(?P<uidb64>\w+)/(?P<token>[\w-]+)/$", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a suggestion:
you can use slug
here as in this example
ignore this comment if you want
drip/utils.py
Outdated
unsubscribe_link = None | ||
try: | ||
unsubscribe_link = reverse(path, kwargs=url_args) | ||
except NoReverseMatch: | ||
return unsubscribe_link | ||
return unsubscribe_link |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsubscribe_link = None | |
try: | |
unsubscribe_link = reverse(path, kwargs=url_args) | |
except NoReverseMatch: | |
return unsubscribe_link | |
return unsubscribe_link | |
try: | |
unsubscribe_link = reverse(path, kwargs=url_args) | |
except NoReverseMatch: | |
return None | |
return unsubscribe_link |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore this if you want
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I apply this suggestion. Thanks!
drip/views.py
Outdated
def _set_user_and_drip(self, **kwargs): | ||
drip_uidb64 = kwargs.get("drip_uidb64", "") | ||
uidb64 = kwargs.get("uidb64", "") | ||
token = kwargs.get("token", "") | ||
self.user = EmailToken.validate_user_uidb64_token(uidb64, token) | ||
self.drip = EmailToken.validate_drip_uidb64(drip_uidb64) | ||
self.post_sucess = False | ||
|
||
def dispatch(self, *args, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to set Any
type for the args and kwargs right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I apply this suggestion. Thanks!
def _set_user_and_drip(self, **kwargs): | ||
drip_uidb64 = kwargs.get("drip_uidb64", "") | ||
uidb64 = kwargs.get("uidb64", "") | ||
token = kwargs.get("token", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if these values are ""
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will go to invalid template, but a URL with ///
no data between slashes will break, so I think it is impossible to reach this case.
Description
DRIP_UNSUBSCRIBE_USERS = True
and add drip.urls to the project path.Body html template field in form
as the followingThis will build a url hashing user and drip data that will be valid forever. Once you open the link it will show you a dumb HTML like this, if the hashes are valid:
If the hashes are invalid it will show you the following:
Once you click the button it will show you a success page.
The library user could add the drip.urls or extend the
UnsubscribeDripView
and change the template names for the ones that matches the style of the user page:ManyToManyField
unsubscribed_users
and new functions for builiding context for the message and excluding this new model in querysets, based on DRIP_UNSUBSCRIBE_USERS.Changes include
Other comments