Concierge

 view release on metacpan or  search on metacpan

lib/Concierge.pm  view on Meta::CPAN

        if ($save_result->{success}) {
            push @deleted_from, 'concierge mapping';
        } else {
            push @warnings, "Concierge mapping: failed to save";
        }
    }

    # Build response
    my $message = scalar(@deleted_from)
        ? "User '$user_id' removed from: " . join(', ', @deleted_from)
        : "User '$user_id' not found in any component";

    return {
        success => 1,
        message => $message,
        user_id => $user_id,
        deleted_from => \@deleted_from,
        (@warnings ? (warnings => \@warnings) : ()),
    };
}

# Verify user: check if user exists in both Auth and Users components
sub verify_user ($self, $user_id) {
    # Verifies user exists and checks for data consistency
    # User is considered verified only if present in BOTH components

    return { success => 0, message => 'user_id is required' }
        unless defined $user_id && length($user_id);

    # Check Auth component (password file)
    my $auth_exists = $self->auth->checkID($user_id);

    # Check Users component (user data store)
    my $user_result = $self->users->get_user($user_id);
    my $users_exists = $user_result->{success};

    # User is verified if in BOTH components
    my $verified = $auth_exists && $users_exists;

    my $response = {
        success => 1,
        verified => $verified,
        exists_in_auth => $auth_exists,
        exists_in_users => $users_exists,
    };

    # Add user_status if available
    if ($users_exists && exists $user_result->{user}{user_status}) {
        $response->{user_status} = $user_result->{user}{user_status};
    }

    # Warn if inconsistent (exists in one but not both)
    if ($auth_exists != $users_exists) {
        $response->{warning} = 'User exists in only one component - data inconsistency detected';
    }

    return $response;
}

# Update user data: modify user record in Users component
sub update_user_data ($self, $user_id, $update_data) {
    return { success => 0, message => 'user_id is required' }
        unless defined $user_id && length($user_id);

    return { success => 0, message => 'update_data must be a hash reference' }
        unless ref $update_data eq 'HASH';

    # Filter update data (excludes user_id, password, confirm_password)
    my $filtered_updates = $user_update_filter->($update_data);
    return { success => 0, message => 'No valid fields to update' }
        unless $filtered_updates && keys %$filtered_updates;

    # Update user in Users component
    my $update_result = $self->users->update_user($user_id, $filtered_updates);
    unless ($update_result->{success}) {
        return { success => 0, message => $update_result->{message} };
    }

    return {
        success => 1,
        message => "User '$user_id' updated successfully",
        user_id => $user_id,
    };
}

# Get user data: retrieve user profile from Users component
sub get_user_data ($self, $user_id, @fields) {
    # Retrieves user profile data fields
    # If @fields specified, returns only those fields
    # Otherwise returns all user data

    return { success => 0, message => 'user_id is required' }
        unless defined $user_id && length($user_id);

    # Get user from Users component
    my $user_result = $self->users->get_user($user_id);
    return { success => 0, message => $user_result->{message} || 'User not found' }
        unless $user_result->{success};

    my $user_data = $user_result->{user};

    # If specific fields requested, return only those that exist
    if (@fields) {
        my %selected;
        for my $field (@fields) {
            $selected{$field} = $user_data->{$field} if exists $user_data->{$field};
        }
        return { success => 1, user => \%selected };
    }

    # Otherwise return all data
    return { success => 1, user => $user_data };
}

# List users: retrieve list of user_ids, optionally with full data
sub list_users ($self, $filter='', $options={}) {
    # Returns user_ids by default
    # With include_data => 1: fetches full user records
    # With fields => [...]: returns only specified fields per user

    # Get user_ids from Users component



( run in 0.585 second using v1.01-cache-2.11-cpan-39bf76dae61 )