]> 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 3b7fa3ddbaeca90f5f118ff509bef2966fe612be..fec3f090f81fec61afd4aa3029797c319d71243b 100644 (file)
@@ -10,8 +10,6 @@ BEGIN { extends 'Catalyst::Controller' }
 #
 __PACKAGE__->config(namespace => '');
 
-use JSON 'encode_json';
-
 use Chatty::Form::Login;
 use Chatty::Form::Register;
 
@@ -137,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
This page took 0.020612 seconds and 4 git commands to generate.