Skip to content

Instantly share code, notes, and snippets.

@sankalpjonn
Last active March 20, 2019 07:42
Show Gist options
  • Save sankalpjonn/16eccb066d76944817bd152893380bf0 to your computer and use it in GitHub Desktop.
Save sankalpjonn/16eccb066d76944817bd152893380bf0 to your computer and use it in GitHub Desktop.
## validated_data contains the request data to the invite api
user, _ = helpers.get_or_create_user(email=validated_data['email'])
user.is_active = False
user.save()
## business is the object of the business model that is retrieved using the auth token in the header
business_team_member, _ = BusinessTeamMember.objects.get_or_create(
user=user,
business=business,
defaults={
'activation_key': helpers.generate_activation_key(),
'role': validated_data['role'],
'email': validated_data['email']
}
)
## send invitation email with a link containing the activation key
if not validated_data.get('no_email'):
send_invitation_email(validated_data['email'], business_team_member.activation_key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment