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

Can you reference the Invitation key? #145

Open
Redhaus opened this issue Mar 15, 2020 · 5 comments
Open

Can you reference the Invitation key? #145

Redhaus opened this issue Mar 15, 2020 · 5 comments

Comments

@Redhaus
Copy link

Redhaus commented Mar 15, 2020

Hello,

Thanks for this great project!

Quick question.
I would like to reference the invitation key so that I can do a lookup on the inviters_id.
I would use the email address for the lookup but if the user clicks a link then wishes to signup with a different email this method would not work. However, if I could reference the invitation key that would be a unique string. Is there a way for me to get the invitation key in a variable?

thank you in advance.

@ashersuman
Copy link

i am also looking for this. please reply

@Redhaus
Copy link
Author

Redhaus commented Apr 19, 2020

@ashersuman this isn't the ideal way of going about it but as a workaround, I was able to get the inviters_id using a signal after a user signs up. I hope this helps.

...
from invitations.models import Invitation
...

@receiver(user_signed_up)
def teacher_confirmed_(request, user, **kwargs):

       # If invited by school get invite object and assign those teachers to those schools

        invite = Invitation.objects.filter(email=user.email).first()

        if invite:

            # get inviter_id
            schoolAdminID = invite.inviter_id
            
            # get school user who sent invitation with inviter schooladmin_id
            parentSchoolObj = School.objects.filter(primary_contact_id=schoolAdminID).first()

            # create teacher profile and assign to school
            profile = TeacherProfile.objects.create(
                user=user,
                school_name=parentSchoolObj,
            )

            return profile

@ashersuman
Copy link

Thanks a lot!! Signals worked for me.

@scambrayj
Copy link

I'll post this here for anyone needing this, but was able to get the key via the below using the invite_accepted receiver.

Note: the receiver currently has an error that is not merged yet and related to #116

the fix for this is listed in the #116 comments to modify installed files for Invitations --> views.py line 181, add request=request to arguments. That will get the signal to fire and the below should work in getting the key.

@receiver(invite_accepted)
def invite_accepted(sender, request, email, **kwargs):
    # extract the key from the request address
    # example request - <WSGIRequest: GET '/invitations/accept-invite/ezgu4srazp9vmrgipgnbwwtd04ifsdivbqba9i2ooe9vi15wss8gcs9sa3vvydwh'>
    request = str(request)
    list1 = request.split('/')
    value = list1[3]
    list2 = value.split("'")
    key = list2[0]
    # use the key and the email to lookup the exact invite and get team assignment from custom model or other fields...
    invite = MemberInvitation.objects.get(key=key, email=email)
    print(invite.team)

@valberg
Copy link
Contributor

valberg commented Mar 31, 2022

These are great ideas to have as small cookbook examples in the docs (#176)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants