Commit fb60f5d5 authored by Thibaut Frain's avatar Thibaut Frain

Manage wrong login or password

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