def create_user_profile(sender, instance, created, **kwargs): """signal handler for User post-save """ if created: user = instance from htk.apps.accounts.utils.general import get_user_profile_model UserProfileModel = get_user_profile_model() profile = UserProfileModel.objects.create(user=user) profile.save() if htk_setting('HTK_SLACK_NOTIFICATIONS_ENABLED'): try: from htk.utils.notifications import slack_notify slack_notify( 'A new user has registered on the site %s: *%s <%s>*' % ( htk_setting('HTK_SITE_NAME'), user.profile.get_display_name(), user.email, )) if htk_setting('HTK_SLACK_BOT_ENABLED'): slack_notify('htk: emaildig %s' % user.email) except: rollbar.report_exc_info() if htk_setting('HTK_ITERABLE_ENABLED'): try: from htk.lib.iterable.utils import get_iterable_api_client itbl = get_iterable_api_client() itbl.notify_sign_up(user) except: rollbar.report_exc_info()
def create_user_profile(sender, instance, created, **kwargs): """signal handler for User post-save """ if created: user = instance from htk.apps.accounts.utils.general import get_user_profile_model UserProfileModel = get_user_profile_model() profile = UserProfileModel.objects.create(user=user) profile.save() if not settings.TEST and htk_setting('HTK_SLACK_NOTIFICATIONS_ENABLED'): try: from htk.utils.notifications import slack_notify slack_notify('A new user has registered on the site %s: *%s <%s>*' % ( get_site_name(), user.profile.get_display_name(), user.email, )) if htk_setting('HTK_SLACK_BOT_ENABLED'): slack_notify('htk: emaildig %s' % user.email) except: rollbar.report_exc_info() if not settings.TEST and htk_setting('HTK_ITERABLE_ENABLED'): try: from htk.lib.iterable.utils import get_iterable_api_client itbl = get_iterable_api_client() itbl.notify_sign_up(user) except: rollbar.report_exc_info() if htk_setting('HTK_INVITATIONS_LIFECYCLE_SIGNALS_ENABLED'): from htk.apps.invitations.services import InvitationsService invitations_service = InvitationsService() invitations_service.process_user_created(user)
def send_activation_email(self, domain=None, resend=False, template=None, subject=None, sender=None): """Sends an activation email """ domain = domain or htk_setting('HTK_DEFAULT_EMAIL_SENDING_DOMAIN') self._reset_activation_key(resend=resend) try: should_send_activation_email = True if htk_setting('HTK_ITERABLE_ENABLED'): from htk.lib.iterable.utils import get_iterable_api_client from htk.lib.iterable.utils import get_campaign_id if resend: campaign_key = 'triggered.transactional.account.confirm_email_resend' else: campaign_key = 'triggered.transactional.account.sign_up_confirm_email' itbl_campaign_id = get_campaign_id(campaign_key) if itbl_campaign_id: should_send_activation_email = False data = { 'activation_uri' : self.get_activation_uri(domain=domain), } itbl = get_iterable_api_client() itbl.send_triggered_email(self.email, itbl_campaign_id, data=data) if should_send_activation_email: activation_email(self, domain=domain, template=template, subject=subject, sender=sender) except: request = get_current_request() rollbar.report_exc_info(request=request)
def send_activation_email(self, domain=None, resend=False, template=None, subject=None, sender=None): """Sends an activation email """ domain = domain or htk_setting('HTK_DEFAULT_EMAIL_SENDING_DOMAIN') self._reset_activation_key(resend=resend) try: should_send_activation_email = True if htk_setting('HTK_ITERABLE_ENABLED'): from htk.lib.iterable.utils import get_iterable_api_client from htk.lib.iterable.utils import get_campaign_id itbl_campaign_id = get_campaign_id('triggered.account.sign_up_confirm_email') if itbl_campaign_id: should_send_activation_email = False data = { 'activation_uri' : self.get_activation_uri(domain=domain), } itbl = get_iterable_api_client() itbl.send_triggered_email(self.email, itbl_campaign_id, data=data) if should_send_activation_email: activation_email(self, domain=domain, template=template, subject=subject, sender=sender) except: request = get_current_request() rollbar.report_exc_info(request=request)
def notify_user_email_update(user, old_email, new_email): if htk_setting('HTK_ITERABLE_ENABLED'): try: from htk.lib.iterable.utils import get_iterable_api_client itbl = get_iterable_api_client() itbl.update_user_email(old_email, new_email, force=True) except: rollbar.report_exc_info()
def notify_user_email_update(user, old_email, new_email): if htk_setting('HTK_ITERABLE_ENABLED'): try: from htk.lib.iterable.utils import get_iterable_api_client itbl = get_iterable_api_client() itbl.update_user_email(old_email, new_email, force=True) except: rollbar.report_exc_info()
def pre_delete_user(sender, instance, using, **kwargs): user = instance if not settings.TEST and htk_setting('HTK_ITERABLE_ENABLED'): try: from htk.lib.iterable.utils import get_iterable_api_client itbl = get_iterable_api_client() emails = list(set([user.email] + [user_email.email for user_email in user.profile.get_confirmed_emails()])) for email in emails: itbl.delete_user(email) except: rollbar.report_exc_info()
def login_authenticated_user(request, authenticated_user, backend=None): """Logs in an authenticated user and performs related updates `authenticated_user` has already been authenticated via one of the login backends """ login(request, authenticated_user, backend=backend) authenticated_user.profile.update_locale_info_by_ip_from_request(request) if htk_setting('HTK_ITERABLE_ENABLED'): try: from htk.lib.iterable.utils import get_iterable_api_client itbl = get_iterable_api_client() itbl.notify_login(authenticated_user) except: rollbar.report_exc_info()
def login_authenticated_user(request, authenticated_user, backend=None): """Logs in an authenticated user and performs related updates `authenticated_user` has already been authenticated via one of the login backends """ login(request, authenticated_user, backend=backend) authenticated_user.profile.update_locale_info_by_ip_from_request(request) if htk_setting('HTK_ITERABLE_ENABLED'): try: from htk.lib.iterable.utils import get_iterable_api_client itbl = get_iterable_api_client() itbl.notify_login(authenticated_user) except: rollbar.report_exc_info()
def pre_delete_user(sender, instance, using, **kwargs): user = instance if not settings.TEST and htk_setting('HTK_ITERABLE_ENABLED'): try: from htk.lib.iterable.utils import get_iterable_api_client itbl = get_iterable_api_client() emails = list( set([user.email] + [ user_email.email for user_email in user.profile.get_confirmed_emails() ])) for email in emails: itbl.delete_user(email) except: rollbar.report_exc_info()
def activate(self, email_template=None, email_subject=None, email_sender=None): """Activate the User if not already activated """ was_activated = False user = self.user if not user.is_active: user.is_active = True user.save() was_activated = user.is_active if was_activated: # trigger notifications for an activated account should_send_welcome_email = True if htk_setting('HTK_ITERABLE_ENABLED'): try: itbl_opts = htk_setting('HTK_ITERABLE_OPTIONS') should_send_welcome_email = not itbl_opts.get( 'override_welcome_email', False) from htk.lib.iterable.utils import get_iterable_api_client itbl = get_iterable_api_client() itbl.notify_account_activation(user) except: rollbar.report_exc_info() if should_send_welcome_email: self.send_welcome_email(template=email_template, subject=email_subject, sender=email_sender) if htk_setting('HTK_SLACK_NOTIFICATIONS_ENABLED'): try: from htk.utils.notifications import slack_notify slack_notify('*%s* has activated their account on %s' % ( user.email, htk_setting('HTK_SITE_NAME'), )) except: rollbar.report_exc_info() return was_activated
def activate(self, email_template=None, email_subject=None, email_sender=None): """Activate the User if not already activated """ was_activated = False user = self.user if not user.is_active: user.is_active = True user.save() was_activated = user.is_active if was_activated: # trigger notifications for an activated account should_send_welcome_email = True if htk_setting('HTK_ITERABLE_ENABLED'): try: itbl_opts = htk_setting('HTK_ITERABLE_OPTIONS') should_send_welcome_email = not itbl_opts.get('override_welcome_email', False) from htk.lib.iterable.utils import get_iterable_api_client itbl = get_iterable_api_client() itbl.notify_account_activation(user) except: rollbar.report_exc_info() if should_send_welcome_email: self.send_welcome_email(template=email_template, subject=email_subject, sender=email_sender) if htk_setting('HTK_SLACK_NOTIFICATIONS_ENABLED'): try: from htk.utils.notifications import slack_notify slack_notify('*%s* has activated their account on %s' % ( user.email, htk_setting('HTK_SITE_NAME'), )) except: rollbar.report_exc_info() return was_activated