]>
Dogcows Code - chaz/chatty/blob - Controller/Root.pm
1 package Chatty
::Controller
::Root
;
3 use namespace
::autoclean
;
5 BEGIN { extends
'Catalyst::Controller' }
8 # Sets the actions in this controller to be registered with no prefix
9 # so they function identically to actions created in MyApp.pm
11 __PACKAGE__-
>config(namespace
=> '');
13 use Chatty
::Form
::Login
;
14 use Chatty
::Form
::Register
;
17 isa
=> 'Chatty::Form::Login',
20 default => sub { Chatty
::Form
::Login-
>new }
23 has 'register_form' => (
24 isa
=> 'Chatty::Form::Register',
27 default => sub { Chatty
::Form
::Register-
>new }
32 Chatty::Controller::Root - Root Controller for Chatty
36 Implements all actions for this simple chat application.
46 sub index :Path
:Args
(0) {
47 my ( $self, $c ) = @_;
52 Allow a user to login.
56 sub login
:Local
:Args
(0) {
59 $c->stash(form
=> $self->login_form);
60 $self->login_form->process($c->req->params);
61 return unless $self->login_form->is_valid;
64 if ($c->authenticate({
65 username
=> $self->login_form->value->{username
},
66 password
=> $self->login_form->value->{password
}
68 $c->change_session_id;
69 my $user = $c->user->get('username');
70 $c->flash->{message
} .= "Hi, $user! You are now logged in.";
71 $c->response->redirect($c->uri_for('/'));
74 $c->flash->{error
} = "Log-in failed! Try again, I guess.";
75 $c->response->redirect($c->uri_for('login'));
86 sub logout
:Local
:Args
(0) {
88 if ($c->user_exists) {
90 $c->flash->{message
} = "Goodbye! You have been logged out.";
92 $c->response->redirect($c->uri_for('/'));
97 Register a new account.
101 sub register
:Local
:Args
(0) {
104 $c->stash(form
=> $self->register_form);
106 my $new_account = $c->model('DB::Account')->new_result({});
107 $self->register_form->process(
108 item
=> $new_account,
109 params
=> $c->req->params
112 return unless $self->register_form->is_valid;
114 $c->flash->{message
} = "Registration complete. ";
115 $c->forward('login');
120 Standard 404 error page
126 $c->response->body('Page not found.');
127 $c->response->status(404);
132 Attempt to render a view, if needed.
136 sub end
: ActionClass
('RenderView') {}
144 This library is free software. You can redistribute it and/or modify
145 it under the same terms as Perl itself.
149 __PACKAGE__-
>meta->make_immutable;
This page took 0.047533 seconds and 4 git commands to generate.