]> Dogcows Code - chaz/chatty/blobdiff - lib/Chatty/Controller/Root.pm
use a json view instead of writing json directly
[chaz/chatty] / lib / Chatty / Controller / Root.pm
index f526d4152aa3e4e2a76e19d866604573fc96b737..fec3f090f81fec61afd4aa3029797c319d71243b 100644 (file)
@@ -10,8 +10,6 @@ BEGIN { extends 'Catalyst::Controller' }
 #
 __PACKAGE__->config(namespace => '');
 
 #
 __PACKAGE__->config(namespace => '');
 
-use JSON 'encode_json';
-
 use Chatty::Form::Login;
 use Chatty::Form::Register;
 
 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;
                }
                        $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
 }
 
 =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 $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) {
        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 {
                }
                else {
-                       $json_arr = ["$id", 0, "This username is taken."];
+                       $c->stash->{json} = ["$id", 0, "This username is taken."];
                }
        }
        else {
                }
        }
        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
 }
 
 =head2 access_denied
This page took 0.018747 seconds and 4 git commands to generate.