Skip to content

Instantly share code, notes, and snippets.

@krusty
Created July 12, 2012 13:13
Show Gist options
  • Save krusty/3098025 to your computer and use it in GitHub Desktop.
Save krusty/3098025 to your computer and use it in GitHub Desktop.
$(function () {
Login = {};
Login.Views = {};
Login.Model = Backbone.Model.extend({
//curl -v -H "Accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" https://sandbox.catalogchoice.org/oauth2/access_token -d "grant_type=password&[email protected]&password=apassword&client_id=8rmz3ts4r7dvr877i2zvrsw66&scope=read write"
url: "https://sandbox.catalogchoice.org/oauth2/access_token",
defaults: {
grant_type: 'password',
client_id: '8rmz3ts4r7dvr877i2zvrsw66',
scope: 'read write'
}
});
Login.Views.Form = Backbone.View.extend({
model: Login.Model,
el: "#login-form",
events: {
"click #submit-login": function(event) {
event.preventDefault();
this.model = new Login.Model({
username: this.$('#username').val(),
password: this.$('#password').val()
});
//the login API doesn't support json content, so we need to use jquery directly
$.ajax('https://sandbox.catalogchoice.org/oauth2/access_token', {
type: 'POST',
accepts: 'application/json',
dconata: this.model.attributes,
success: function (response) {
console.log(JSON.stringify(response));
},
error: function (response) {
console.log('error');
console.log(response);
}
});
}
}
});
var login = new Login.Views.Form();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment