Commit fb60f5d5 authored by Thibaut Frain's avatar Thibaut Frain

Manage wrong login or password

parent eb321967
...@@ -31,6 +31,9 @@ ...@@ -31,6 +31,9 @@
<fieldset class="ui-btn-inline"> <fieldset class="ui-btn-inline">
<input type="submit" value="Log In"> <input type="submit" value="Log In">
</fieldset> </fieldset>
{{#if authfail}}
<p style="color:red;">Bad username or password</p>
{{/if}}
</form> </form>
</div> </div>
</script> </script>
......
...@@ -10,9 +10,11 @@ ...@@ -10,9 +10,11 @@
function serializeXML(xml) { function serializeXML(xml) {
return new XMLSerializer().serializeToString(xml); return new XMLSerializer().serializeToString(xml);
} }
function logout(gadget) { function logout(gadget, authfail) {
sessionStorage.removeItem("connection_params"); sessionStorage.removeItem("connection_params");
return gadget.render(); return gadget.render({
authfail: authfail
});
} }
function showLogout(gadget) { function showLogout(gadget) {
return new RSVP.Queue().push(function() { return new RSVP.Queue().push(function() {
...@@ -67,7 +69,7 @@ ...@@ -67,7 +69,7 @@
}); });
} }
function connectionListener(gadget, params) { function connectionListener(gadget, params) {
var connection = new Strophe.Connection(params.server), connection_callback; var connection = new Strophe.Connection(params.server), connection_callback, authfail = false;
gadget.props.connection = connection; gadget.props.connection = connection;
function canceller() { function canceller() {
if (connection_callback !== undefined) { if (connection_callback !== undefined) {
...@@ -78,10 +80,14 @@ ...@@ -78,10 +80,14 @@
connection_callback = function(status) { connection_callback = function(status) {
new RSVP.Queue().push(function() { new RSVP.Queue().push(function() {
if (status === Strophe.Status.CONNECTED) { if (status === Strophe.Status.CONNECTED) {
authfail = false;
return login(gadget, params); return login(gadget, params);
} }
if (status === Strophe.Status.DISCONNECTED) { if (status === Strophe.Status.DISCONNECTED) {
return logout(gadget); return logout(gadget, authfail);
}
if (status === Strophe.Status.CONNFAIL || status === Strophe.Status.AUTHFAIL) {
authfail = true;
} }
}).fail(function(e) { }).fail(function(e) {
reject(e); reject(e);
...@@ -91,11 +97,14 @@ ...@@ -91,11 +97,14 @@
} }
return new RSVP.Promise(resolver, canceller); return new RSVP.Promise(resolver, canceller);
} }
function showLogin(gadget) { function showLogin(gadget, options) {
var params = { var params = {
server: "https://mail.tiolive.com/chat/http-bind/" server: "https://mail.tiolive.com/chat/http-bind/"
}; };
return new RSVP.Queue().push(function() { return new RSVP.Queue().push(function() {
if (options && options.authfail) {
params.authfail = true;
}
$(gadget.__element).html(login_template(params)); $(gadget.__element).html(login_template(params));
}).push(function() { }).push(function() {
return promiseEventListener(gadget.__element.querySelector("form.login-form"), "submit", false); return promiseEventListener(gadget.__element.querySelector("form.login-form"), "submit", false);
...@@ -126,10 +135,10 @@ ...@@ -126,10 +135,10 @@
} }
}).ready(function(g) { }).ready(function(g) {
g.props = {}; g.props = {};
}).declareMethod("render", function() { }).declareMethod("render", function(options) {
if (this.props.connection && this.props.connection.authenticated) { if (this.props.connection && this.props.connection.authenticated) {
return showLogout(this); return showLogout(this);
} }
return showLogin(this); return showLogin(this, options);
}); });
})($, Strophe, rJS, Handlebars); })($, Strophe, rJS, Handlebars);
\ No newline at end of file
...@@ -31,6 +31,9 @@ ...@@ -31,6 +31,9 @@
<fieldset class="ui-btn-inline"> <fieldset class="ui-btn-inline">
<input type="submit" value="Log In"> <input type="submit" value="Log In">
</fieldset> </fieldset>
{{#if authfail}}
<p style="color:red;">Bad username or password</p>
{{/if}}
</form> </form>
</div> </div>
</script> </script>
......
...@@ -22,9 +22,9 @@ ...@@ -22,9 +22,9 @@
return new XMLSerializer().serializeToString(xml); return new XMLSerializer().serializeToString(xml);
} }
function logout(gadget) { function logout(gadget, authfail) {
sessionStorage.removeItem("connection_params"); sessionStorage.removeItem("connection_params");
return gadget.render(); return gadget.render({authfail: authfail});
} }
function showLogout(gadget) { function showLogout(gadget) {
...@@ -101,7 +101,9 @@ ...@@ -101,7 +101,9 @@
function connectionListener(gadget, params) { function connectionListener(gadget, params) {
var connection = new Strophe.Connection(params.server), var connection = new Strophe.Connection(params.server),
connection_callback; connection_callback,
authfail = false;
gadget.props.connection = connection; gadget.props.connection = connection;
function canceller() { function canceller() {
...@@ -115,10 +117,15 @@ ...@@ -115,10 +117,15 @@
new RSVP.Queue() new RSVP.Queue()
.push(function () { .push(function () {
if (status === Strophe.Status.CONNECTED) { if (status === Strophe.Status.CONNECTED) {
authfail = false;
return login(gadget, params); return login(gadget, params);
} }
if (status === Strophe.Status.DISCONNECTED) { if (status === Strophe.Status.DISCONNECTED) {
return logout(gadget); return logout(gadget, authfail);
}
if (status === Strophe.Status.CONNFAIL ||
status === Strophe.Status.AUTHFAIL) {
authfail = true;
} }
}) })
.fail(function (e) { .fail(function (e) {
...@@ -130,12 +137,15 @@ ...@@ -130,12 +137,15 @@
return new RSVP.Promise(resolver, canceller); return new RSVP.Promise(resolver, canceller);
} }
function showLogin(gadget) { function showLogin(gadget, options) {
var params = { var params = {
server: "https://mail.tiolive.com/chat/http-bind/" server: "https://mail.tiolive.com/chat/http-bind/"
}; };
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
if (options && options.authfail) {
params.authfail = true;
}
$(gadget.__element).html(login_template(params)); $(gadget.__element).html(login_template(params));
}) })
.push(function () { .push(function () {
...@@ -198,11 +208,11 @@ ...@@ -198,11 +208,11 @@
g.props = {}; g.props = {};
}) })
.declareMethod('render', function () { .declareMethod('render', function (options) {
if (this.props.connection && if (this.props.connection &&
this.props.connection.authenticated) { this.props.connection.authenticated) {
return showLogout(this); return showLogout(this);
} }
return showLogin(this); return showLogin(this, options);
}); });
}($, Strophe, rJS, Handlebars)); }($, Strophe, rJS, Handlebars));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment