X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fchatty;a=blobdiff_plain;f=lib%2FChatty%2FController%2FRoot.pm;h=fec3f090f81fec61afd4aa3029797c319d71243b;hp=f526d4152aa3e4e2a76e19d866604573fc96b737;hb=30558f981fe131d1ae3cc88ff5fc7f9e910932e9;hpb=8a3ece46ef6bfeefaa27f53f199c285d0062f841 diff --git a/lib/Chatty/Controller/Root.pm b/lib/Chatty/Controller/Root.pm index f526d41..fec3f09 100644 --- a/lib/Chatty/Controller/Root.pm +++ b/lib/Chatty/Controller/Root.pm @@ -10,8 +10,6 @@ BEGIN { extends 'Catalyst::Controller' } # __PACKAGE__->config(namespace => ''); -use JSON 'encode_json'; - use Chatty::Form::Login; use Chatty::Form::Register; @@ -75,9 +73,11 @@ sub login :Local :Args(0) { $c->res->redirect($c->uri_for_action('index')); return; } + else { + $c->flash->{error} = "Log-in failed! Try again, I guess."; + $c->res->redirect($c->uri_for_action('login')); + } }; - $c->flash->{error} = "Log-in failed! Try again, I guess."; - $c->res->redirect($c->uri_for_action('login')); } =head2 logout @@ -135,22 +135,19 @@ sub register_validate :Local :Args(0) { my $id = $c->req->param('fieldId'); my $username = $c->req->param('fieldValue'); - my $json_arr = []; - if ($username) { my $account = $c->model('DB::Account')->find({username => $username}); if (!$account) { - $json_arr = ["$id", 1, "This username is available. Nice!"]; + $c->stash->{json} = ["$id", 1, "This username is available. Nice!"]; } else { - $json_arr = ["$id", 0, "This username is taken."]; + $c->stash->{json} = ["$id", 0, "This username is taken."]; } } else { - $json_arr = ["$id", 0, "Invalid arguments to check script."]; + $c->stash->{json} = ["$id", 0, "Invalid arguments to check script."]; } - $c->res->content_type("application/json"); - $c->res->body(encode_json($json_arr)); + $c->forward('View::JSON'); } =head2 access_denied