]> Dogcows Code - chaz/chatty/blob - lib/Chatty/Controller/Root.pm
add register template; improved message feedback
[chaz/chatty] / lib / Chatty / Controller / Root.pm
1 package Chatty::Controller::Root;
2 use Moose;
3 use namespace::autoclean;
4
5 BEGIN { extends 'Catalyst::Controller' }
6
7 #
8 # Sets the actions in this controller to be registered with no prefix
9 # so they function identically to actions created in MyApp.pm
10 #
11 __PACKAGE__->config(namespace => '');
12
13 =head1 NAME
14
15 Chatty::Controller::Root - Root Controller for Chatty
16
17 =head1 DESCRIPTION
18
19 Implements all actions for this simple chat application.
20
21 =head1 METHODS
22
23 =head2 index
24
25 The root page (/)
26
27 =cut
28
29 sub index :Path :Args(0) {
30 my ( $self, $c ) = @_;
31 }
32
33 =head2 login
34
35 Allow a user to login.
36
37 =cut
38
39 sub login :Local :Args(0) {
40 my ($self, $c) = @_;
41 if ($c->req->method eq 'POST' && exists($c->req->params->{handle})) {
42 eval {
43 if ($c->authenticate({
44 username => $c->req->params->{handle},
45 password => $c->req->params->{password}
46 })) {
47 $c->change_session_id;
48 my $user = $c->user->get('username');
49 $c->flash->{message} = "Hi, $user! You are now logged in.";
50 $c->response->redirect($c->uri_for('/'));
51 }
52 else {
53 $c->flash->{error} = "Log-in failed! Try again, I guess.";
54 $c->response->redirect($c->uri_for('login'));
55 }
56 }
57 }
58 }
59
60 =head2 logout
61
62 Log the user out.
63
64 =cut
65
66 sub logout :Local :Args(0) {
67 my ($self, $c) = @_;
68 if ($c->user_exists) {
69 $c->logout;
70 $c->flash->{message} = "Goodbye! You have been logged out.";
71 }
72 $c->response->redirect($c->uri_for('/'));
73 }
74
75 =head2 register
76
77 Register a new account.
78
79 =cut
80
81 sub register :Local :Args(0) {
82 }
83
84 =head2 default
85
86 Standard 404 error page
87
88 =cut
89
90 sub default :Path {
91 my ($self, $c) = @_;
92 $c->response->body('Page not found.');
93 $c->response->status(404);
94 }
95
96 =head2 end
97
98 Attempt to render a view, if needed.
99
100 =cut
101
102 sub end : ActionClass('RenderView') {}
103
104 =head1 AUTHOR
105
106 Charles McGarvey
107
108 =head1 LICENSE
109
110 This library is free software. You can redistribute it and/or modify
111 it under the same terms as Perl itself.
112
113 =cut
114
115 __PACKAGE__->meta->make_immutable;
116
117 1;
This page took 0.039192 seconds and 5 git commands to generate.