Skip to content

Commit

Permalink
* Reworked the way login happens (now redirects correctly)
Browse files Browse the repository at this point in the history
* Use Catalyst::Model::XML::Feed to get blog entries
  • Loading branch information
Oliver Charles committed Jul 27, 2008
1 parent 67514be commit be3a168
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 87 deletions.
2 changes: 0 additions & 2 deletions lib/MusicBrainz/Server.pm
Expand Up @@ -43,8 +43,6 @@ our $VERSION = '0.01';
# local deployment.
require MusicBrainz::Server::Filters;

__PACKAGE__->config( 'Plugin::ConfigLoader' => { file => 'musicbrainz.yml' } );

__PACKAGE__->config(
name => 'MusicBrainz::Server',
"View::Default" => {
Expand Down
9 changes: 7 additions & 2 deletions lib/MusicBrainz/Server/Controller/Artist.pm
Expand Up @@ -217,6 +217,8 @@ sub create : Local
{
my ($self, $c) = @_;

$c->forward('/user/login');

use MusicBrainz::Server::Form::Artist;

my $form = new MusicBrainz::Server::Form::Artist;
Expand Down Expand Up @@ -258,11 +260,14 @@ into the MusicBrainz database.
sub edit : Chained('artist')
{
my ($self, $c, $mbid) = @_;
my $artist = $c->stash->{_artist};

$c->forward('/user/login');

my $artist = $c->stash->{artist};

use MusicBrainz::Server::Form::Artist;

my $form = new MusicBrainz::Server::Form::Artist($artist->GetId);
my $form = new MusicBrainz::Server::Form::Artist($artist->id);
$form->context($c);

$c->stash->{form} = $form;
Expand Down
52 changes: 4 additions & 48 deletions lib/MusicBrainz/Server/Controller/Root.pm
Expand Up @@ -27,30 +27,6 @@ This controller handles application wide logic for the MusicBrainz website.
=head1 METHODS
=head2 auto
Runs before any other action is dispatched, so we use this to make sure
the user can view the page. This involves checking the list of "private
pages" (those that require an authenticated user), and if the user should
be logged in, gracefully redirecting them to the login action.
=cut

sub auto : Private {
my ($self, $c) = @_;

my %private = map { $_ => 1} @{$c->config->{privatePages}};

if (!$c->user_exists && $private{$c->action})
{
$c->flash->{login_redirect} = $c->uri_for($c->action, $c->req->args);
$c->forward('/user/login');
return 0;
}

return 1;
}

=head2 index
Render the standard MusicBrainz welcome page, which is mainly static,
Expand All @@ -63,34 +39,14 @@ sub index : Path Args(0)
my ($self, $c) = @_;

$c->stash->{server_details} = {
is_slave_db => &DBDefs::REPLICATION_TYPE == RT_SLAVE,
is_slave_db => &DBDefs::REPLICATION_TYPE == RT_SLAVE,
staging_server => &DBDefs::DB_STAGING_SERVER,
};

# Load the blog for the sidebar
#
my $feed = MusicBrainz::Server::NewsFeed->new(
url => 'http://blog.musicbrainz.org/?feed=rss2',
update_interval => 5 * 60,
max_items => 3);

if (defined $feed)
{
$feed->Load();

# Process the items to a template friendly data structure
$c->stash->{blog} = [];

foreach my $item ($feed->GetItems())
{
push @{ $c->stash->{blog} }, {
title => $item->GetTitle,
description => $item->GetDescription,
date_time => $item->GetDateTimeString,
link => $item->GetLink,
};
}
}
#
$c->model('Feeds')->register('musicbrainz', 'http://blog.musicbrainz.org/?feed=rss2');
$c->stash->{blog} = $c->model('Feeds')->get('musicbrainz');

$c->stash->{template} = 'main/index.tt';
}
Expand Down
50 changes: 25 additions & 25 deletions lib/MusicBrainz/Server/Controller/User.pm
Expand Up @@ -58,37 +58,35 @@ sub login : Local
{
my ($self, $c) = @_;

if ($c->user_exists)
unless ($c->user_exists)
{
my $redir = $c->flash->{login_redirect} || $c->uri_for('/user/profile');
$c->response->redirect($redir);
$c->detach;
}
use MusicBrainz::Server::Form::User::Login;

use MusicBrainz::Server::Form::User::Login;
my $form = MusicBrainz::Server::Form::User::Login->new;
$c->stash->{form} = $form;

my $form = MusicBrainz::Server::Form::User::Login->new;
$c->stash->{form} = $form;

if ($c->form_posted && $form->validate($c->request->parameters))
{
my ($username, $password) = ( $form->value("username"),
$form->value("password") );

if( $c->authenticate({ username => $username,
password => $password }) )
if ($c->form_posted && $form->validate($c->request->parameters))
{
my $redir = $c->flash->{login_redirect} || $c->uri_for('/user/profile');
$c->response->redirect($redir);
$c->detach;
}
else
{
$c->stash->{errors} = ['Username/password combination invalid'];
my ($username, $password) = ( $form->value("username"),
$form->value("password") );

if( $c->authenticate({ username => $username,
password => $password }) )
{
$c->response->redirect($c->req->referer);
$c->detach;
}
else
{
$c->stash->{errors} = ['Username/password combination invalid'];
}
}
}

$c->stash->{template} = 'user/login.tt';
$c->stash->{template} = 'user/login.tt';

# Have to make sure we detach
$c->detach;
}
}

=head2 register
Expand Down Expand Up @@ -169,6 +167,8 @@ sub forgotPassword : Local
{
my ($self, $c) = @_;

$c->forward('login');

use MusicBrainz::Server::Form::User::ForgotPassword;

my $form = new MusicBrainz::Server::Form::User::ForgotPassword;
Expand Down
8 changes: 8 additions & 0 deletions lib/MusicBrainz/Server/Model/Feeds.pm
@@ -0,0 +1,8 @@
package MusicBrainz::Server::Model::Feeds;

use strict;
use warnings;

use base 'Catalyst::Model::XML::Feed';

1;
7 changes: 0 additions & 7 deletions musicbrainz.yml
@@ -1,8 +1 @@
---
privatePages:
- artist/edit
- artist/create

- user/donate
- user/changePassword
- user/preferences
7 changes: 4 additions & 3 deletions root/main/index.tt
Expand Up @@ -16,11 +16,12 @@

[% WRAPPER "components/box.tt" color="purple" header="MusicBrainz Blog" %]
<ul id="blog">
[% FOREACH post IN blog %]
[% FOREACH post IN blog.entries %]
[% LAST IF loop.count > 5 %]
<li>
<h3>[% post.title %]</h3>
<p>[% post.description %]</p>
<p>Posted: [% post.date_time %]</p>
<p>[% post.summary.body %]</p>
<p>Posted: [% post.issued %]</p>
</li>
[% END %]
</ul>
Expand Down

0 comments on commit be3a168

Please sign in to comment.