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

Resend activation link #100

Closed
3 tasks done
14MR opened this issue Jan 30, 2020 · 4 comments
Closed
3 tasks done

Resend activation link #100

14MR opened this issue Jan 30, 2020 · 4 comments

Comments

@14MR
Copy link

14MR commented Jan 30, 2020

Checklist

Is your feature request related to a problem? Please describe.

(Provide a clear and concise description of what the problem is.
For example: "I'm always frustrated when ...")
Sometimes, due to some email transport reasons, we need to send again a registration email. But just calling send_verification_notification() function with the same parameters didn't work in this case.

Describe the solution you'd like

(Provide a clear and concise description of what you want to happen)
I want to have an ability to resend registration email manually using a function or admin panel action

P.S. I would like to get some help with an idea of how to implement this so I can do it myself and probably provide a PR. Thank you

@apragacz
Copy link
Owner

apragacz commented Feb 3, 2020

Hi @14MR, would moving the code for sending the" register user" notification to a separate function send_register_verification_notification help, like in this PR:

https://github.com/apragacz/django-rest-registration/pull/101/files

You would only need to provide request and user when calling this function.

@apragacz apragacz added the state:needs-answer Needs additional information from the issue creator label Feb 3, 2020
@14MR
Copy link
Author

14MR commented Feb 4, 2020

It looks like I have to have my user's request to sign it, right? I would like to be able to resend activation link without asking the user to resend it

@no-response no-response bot removed the state:needs-answer Needs additional information from the issue creator label Feb 4, 2020
@apragacz
Copy link
Owner

apragacz commented Feb 5, 2020

@14MR
You need a request because the DRR signer uses request.build_absolute_uri to build the full verification URL. To be exact, this is currently done by function derived from ‘VERIFICATION_URL_BUILDER’ setting key, which is getting the request from the signer.

It doesn't matter whether the request is a Django Request object or DRF Request proxy object, in both cases this method (.build_absolute_uri()) should be available.

So in the case you mentioned earlier (re-sending the e-mail to users from the admin), you could write simple admin action like that:

from django.contrib.auth.admin import UserAdmin

from rest_registration.api.views.register import send_register_verification_notification

from myapp.models import User

def send_verification(modeladmin, request, queryset):
    for user in queryset:
        send_register_verification_notification(request, user)
send_verification.short_description = "Send verification e-mail"

class MyUserAdmin(UserAdmin):
    # ...
    actions = UserAdmin.actions + [send_verification]

admin.site.register(User, MyUserAdmin)

The code above is untested and needs refinement, but hopefully you get the idea; see the docs about admin actions for more:
https://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/

You could consider refining the code by sending the verification only to the unverified users (not all selected) but that's up to you.

I think I will move the send_register_verification_notification to new rest_registration.utils.verification module to avoid confusion, but will confirm that when the change will be merged to master.

If you have any other questions please let me know, in other case I will merge the change in the PR above soon (in few days).

apragacz added a commit that referenced this issue Feb 22, 2020
In regard to issue #100

Changes:
* Create `send_register_verification_email_notification`
  in `rest_registration.utils.verification_notifications` module
* Move `RegisterSigner` to `rest_registration.signers.register` module
apragacz added a commit that referenced this issue Feb 22, 2020
In regard to issue #100

Changes:
* Create `send_register_verification_email_notification`
  in `rest_registration.utils.verification_notifications` module
* Move `RegisterSigner` to `rest_registration.signers.register` module
apragacz added a commit that referenced this issue Feb 22, 2020
In regard to issue #100

Changes:
* Create `send_register_verification_email_notification`
  in `rest_registration.utils.verification_notifications` module
* Move `RegisterSigner` to `rest_registration.signers.register` module
@apragacz
Copy link
Owner

@14MR
I decided to name the aforementioned function send_register_verification_email_notification and place it in rest_registration.utils.verification_notifications module.

apragacz added a commit that referenced this issue Feb 23, 2020
Changes:

*   Re-enable Django 3.0 and DRF 3.10 support (issue #70)
*   Put the code for sending the register verification email in separate
    `send_register_verification_email_notification` (issue #100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants