Created
July 12, 2012 13:13
-
-
Save krusty/3098025 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
$(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