- // needed in case of 403 errors: if user has already connected successfully
- // before, it probably means he has cookies disabled
- hasAlreadyConnected: function() {
- return (this.connections >= 1);
+ reset: function() {
+ if (this.req) {
+ this.req.abort();
+ this.req = this.currentvalue = null;
+ }
+ if (this.messageelt) {
+ this.messageelt.up().setStyle({visibility: 'hidden'});
+ }
+ },
+
+ check: function() {
+ var pseudo = $("user_pseudo").value;
+
+ this.reset();
+
+ if (!pseudo || !(pseudo.match(/^[a-zA-Z0-9_.]+$/))) {
+ return;
+ }
+
+ if (typeof this.exists[pseudo] === "boolean") {
+ this.reset();
+ this.availableMessage(!this.exists[pseudo]);
+ return;
+ }
+
+ this.message(SyjStrings.pseudoChecking, "", true);
+
+ this.currentvalue = pseudo;
+ this.req = new Ajax.TimedRequest('userexists/' + encodeURIComponent(pseudo), 20, {
+ onFailure: this.failure.bind(this),
+ onSuccess: this.success.bind(this)
+ });
+ },
+
+ failure: function(transport) {
+ var httpCode = 0, value = this.currentvalue;
+
+ if (transport) {
+ httpCode = transport.getStatus();
+ }
+ this.reset();
+ if (httpCode === 404) {
+ this.exists[value] = false;
+ this.availableMessage(true);
+ }
+
+ },
+
+ success: function(transport) {
+ var httpCode = transport.getStatus(), value = this.currentvalue;
+ this.reset();
+ this.exists[value] = true;
+ this.availableMessage(false);