2014-08-19 09:39:30 -06:00
|
|
|
var accountInfo = {};
|
|
|
|
|
|
|
|
var showLoggedIn = function(data) {
|
|
|
|
accountInfo = data;
|
|
|
|
$(".loggedin").css({visibility: "visible"});
|
|
|
|
$("#welcomeText").text("Welcome " + accountInfo.user_id+". Your access token is: " +
|
|
|
|
accountInfo.access_token);
|
|
|
|
};
|
|
|
|
|
|
|
|
$('.register').live('click', function() {
|
|
|
|
var user = $("#user").val();
|
|
|
|
var password = $("#password").val();
|
|
|
|
$.ajax({
|
2014-08-31 07:51:37 -06:00
|
|
|
url: "http://localhost:8080/_matrix/client/api/v1/register",
|
2014-08-19 09:39:30 -06:00
|
|
|
type: "POST",
|
|
|
|
contentType: "application/json; charset=utf-8",
|
|
|
|
data: JSON.stringify({ user_id: user, password: password }),
|
|
|
|
dataType: "json",
|
|
|
|
success: function(data) {
|
|
|
|
showLoggedIn(data);
|
|
|
|
},
|
|
|
|
error: function(err) {
|
|
|
|
alert(JSON.stringify($.parseJSON(err.responseText)));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
var login = function(user, password) {
|
|
|
|
$.ajax({
|
2014-08-31 07:51:37 -06:00
|
|
|
url: "http://localhost:8080/_matrix/client/api/v1/login",
|
2014-08-19 09:39:30 -06:00
|
|
|
type: "POST",
|
|
|
|
contentType: "application/json; charset=utf-8",
|
|
|
|
data: JSON.stringify({ user: user, password: password, type: "m.login.password" }),
|
|
|
|
dataType: "json",
|
|
|
|
success: function(data) {
|
|
|
|
showLoggedIn(data);
|
|
|
|
},
|
|
|
|
error: function(err) {
|
|
|
|
alert(JSON.stringify($.parseJSON(err.responseText)));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$('.login').live('click', function() {
|
|
|
|
var user = $("#userLogin").val();
|
|
|
|
var password = $("#passwordLogin").val();
|
2014-08-31 07:51:37 -06:00
|
|
|
$.getJSON("http://localhost:8080/_matrix/client/api/v1/login", function(data) {
|
2014-08-29 08:01:46 -06:00
|
|
|
if (data.flows[0].type !== "m.login.password") {
|
2014-08-19 09:39:30 -06:00
|
|
|
alert("I don't know how to login with this type: " + data.type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
login(user, password);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.logout').live('click', function() {
|
|
|
|
accountInfo = {};
|
|
|
|
$("#imSyncText").text("");
|
|
|
|
$(".loggedin").css({visibility: "hidden"});
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.testToken').live('click', function() {
|
2014-08-31 07:51:37 -06:00
|
|
|
var url = "http://localhost:8080/_matrix/client/api/v1/initialSync?access_token=" + accountInfo.access_token + "&limit=1";
|
2014-08-19 09:39:30 -06:00
|
|
|
$.getJSON(url, function(data) {
|
|
|
|
$("#imSyncText").text(JSON.stringify(data, undefined, 2));
|
|
|
|
}).fail(function(err) {
|
|
|
|
$("#imSyncText").text(JSON.stringify($.parseJSON(err.responseText)));
|
|
|
|
});
|
|
|
|
});
|