#
__PACKAGE__->config(namespace => '');
+use JSON 'encode_json';
+
use Chatty::Form::Login;
use Chatty::Form::Register;
=cut
sub index :Path :Args(0) {
- my ( $self, $c ) = @_;
+ my ($self, $c) = @_;
+ $c->go('/chat/list') if ($c->user_exists);
+ $c->go('login');
}
=head2 login
$c->change_session_id;
my $user = $c->user->get('username');
$c->flash->{message} .= "Hi, $user! You are now logged in.";
- $c->response->redirect($c->uri_for('/'));
+ $c->res->redirect($c->uri_for_action('index'));
+ return;
}
- else {
- $c->flash->{error} = "Log-in failed! Try again, I guess.";
- $c->response->redirect($c->uri_for('login'));
- }
- }
+ };
+ $c->flash->{error} = "Log-in failed! Try again, I guess.";
+ $c->res->redirect($c->uri_for_action('login'));
}
=head2 logout
$c->logout;
$c->flash->{message} = "Goodbye! You have been logged out.";
}
- $c->response->redirect($c->uri_for('/'));
+ $c->res->redirect($c->uri_for_action('index'));
}
=head2 register
params => $c->req->params
);
- return unless $self->register_form->is_valid;
+ if (!$self->register_form->is_valid) {
+ if ($c->req->method eq 'POST') {
+ $c->stash->{error} = "The form has a validation error. Try again...";
+ }
+ return;
+ }
$c->flash->{message} = "Registration complete. ";
$c->forward('login');
}
+=head2 register_validate
+
+Check whether or not a username is available.
+
+=cut
+
+sub register_validate :Local :Args(0) {
+ my ($self, $c) = @_;
+
+ 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!"];
+ }
+ else {
+ $json_arr = ["$id", 0, "This username is taken."];
+ }
+ }
+ else {
+ $json_arr = ["$id", 0, "Invalid arguments to check script."];
+ }
+ $c->res->content_type("application/json");
+ $c->res->body(encode_json($json_arr));
+}
+
+=head2 access_denied
+
+Standard 403 error page
+
+=cut
+
+sub access_denied :Private {
+ my ($self, $c) = @_;
+ $c->res->body('Access denied.');
+ $c->res->status(403);
+}
+
+=head2 missing
+
+Standard 404 error page
+
+=cut
+
+sub missing :Private {
+ my ($self, $c) = @_;
+ $c->res->body('Page not found.');
+ $c->res->status(404);
+}
+
=head2 default
Standard 404 error page
sub default :Path {
my ($self, $c) = @_;
- $c->response->body('Page not found.');
- $c->response->status(404);
+ $c->detach('missing');
}
=head2 end
$.validationEngineLanguage.allRules = {\r
"required": { // Add your regex rules here, you can take telephone as an example\r
"regex": "none",\r
- "alertText": "* This field is required",\r
- "alertTextCheckboxMultiple": "* Please select an option",\r
- "alertTextCheckboxe": "* This checkbox is required",\r
- "alertTextDateRange": "* Both date range fields are required"\r
+ "alertText": "This field is required.",\r
+ "alertTextCheckboxMultiple": "Please select an option.",\r
+ "alertTextCheckboxe": "This checkbox is required.",\r
+ "alertTextDateRange": "Both date range fields are required."\r
},\r
"dateRange": {\r
"regex": "none",\r
- "alertText": "* Invalid ",\r
+ "alertText": "Invalid ",\r
"alertText2": "Date Range"\r
},\r
"dateTimeRange": {\r
"regex": "none",\r
- "alertText": "* Invalid ",\r
+ "alertText": "Invalid ",\r
"alertText2": "Date Time Range"\r
},\r
"minSize": {\r
"regex": "none",\r
- "alertText": "* Minimum ",\r
+ "alertText": "Minimum ",\r
"alertText2": " characters allowed"\r
},\r
"maxSize": {\r
"regex": "none",\r
- "alertText": "* Maximum ",\r
+ "alertText": "Maximum ",\r
"alertText2": " characters allowed"\r
},\r
"groupRequired": {\r
"regex": "none",\r
- "alertText": "* You must fill one of the following fields"\r
+ "alertText": "You must fill one of the following fields."\r
},\r
"min": {\r
"regex": "none",\r
- "alertText": "* Minimum value is "\r
+ "alertText": "Minimum value is "\r
},\r
"max": {\r
"regex": "none",\r
- "alertText": "* Maximum value is "\r
+ "alertText": "Maximum value is "\r
},\r
"past": {\r
"regex": "none",\r
- "alertText": "* Date prior to "\r
+ "alertText": "Date prior to "\r
},\r
"future": {\r
"regex": "none",\r
- "alertText": "* Date past "\r
+ "alertText": "Date past "\r
}, \r
"maxCheckbox": {\r
"regex": "none",\r
- "alertText": "* Maximum ",\r
+ "alertText": "Maximum ",\r
"alertText2": " options allowed"\r
},\r
"minCheckbox": {\r
"regex": "none",\r
- "alertText": "* Please select ",\r
+ "alertText": "Please select ",\r
"alertText2": " options"\r
},\r
"equals": {\r
"regex": "none",\r
- "alertText": "* Fields do not match"\r
+ "alertText": "Fields do not match."\r
},\r
"phone": {\r
// credit: jquery.h5validate.js / orefalo\r
"regex": /^([\+][0-9]{1,3}[ \.\-])?([\(]{1}[0-9]{2,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/,\r
- "alertText": "* Invalid phone number"\r
+ "alertText": "Invalid phone number."\r
},\r
"email": {\r
// Shamelessly lifted from Scott Gonzalez via the Bassistance Validation plugin http://projects.scottsplayground.com/email_address_validation/\r
"regex": /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,\r
- "alertText": "* Invalid email address"\r
+ "alertText": "Invalid email address."\r
},\r
"integer": {\r
"regex": /^[\-\+]?\d+$/,\r
- "alertText": "* Not a valid integer"\r
+ "alertText": "Not a valid integer."\r
},\r
"number": {\r
// Number, including positive, negative, and floating decimal. credit: orefalo\r
"regex": /^[\-\+]?(([0-9]+)([\.,]([0-9]+))?|([\.,]([0-9]+))?)$/,\r
- "alertText": "* Invalid floating decimal number"\r
+ "alertText": "Invalid floating decimal number."\r
},\r
"date": {\r
"regex": /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/,\r
- "alertText": "* Invalid date, must be in YYYY-MM-DD format"\r
+ "alertText": "Invalid date, must be in YYYY-MM-DD format."\r
},\r
"ipv4": {\r
"regex": /^((([01]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))[.]){3}(([0-1]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))$/,\r
- "alertText": "* Invalid IP address"\r
+ "alertText": "Invalid IP address."\r
},\r
"url": {\r
"regex": /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i,\r
- "alertText": "* Invalid URL"\r
+ "alertText": "Invalid URL."\r
},\r
"onlyNumberSp": {\r
"regex": /^[0-9\ ]+$/,\r
- "alertText": "* Numbers only"\r
+ "alertText": "Numbers only."\r
},\r
"onlyLetterSp": {\r
"regex": /^[a-zA-Z\ \']+$/,\r
- "alertText": "* Letters only"\r
+ "alertText": "Letters only."\r
},\r
"onlyLetterNumber": {\r
"regex": /^[0-9a-zA-Z]+$/,\r
- "alertText": "* No special characters allowed"\r
+ "alertText": "No special characters allowed."\r
},\r
// --- CUSTOM RULES -- Those are specific to the demos, they can be removed or changed to your likings\r
"ajaxUserCall": {\r
"url": "ajaxValidateFieldUser",\r
// you may want to pass extra data on the ajax call\r
"extraData": "name=eric",\r
- "alertText": "* This user is already taken",\r
- "alertTextLoad": "* Validating, please wait"\r
+ "alertText": "This user is already taken.",\r
+ "alertTextLoad": "Validating, please wait..."\r
},\r
"ajaxUserCallPhp": {\r
"url": "phpajax/ajaxValidateFieldUser.php",\r
// you may want to pass extra data on the ajax call\r
"extraData": "name=eric",\r
// if you provide an "alertTextOk", it will show as a green prompt when the field validates\r
- "alertTextOk": "* This username is available",\r
- "alertText": "* This user is already taken",\r
- "alertTextLoad": "* Validating, please wait"\r
+ "alertTextOk": "This username is available.",\r
+ "alertText": "This user is already taken.",\r
+ "alertTextLoad": "Validating, please wait..."\r
},\r
"ajaxNameCall": {\r
// remote json service location\r
"url": "ajaxValidateFieldName",\r
// error\r
- "alertText": "* This name is already taken",\r
+ "alertText": "This name is already taken.",\r
// if you provide an "alertTextOk", it will show as a green prompt when the field validates\r
- "alertTextOk": "* This name is available",\r
+ "alertTextOk": "This name is available.",\r
// speaks by itself\r
- "alertTextLoad": "* Validating, please wait"\r
+ "alertTextLoad": "Validating, please wait..."\r
},\r
"ajaxNameCallPhp": {\r
// remote json service location\r
"url": "phpajax/ajaxValidateFieldName.php",\r
// error\r
- "alertText": "* This name is already taken",\r
+ "alertText": "This name is already taken.",\r
// speaks by itself\r
- "alertTextLoad": "* Validating, please wait"\r
+ "alertTextLoad": "Validating, please wait..."\r
},\r
"validate2fields": {\r
- "alertText": "* Please input HELLO"\r
+ "alertText": "Please input HELLO."\r
},\r
//tls warning:homegrown not fielded \r
"dateFormat":{\r
"regex": /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$|^(?:(?:(?:0?[13578]|1[02])(\/|-)31)|(?:(?:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(?:(?:0?[1-9]|1[0-2])(\/|-)(?:0?[1-9]|1\d|2[0-8]))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(0?2(\/|-)29)(\/|-)(?:(?:0[48]00|[13579][26]00|[2468][048]00)|(?:\d\d)?(?:0[48]|[2468][048]|[13579][26]))$/,\r
- "alertText": "* Invalid Date"\r
+ "alertText": "Invalid Date."\r
},\r
//tls warning:homegrown not fielded \r
"dateTimeFormat": {\r
"regex": /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])\s+(1[012]|0?[1-9]){1}:(0?[1-5]|[0-6][0-9]){1}:(0?[0-6]|[0-6][0-9]){1}\s+(am|pm|AM|PM){1}$|^(?:(?:(?:0?[13578]|1[02])(\/|-)31)|(?:(?:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^((1[012]|0?[1-9]){1}\/(0?[1-9]|[12][0-9]|3[01]){1}\/\d{2,4}\s+(1[012]|0?[1-9]){1}:(0?[1-5]|[0-6][0-9]){1}:(0?[0-6]|[0-6][0-9]){1}\s+(am|pm|AM|PM){1})$/,\r
- "alertText": "* Invalid Date or Date Format",\r
+ "alertText": "Invalid Date or Date Format.",\r
"alertText2": "Expected Format: ",\r
"alertText3": "mm/dd/yyyy hh:mm:ss AM|PM or ", \r
"alertText4": "yyyy-mm-dd hh:mm:ss AM|PM"\r
- }\r
+ },\r
+ "register_validate": {\r
+ "url": "register_validate",\r
+ "alertTextLoad": "Validating, please wait..."\r
+ },\r
};\r
\r
}\r
};\r
$.validationEngineLanguage.newLang();\r
-})(jQuery);
\ No newline at end of file
+})(jQuery);\r