Permalink
Browse files

Merge branch 'release/v0.27'

  • Loading branch information...
szabgab committed Mar 11, 2012
2 parents 78e73f2 + 30de443 commit c398be83e666ddd10faccafed9055734379890c1
@@ -1,5 +1,14 @@
Changes to the Dwimmer system. See http://dwimmer.org/
0.27 2012.03.11
- rename /change_password to /change_my_password
- add new /change_password to change the password
of another user
- fix command line adding user
- add command line listing all the users
- set the minimum perl to 5.12
0.26 2012.02.16
- Add minimal search capability
@@ -1,5 +1,4 @@
use 5.008005;
use strict;
use 5.012000;
use warnings;
use inc::Module::Install 1.00;
@@ -3,7 +3,7 @@ use Dancer ':syntax';
use 5.008005;
our $VERSION = '0.26';
our $VERSION = '0.27';
use Data::Dumper qw(Dumper);
use Dwimmer::DB;
@@ -3,7 +3,7 @@ use Dancer ':syntax';
use 5.008005;
our $VERSION = '0.26';
our $VERSION = '0.27';
use Data::Dumper qw(Dumper);
use Email::Valid ();
@@ -680,7 +680,38 @@ post '/set_site_config.json' => sub {
return to_json { success => 1 };
};
post '/change_password.json' => sub {
my %params = _clean_params(qw(uid name new_password admin_password));
return render_response 'error', { 'no_uid_or_name' => 1 } if not $params{uid} and not $params{name};
return render_response 'error', { 'no_new_password' => 1 } if not $params{new_password};
return render_response 'error', { 'no_admin_password' => 1 } if not $params{admin_password};
my $new_sha1 = sha1_base64( $params{new_password} );
my $admin_sha1 = sha1_base64( $params{admin_password} );
my $db = _get_db();
my $admin = $db->resultset('User')->find( { id => session->{userid} } );
return render_response 'error', { 'invalid_admin_password' => 1 }
if $admin->sha1 ne $admin_sha1;
my $user;
if ($params{uid}) {
$user = $db->resultset('User')->find( { id => $params{uid} } );
} else {
$user = $db->resultset('User')->find( { name => $params{name} } );
}
return render_response 'error', { 'no_user_found' => 1 } if not $user;
$user->sha1($new_sha1);
$user->update;
return to_json { success => 1 };
};
post '/change_my_password.json' => sub {
my %params = _clean_params(qw(new_password old_password));
return render_response 'error', { 'no_new_password' => 1 } if not $params{new_password};
return render_response 'error', { 'no_old_password' => 1 } if not $params{old_password};
@@ -8,7 +8,7 @@ has host => ( is => 'ro', isa => 'Str', required => 1 );
has mech => ( is => 'rw', isa => 'WWW::Mechanize', default => sub { WWW::Mechanize->new } );
our $VERSION = '0.26';
our $VERSION = '0.27';
# get_user parameters can be id => 1
@@ -44,6 +44,7 @@ my %POST = map { $_ => $_ } qw(
add_feed
add_user
change_password
change_my_password
create_feed_collector
create_list
create_site
@@ -0,0 +1,118 @@
package Dwimmer::Feed::Admin;
use Moose;
use 5.008005;
our $VERSION = '0.27';
use Dwimmer::Feed::DB;
use Data::Dumper qw(Dumper);
has 'store' => (is => 'ro', isa => 'Str', required => 1);
has 'db' => (is => 'rw', isa => 'Dwimmer::Feed::DB');
sub BUILD {
my ($self) = @_;
$self->db( Dwimmer::Feed::DB->new( store => $self->store ) );
$self->db->connect;
return;
}
sub list {
my ($self, $filter) = @_;
my $sources = $self->db->get_sources;
foreach my $s (@$sources) {
my $show;
if ($filter) {
foreach my $field (qw(feed url status title)) {
$show++ if $s->{$field} =~ /$filter/i;
}
} else {
$show++;
}
if ($show) {
_dump($s);
}
}
return;
}
sub enable {
my ($self, $id) = @_;
return $self->able($id, 1);
}
sub disable {
my ($self, $id) = @_;
return $self->able($id, 0);
}
sub able {
my ($self, $id, $able) = @_;
my $s = $self->db->get_source_by_id($id);
if (not $s) {
die "ID '$id' not found\n";
}
_dump($s);
$self->db->able($id, $able);
_dump($self->db->get_source_by_id($id));
return;
}
sub update {
my ($self, $id, $field, $value) = @_;
_dump($self->db->get_source_by_id($id));
$self->db->update($id, $field, $value);
_dump($self->db->get_source_by_id($id));
return;
}
sub add {
my ($self) = @_;
my %data;
$data{url} = prompt('URL');
$data{feed} = prompt('Feed (Atom or RSS)');
$data{title} = prompt('Title');
$data{twitter} = prompt('Twitter');
$data{status} = 'enabled';
$data{comment} = prompt('Comment');
$data{twitter} =~ s/\@//;
my $id = $self->db->add_source(\%data);
_dump($self->db->get_source_by_id($id));
return;
}
sub _dump {
local $Data::Dumper::Sortkeys = 1;
print Dumper shift;
return;
}
sub prompt {
my ($text) = @_;
print "$text :";
my $input = <STDIN>;
chomp $input;
return $input;
}
sub list_config {
my ($self) = @_;
my $config = $self->db->get_config;
_dump($config);
}
1;
@@ -3,12 +3,20 @@ use Moose;
use 5.008005;
our $VERSION = '0.26';
our $VERSION = '0.27';
my $MAX_SIZE = 500;
my $TRIM_SIZE = 400;
use XML::Feed ();
use Dwimmer::Feed::DB;
use Cwd qw(abs_path);
use File::Basename qw(dirname);
use File::Path qw(mkpath);
use List::Util qw(min);
use MIME::Lite ();
use Template;
use XML::Feed ();
#has 'sources' => (is => 'ro', isa => 'Str', required => 1);
has 'store' => (is => 'ro', isa => 'Str', required => 1);
@@ -34,10 +42,13 @@ TRACK
sub collect {
my ($self) = @_;
my $sources = $self->db->get_sources();
my $INDENT = ' ' x 11;
my $sources = $self->db->get_sources( enabled => 1 );
main::LOG("sources loaded: " . @$sources);
for my $e ( @$sources ) {
main::LOG('');
next if not $e->{status} or $e->{status} ne 'enabled';
if (not $e->{feed}) {
main::LOG("ERROR: No feed for $e->{title}");
@@ -48,22 +59,24 @@ sub collect {
local $SIG{ALRM} = sub { die 'TIMEOUT' };
alarm 10;
main::LOG("Processing $e->{title}");
main::LOG("Processing feed");
main::LOG("$INDENT $e->{feed}");
main::LOG("$INDENT Title by us : $e->{title}");
$feed = XML::Feed->parse(URI->new($e->{feed}));
};
my $err = $@;
alarm 0;
if ($err) {
main::LOG("EXCEPTION $err");
main::LOG(" EXCEPTION: $err");
}
if (not $feed) {
main::LOG("ERROR: " . XML::Feed->errstr);
main::LOG(" ERROR: " . XML::Feed->errstr);
next;
}
if ($feed->title) {
main::LOG("Title: " . $feed->title);
main::LOG("$INDENT Title by them: " . $feed->title);
} else {
main::LOG("WARN: no title");
main::LOG(" WARN: no title");
}
@@ -75,8 +88,7 @@ sub collect {
$hostname =~ s{^(https?://[^/]+).*}{$1};
#main::LOG("HOST: $hostname");
if ( not $self->db->find( link => "$hostname%" ) ) {
main::LOG("ALERT: new hostname ($hostname) in URL: " . $entry->link);
use MIME::Lite ();
main::LOG(" ALERT: new hostname ($hostname) in URL: " . $entry->link);
my $msg = MIME::Lite->new(
From => 'dwimmer@dwimmer.com',
To => 'szabgab@gmail.com',
@@ -89,20 +101,20 @@ sub collect {
my %current = (
source_id => $e->{id},
link => $entry->link,
author => ($entry->{author} || ''),
remote_id => ($entry->{id} || ''),
issued => $entry->issued,
author => ($entry->author || ''),
remote_id => ($entry->id || ''),
issued => ($entry->issued || $entry->modified),
title => ($entry->title || ''),
summary => ($entry->summary->body || ''),
content => ($entry->content->body || ''),
tags => '', #$entry->tags,
);
main::LOG("Adding $current{link}");
main::LOG(" INFO: Adding $current{link}");
$self->db->add(%current);
}
};
if ($@) {
main::LOG("EXCEPTION $@");
main::LOG(" EXCEPTION: $@");
}
}
}
@@ -125,19 +137,18 @@ sub generate_html {
my ($self, $dir) = @_;
die if not $dir or not -d $dir;
my $sources = $self->db->get_sources();
my $sources = $self->db->get_sources( enabled => 1 );
my %src = map { $_->{id } => $_ } @$sources;
my $all_entries = $self->db->get_all_entries;
use List::Util qw(min);
use Template;
my $size = min($FRONT_PAGE_SIZE, scalar @$all_entries);
my @entries = @$all_entries[0 .. $size-1];
foreach my $e (@entries) {
$e->{source_name} = $src{ $e->{source_id} }{title};
$e->{source_url} = $src{ $e->{source_id} }{url};
$e->{twitter} = $src{ $e->{source_id} }{twitter};
$e->{display} = $e->{summary};
if (not $e->{display} and $e->{content} and length $e->{content} < $MAX_SIZE) {
$e->{display} = $e->{content};
@@ -186,8 +197,6 @@ sub generate_html {
}
use File::Basename qw(dirname);
use Cwd qw(abs_path);
my $root = dirname dirname abs_path $0;
my $t = Template->new({ ABSOLUTE => 1, });
@@ -199,7 +208,6 @@ sub generate_html {
foreach my $date (keys %entries_on) {
my ($year, $month, $day) = split /-/, $date;
my $path = "$dir/archive/$year/$month";
use File::Path qw(mkpath);
mkpath $path;
$t->process("$root/views/feed_index.tt", {entries => $entries_on{$date}, %site}, "$path/$day.html") or die $t->error;
}
Oops, something went wrong.

0 comments on commit c398be8

Please sign in to comment.