Beispiel #1
0
 def _assigned(self, ticket):
     if ticket.p3_conference:
         assigned_to = ticket.p3_conference.assigned_to
         if assigned_to:
             comment = ''
             user = None
             try:
                 user = autils.get_user_account_from_email(assigned_to)
             except User.MultipleObjectsReturned:
                 comment = ' (email not unique)'
             except User.DoesNotExist:
                 try:
                     user = autils.get_user_account_from_email(assigned_to,
                                                               active_only=False)
                 except User.DoesNotExist:
                     comment = ' (does not exist)'
                 else:
                     comment = ' (user inactive)'
             if user is not None:
                 url = urlresolvers.reverse('admin:auth_user_change',
                                            args=(user.id,))
                 user_name = ('%s %s' %
                              (user.first_name, user.last_name)).strip()
                 if not user_name:
                     user_name = assigned_to
                     comment += ' (no name set)'
                 return '<a href="%s">%s</a>%s' % (url, user_name, comment)
             elif not comment:
                 comment = ' (missing user account)'
             return '%s%s' % (assigned_to, comment)
         else:
             return '(not assigned)'
     else:
         return '(old style ticket)'
Beispiel #2
0
def _linkProfileToEmail(email, profile):
    try:
        current = autils.get_user_account_from_email(email)
    except auth.models.User.DoesNotExist:
        current = auth.models.User.objects.create_user(
            janrain.suggest_username(profile), email)
        try:
            current.first_name = profile['name']['givenName']
        except KeyError:
            pass
        try:
            current.last_name = profile['name']['familyName']
        except KeyError:
            pass
        current.is_active = True
        current.save()
        log.debug('new (active) django user created "%s"', current)
    else:
        log.debug('django user found "%s"', current)
    try:
        # se current è stato trovato tra gli utenti locali forse esiste
        # anche la controparte assopy
        user = current.assopy_user
    except models.User.DoesNotExist:
        log.debug('the current user "%s" will become an assopy user', current)
        user = models.User(user=current)
        user.save()
    log.debug('a new identity (for "%s") will be linked to "%s"',
              profile['identifier'], current)
    identity = models.UserIdentity.objects.create_from_profile(user, profile)
    return identity
Beispiel #3
0
    def do_update_ticket_name(self, request, queryset):

        if not queryset:
            self.message_user(request, 'no tickets selected')
            return
        for ticket in queryset:
            # Find selected user
            if not ticket.p3_conference:
                continue
            assigned_to = ticket.p3_conference.assigned_to
            try:
                user = autils.get_user_account_from_email(assigned_to)
            except User.MultipleObjectsReturned:
                self.message_user(request,
                                  'found multiple users with '
                                  'email address %s' % assigned_to,
                                  level='error')
                return
            except User.DoesNotExist:
                self.message_user(request,
                                  'no user record found or user inactive for '
                                  ' email address %s' % assigned_to,
                                  level='error')
                return
            if user is None:
                self.message_user(request,
                                  'no user record found for '
                                  ' email address %s' % assigned_to,
                                  level='error')
            # Reassign to selected user
            utils.assign_ticket_to_user(ticket, user)
Beispiel #4
0
def assign_ticket_to_user(ticket, user=None):
    """ Assign ticket to the given user (defaults to buyer of the
        ticket if not given).
    """
    if user is None:
        user = ticket.user

    # Get or create the TicketConference record associated with the
    # Ticket
    try:
        p3c = ticket.p3_conference
    except p3models.TicketConference.DoesNotExist:
        p3c = None
    if p3c is None:
        p3c = p3models.TicketConference(ticket=ticket)

    # Set attendee name on the ticket
    ticket.name = ('%s %s' % (user.first_name, user.last_name)).strip()
    ticket.save()

    # Associate the email address with the ticket, if possible
    try:
        check_user = autils.get_user_account_from_email(user.email)
    except User.MultipleObjectsReturned:
        # Use a work-around by setting the .assigned_to to '';
        # this only works if the buyer is the attendee and the
        # user will have other issues in the system as well.
        p3c.assigned_to = ''
    else:
        p3c.assigned_to = user.email

    p3c.save()
Beispiel #5
0
 def profile(self):
     if self.assigned_to:
         # Ticket assigned to someone else
         user = autils.get_user_account_from_email(self.assigned_to)
     else:
         # Ticket assigned to the buyer
         user = self.ticket.user
     return AttendeeProfile.objects.get(user=user)
Beispiel #6
0
def ticket_user(ticket):
    try:
        p3c = ticket.p3_conference
    except models.TicketConference.DoesNotExist:
        p3c = None
    if p3c and p3c.assigned_to:
        from assopy.utils import get_user_account_from_email
        return get_user_account_from_email(p3c.assigned_to)
    else:
        return ticket.orderitem.order.user
Beispiel #7
0
def janrain_incomplete_profile(request):
    p = request.session['incomplete-profile']
    try:
        name = p['displayName']
    except KeyError:
        name = '%s %s' % (p['name'].get('givenName', ''), p['name'].get(
            'familyName', ''))

    class Form(forms.Form):
        email = forms.EmailField()

    if request.method == 'POST':
        form = Form(data=request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            payload = {
                'email': email,
                'profile': p,
            }
            token = models.Token.objects.create(ctype='j',
                                                payload=json.dumps(payload))
            current = autils.get_user_account_from_email(email, default=None)
            utils.email('janrain-incomplete',
                        ctx={
                            'name': name,
                            'provider': p['providerName'],
                            'token': token,
                            'current': current,
                        },
                        to=[email]).send()
            del request.session['incomplete-profile']
            return HttpResponseRedirectSeeOther(
                reverse('assopy-janrain-incomplete-profile-feedback'))
    else:
        form = Form()
    return {
        'provider': p['providerName'],
        'name': name,
        'form': form,
    }
Beispiel #8
0
def _i_all_user_tickets(sender, **kw):
    """
    NOTE(artcz)(2018-02-28)
    I think this _i_ means 'invalidate' (judging by the partial in
    CacheFunction class.

    So it's a signal(?) that invalidates the all_user_tickets caching.

    However this signal doesnt seem to be attached to anything.
    """
    o = kw['instance']
    if sender is models.TicketConference:
        conference = o.ticket.fare.conference
        params = [(o.ticket.user_id, conference)]
        if o.assigned_to:
            try:
                uid = autils.get_user_account_from_email(o.assigned_to).id
            except User.DoesNotExist:
                pass
            else:
                params.append((uid, conference))
    elif sender is cmodels.Ticket:
        params = [(o.user_id, o.fare.conference)]
    else:
        uid = o.user.user_id
        try:
            conference = o.orderitem_set\
                .all()\
                .distinct()\
                .values('ticket__fare__conference')[0]
        except IndexError:
            return []
        params = [(uid, conference)]
    return [
        'all_user_tickets:%s:%s' % (uid, conference)
        for uid, conference in params
    ]
Beispiel #9
0
def _assign_ticket(ticket, email):
    email = email.strip()
    try:
        recipient = autils.get_user_account_from_email(email)
    except auth.models.User.DoesNotExist:
        try:
            # Here I'm using filter + [0] instead of .get because it could happen,
            # even if it shouldn't, that two identities have the same email
            # (e.g. if someone used the same email on multiple remote services
            # but connected these services to two local users).
            # It's not a problem if more identities have the same email (note
            # that the authentication backend already checks that the same email
            # won't be used twice to create django users) because anway they're
            # email validated by external services.
            recipient = amodels.UserIdentity.objects.filter(
                email__iexact=email)[0].user.user
        except IndexError:
            recipient = None

    if recipient is None:
        log.info('No user found for the email "%s"; time to create a new one',
                 email)
        just_created = True
        u = amodels.User.objects.create_user(email=email,
                                             token=True,
                                             send_mail=False)
        recipient = u.user
        name = email
    else:
        log.info('Found a local user (%s) for the email "%s"',
                 unicode(recipient).encode('utf-8'), email.encode('utf-8'))
        just_created = False
        try:
            auser = recipient.assopy_user
        except amodels.User.DoesNotExist:
            # doh... this django user is not an assopy user, surely something
            # coming from before the introduction of assopy app.
            auser = amodels.User(user=recipient)
            auser.save()
        if not auser.token:
            recipient.assopy_user.token = str(uuid.uuid4())
            recipient.assopy_user.save()
        name = '%s %s' % (recipient.first_name, recipient.last_name)

    _reset_ticket(ticket)

    # Set new ticket name
    ticket.name = name
    ticket.save()

    utils.email(
        'ticket-assigned',
        ctx={
            'name':
            name,
            'just_created':
            just_created,
            'ticket':
            ticket,
            'link':
            settings.DEFAULT_URL_PREFIX +
            reverse('p3-user', kwargs={'token': recipient.assopy_user.token}),
        },
        to=[email]).send()
    return email