Cleanup oauth

This commit is contained in:
Tom MacWright
2012-12-05 15:03:58 -05:00
parent bc91f4956d
commit 4968634f12
4 changed files with 35 additions and 32 deletions
+1
View File
@@ -33,6 +33,7 @@
<script src='js/id/renderer/markers.js'></script>
<script src='js/id/ui/inspector.js'></script>
<script src='js/id/ui/modal.js'></script>
<script src='js/id/ui/confirm.js'></script>
<script src='js/id/ui/commit.js'></script>
<script src='js/id/ui/loading.js'></script>
<script src='js/id/ui/userpanel.js'></script>
+2 -2
View File
@@ -91,9 +91,9 @@ iD.Connection = function() {
}
function authenticate(callback) {
return oauth.authenticate(function() {
return oauth.authenticate(function(err, res) {
event.auth();
if (callback) callback();
if (callback) callback(err, res);
});
}
+2 -11
View File
@@ -96,7 +96,7 @@ window.iD = function(container) {
})) > 0;
if (has_changes) {
connection.authenticate(function() {
connection.authenticate(function(err) {
var modal = iD.modal();
modal.select('.content')
.classed('commit-modal', true)
@@ -108,17 +108,8 @@ window.iD = function(container) {
.on('save', save));
});
} else {
var modal = iD.modal();
modal.select('.modal').classed('modal-alert', true);
modal.select('.content')
.append('p')
iD.confirm().select('.description')
.text('You don\'t have any changes to save.');
modal.select('.content')
.append('button')
.text('OK')
.on('click', function() {
modal.remove();
});
}
});
+30 -19
View File
@@ -57,8 +57,8 @@ iD.OAuth = function() {
oauth.authenticate = function(callback) {
if (oauth.authenticated()) return callback();
oauth.logout();
oauth.logout();
o = timenonce(o);
var url = baseurl + '/oauth/request_token';
@@ -66,9 +66,14 @@ iD.OAuth = function() {
ohauth.baseString('POST', url, o));
var l = iD.loading('contacting openstreetmap...');
ohauth.xhr('POST', url, o, null, {}, function(err, xhr) {
if (err) callback(err);
l.remove();
var resp = ohauth.stringQs(xhr.response);
authorize(ohauth.stringQs(xhr.response));
});
function authorize(resp) {
token('oauth_request_token_secret', resp.oauth_token_secret);
var modal = iD.modal();
modal
@@ -82,26 +87,32 @@ iD.OAuth = function() {
.on('load', function() {
if (this.contentWindow.location.search) {
var search = this.contentWindow.location.search,
oauth_token = ohauth.stringQs(search.slice(1)),
url = baseurl + '/oauth/access_token';
o = timenonce(o);
oauth_token = ohauth.stringQs(search.slice(1));
modal.remove();
o.oauth_token = oauth_token.oauth_token;
var request_token_secret = token('oauth_request_token_secret');
o.oauth_signature = ohauth.signature(oauth_secret, request_token_secret,
ohauth.baseString('POST', url, o));
var l = iD.loading('contacting openstreetmap...');
ohauth.xhr('POST', url, o, null, {}, function(err, xhr) {
l.remove();
var access_token = ohauth.stringQs(xhr.response);
token('oauth_token', access_token.oauth_token);
token('oauth_token_secret', access_token.oauth_token_secret);
callback();
});
get_access_token(oauth_token);
}
});
});
}
function get_access_token(oauth_token) {
var url = baseurl + '/oauth/access_token';
o = timenonce(o);
o.oauth_token = oauth_token.oauth_token;
var request_token_secret = token('oauth_request_token_secret');
o.oauth_signature = ohauth.signature(oauth_secret, request_token_secret,
ohauth.baseString('POST', url, o));
var l = iD.loading('contacting openstreetmap...');
ohauth.xhr('POST', url, o, null, {}, function(err, xhr) {
if (err) callback(err);
l.remove();
var access_token = ohauth.stringQs(xhr.response);
token('oauth_token', access_token.oauth_token);
token('oauth_token_secret', access_token.oauth_token_secret);
callback();
});
}
};
oauth.api = function(_) {