Skip to content

Instantly share code, notes, and snippets.

@worr
Last active December 23, 2015 08:09
Show Gist options
  • Save worr/6605541 to your computer and use it in GitHub Desktop.
Save worr/6605541 to your computer and use it in GitHub Desktop.
package cravatar;
use Dancer ':syntax';
use Dancer::Plugin::LDAP;
use Dancer::Plugin::Cache::CHI;
use Net::LDAP::Util qw/escape_filter_value/;
use Try::Tiny;
our $VERSION = '0.1';
check_page_cache;
get '/:UUID.jpg' => sub {
my $uuid = param 'UUID';
my $ret;
try {
$ret = [ (ldap->search(
base => "ou=Users,dc=csh,dc=rit,dc=edu",
filter => "entryUUID=".escape_filter_value($uuid),
attrs => [ 'jpegPhoto' ],
)->entries()) ]->[0]->get('jpegPhoto');
} or status 404;
my $photo = $ret->[0];
cache_page send_file(\$photo, content_type => 'image/jpeg');
};
true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment