Created
December 4, 2014 15:13
-
-
Save mikkeloscar/f116378b2b6233fcf061 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>title</title> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> | |
<script src="test.js"></script> | |
</head> | |
<body> | |
<!-- page content --> | |
<button id="register">Register</button> | |
<button id="activate">Activate</button> | |
<input type="text" id="activate-key" placeholder="Activation key"> | |
<button id="login">Login</button> | |
<input type="text" id="session-token" placeholder="Session token"> | |
<input type="text" id="user-id" placeholder="User ID"> | |
<button id="get-user">Get User</button> | |
<button id="gen-appkey">Gen App-Key</button> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function () { | |
// var base_url = "http://localhost:8080"; | |
var base_url = "http://testing.grammatic.al"; | |
var url = base_url + "/api/v1/users/"; | |
var username = "[email protected]"; | |
var password = "secr3t123"; | |
$("#register").on('click', function () { | |
$.ajax({ | |
type: "POST", | |
url: url + "register", | |
data: { "email": username, "email_retype": username, "password": password, "password_retype": password }, | |
username: username, | |
password: password, | |
}).done(function (data) { | |
console.log(data); | |
console.log(arguments); | |
}).error(function (e) { | |
console.log(e.responseText); | |
console.log(arguments); | |
}); | |
}); | |
$("#login").on('click', function () { | |
$.ajax({ | |
type: "POST", | |
url: url + "login", | |
headers: { | |
"Authorization": "Basic " + btoa(username + ":" + password) | |
}, | |
username: username, | |
password: password, | |
}).done(function (data) { | |
console.log(data); | |
}).error(function (e) { | |
console.log(e.responseText); | |
}); | |
}); | |
$("#activate").on('click', function () { | |
var key = $("#activate-key").val(); | |
$.ajax({ | |
type: "GET", | |
url: url + "activate/" + key, | |
}).done(function (data) { | |
console.log(data); | |
}).error(function (e) { | |
console.log(e.responseText); | |
}); | |
}); | |
// use session cookie | |
$("#get-user").on('click', function () { | |
var session = $("#session-token").val(); | |
var user_id = $("#user-id").val(); | |
$.ajax({ | |
type: "GET", | |
headers: { | |
"Session-Token": session | |
}, | |
url: url + user_id, | |
}).done(function (data) { | |
console.log(data); | |
}).error(function (e) { | |
console.log(e.responseText); | |
}); | |
}); | |
// generate AppKey | |
$("#gen-appkey").on('click', function () { | |
var session = $("#session-token").val(); | |
$.ajax({ | |
type: "POST", | |
headers: { | |
"Session-Token": session | |
}, | |
url: url + "generateappkey", | |
}).done(function (data) { | |
console.log(data); | |
}).error(function (e) { | |
console.log(e.responseText); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment