Exemple #1
0
def user_details(user_id, activation_token):
    """ Returns information about the user. If an activation token is added, 
    it will return a NoUserFound exception if the token does not match. """
    user = lookup_user_by_id(user_id)

    if activation_token is not None:
        if user.activation_key == activation_token or\
           user.is_valid_recovery_code(activation_token):
            return user_to_dict(user, include_name=True)
        else:
            raise ex.UserNotFoundError()

    return user_to_dict(user, include_name=True, include_active=True)
Exemple #2
0
def user_update(user_id, user_info):
    """ Replaces a user's data with the information located in user_info """
    user = lookup_user_by_id(user_id)
    for (key, value) in user_info.iteritems():
        if key == "first_name" and value is not None:
            user.first_name = value
        elif key == "last_name" and value is not None:
            user.last_name = value
        elif key == "email" and value is not None:
            try:
                lookup_user_by_email(value)
            except:
                user.email = value
        elif key == "password" and value is not None:
            user.set_password(value)
        elif key == "active" and value is not None:
            if value:
                user.activate()
            else:
                user.deactivate()
                send_activation_mail.delay(user_id)
        elif key == "social" and value is not None:
            user.meta['social'] = value
        elif key == "address" and value is not None:
            user.meta['address'] = value
        elif key == "crm" and value is not None:
            user.meta['crm'] = value
        elif key == "local" and value is not None:
            user.meta['local'] = value
    return user_to_dict(user)
Exemple #3
0
def ticket_to_dict2(ticket, fields=["id", "user", "creation", "event"]):
    result = dict()
    for field in fields:
        if field == "id":
            result['id'] = ticket.get_code()
        if field == "creation":
            result['created_at'] = timestamp(ticket.created_at)
        if field == "event":
            result['event'] = event_to_dict2(get_event_of_tickettype(
                ticket.ticket_order.ticket_type),
                                             short=True)
        if field == "user":
            result['user'] = user_to_dict(ticket.user)
    return result
Exemple #4
0
def user_create(client_id,
                email,
                password=None,
                first_name=None,
                last_name=None,
                user_info=None):
    """
    Entrypoint for creating new users.
    
    Args:
        email:
            Personal email address of the user
        password:
            Password of the user.
            
    Returns:
        {
            "id": 480
            "first_name": null,
            "last_name": null,
        }
    """
    # validate if email contains actually a valid email address:
    try:
        validate_email(email)
    except ValidationError:
        raise ex.UserError("please enter a valid email address")
    # create account
    user = create_user(email)
    user.first_name = first_name
    user.last_name = last_name
    if password:
        user.set_password(password)
    if user_info:
        for (key, value) in user_info.iteritems():
            if key == "social" and value is not None:
                user.meta['social'] = value
            elif key == "address" and value is not None:
                user.meta['address'] = value
            elif key == "crm" and value is not None:
                user.meta['crm'] = value
            elif key == "local" and value is not None:
                user.meta['local'] = value

    user_info = user_to_dict(user, include_name=True)

    # build success result
    return user_info
Exemple #5
0
def user_exists(email):
    """
    Entrypoint for checking if a user with a given email already exists.
    
    Args:
        email:
            The email address that needs to be checked for existence.
        activation_token:
            
            
    Returns:
        A dictionary {'exists': True} if it exists. If there is no user found
        with the email address, the value will be False.
    """
    user = lookup_user_by_email(email)
    return user_to_dict(user, include_name=True, include_active=True)
Exemple #6
0
def validate_password(user_id, password):
    """ Entrypoint for verifying if there exists a user 
    matching email & password """
    user = lookup_user_by_id(user_id)
    # valid password
    if user.check_password(password):
        user.last_login = datetime.datetime.utcnow()
        result = dict(
            user=user_to_dict(user),
            accounts=map(
                lambda a: account_to_dict2(a, fields=["short_name", "name"]),
                lookup_accounts_of_user(user)))
        return result

    # invalid password
    else:
        raise ex.UserNotFoundError()
Exemple #7
0
def order_list(client_id, order_id=None):
    """ Sends a mail containing the ticket to the owner """
    if order_id is not None:
        try:
            order = lookup_order_by_id(order_id)
        except ex.OrderNotFoundError:
            return []
        else:
            details = dict(
                id=order.id,
                status=order.status,
                user=user_to_dict(order.user),
                account=dict(id=order.account_id, name=order.account.name),
                tickets=map(
                    lambda t: ticket_to_dict(
                        t, include_scanned=True, include_user=False),
                    order.get_tickets()),
                orders=map(lambda to: ticketorder_to_dict(to),
                           order.ordered_tickets))
            return [details]
    return []
Exemple #8
0
def user_deactivate(user_id):
    """ deactivates the user """
    user = lookup_user_by_id(user_id)
    user.deactivate()
    return user_to_dict(user)