Skip to content

Commit

Permalink
Merge pull request xsawyerx#35 from victor-dogaru/victor
Browse files Browse the repository at this point in the history
BLOGSPERL-192 Switch the theme between light and dark - Rewrite
  • Loading branch information
drforr committed Feb 10, 2016
2 parents c177ff4 + 1d63e75 commit b8be43b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import_folder: 'public/uploads/import/'
images_folder: 'public/uploads/images/'
images_path: '/uploads/images'
default_avatar: '/blog/img/male-user.png'
theme: 'light'

app_url: 'http://localhost:5000'
email_templates: 'views/emails/'
Expand Down
15 changes: 11 additions & 4 deletions lib/PearlBee.pm
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,23 @@ Set user's theme (assuming they're logged in) to the given name.
=cut

post '/theme/update' => sub { # Should be PATCH
post '/theme/:theme' => sub { # Should be PATCH
my $session_user = session('user');
my $theme = route_parameters('theme');
return unless $session_user->{id};
my $theme = body_parameters->get('theme') eq 'true' ? 'light' : 'dark';
$theme = body_parameters->get('theme') eq 'true' ? 'light' : 'dark';
my $user = resultset('User')->find({id => $session_user->{id}});

$user->update({ theme => $theme });
return;
redirect "/theme";#redirect to get method so as not to loop
};

get '/theme' => sub{
my $session_user = session('user');
return config('theme') unless $session_user->{id};
my $user = resultset('User')->find({id => $session_user->{id}});
my $theme = $user->theme;
return to_json($theme);
};
=head
Home page
Expand Down

0 comments on commit b8be43b

Please # to comment.