You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.7 KiB
JavaScript
80 lines
2.7 KiB
JavaScript
10 years ago
|
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({
|
||
10 years ago
|
url: "http://localhost:8008/_matrix/client/api/v1/register",
|
||
10 years ago
|
type: "POST",
|
||
|
contentType: "application/json; charset=utf-8",
|
||
10 years ago
|
data: JSON.stringify({ user: user, password: password, type: "m.login.password" }),
|
||
10 years ago
|
dataType: "json",
|
||
|
success: function(data) {
|
||
|
showLoggedIn(data);
|
||
|
},
|
||
|
error: function(err) {
|
||
10 years ago
|
var errMsg = "To try this, you need a home server running!";
|
||
|
var errJson = $.parseJSON(err.responseText);
|
||
|
if (errJson) {
|
||
|
errMsg = JSON.stringify(errJson);
|
||
|
}
|
||
|
alert(errMsg);
|
||
10 years ago
|
}
|
||
|
});
|
||
|
});
|
||
|
|
||
|
var login = function(user, password) {
|
||
|
$.ajax({
|
||
10 years ago
|
url: "http://localhost:8008/_matrix/client/api/v1/login",
|
||
10 years ago
|
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) {
|
||
10 years ago
|
var errMsg = "To try this, you need a home server running!";
|
||
|
var errJson = $.parseJSON(err.responseText);
|
||
|
if (errJson) {
|
||
|
errMsg = JSON.stringify(errJson);
|
||
|
}
|
||
|
alert(errMsg);
|
||
10 years ago
|
}
|
||
|
});
|
||
|
};
|
||
|
|
||
|
$('.login').live('click', function() {
|
||
|
var user = $("#userLogin").val();
|
||
|
var password = $("#passwordLogin").val();
|
||
10 years ago
|
$.getJSON("http://localhost:8008/_matrix/client/api/v1/login", function(data) {
|
||
10 years ago
|
if (data.flows[0].type !== "m.login.password") {
|
||
10 years ago
|
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() {
|
||
10 years ago
|
var url = "http://localhost:8008/_matrix/client/api/v1/initialSync?access_token=" + accountInfo.access_token + "&limit=1";
|
||
10 years ago
|
$.getJSON(url, function(data) {
|
||
|
$("#imSyncText").text(JSON.stringify(data, undefined, 2));
|
||
|
}).fail(function(err) {
|
||
|
$("#imSyncText").text(JSON.stringify($.parseJSON(err.responseText)));
|
||
|
});
|
||
|
});
|