This commit is contained in:
Jeena Paradies 2012-11-12 04:05:08 +01:00
parent acd3968fa9
commit 3507f34210
6 changed files with 124 additions and 55 deletions

View file

@ -34,8 +34,14 @@ function(HostApp, Paths, Hmac) {
}
Oauth.prototype.authenticate = function() {
this.entity = HostApp.stringForKey("entity");
this.requestProfileURL(this.entity);
var entity = HostApp.stringForKey("entity");
if (entity && (entity.startsWith("http://") || entity.startsWith("https://"))) {
this.entity = entity;
this.requestProfileURL(this.entity);
} else {
HostApp.authentificationDidNotSucceed("The entity should start with https:// or http://");
}
}
Oauth.prototype.apiRoot = function() {
@ -44,9 +50,18 @@ function(HostApp, Paths, Hmac) {
Oauth.prototype.requestProfileURL = function (entity) {
var those = this;
Paths.findProfileURL(entity, function(profile_url) {
those.register(profile_url);
});
Paths.findProfileURL(entity,
function(profile_url) {
if (profile_url && (profile_url.startsWith("http://") || profile_url.startsWith("https:(("))) {
those.register(profile_url);
} else {
HostApp.authentificationDidNotSucceed("Could not find profile for: " + entity);
}
},
function(errorMessage) { // error callback
HostApp.authentificationDidNotSucceed("Could not find profile for: " + entity);
}
);
}
Oauth.prototype.register = function (url) {

View file

@ -76,6 +76,22 @@ define(function() {
}
}
HostApp.alertTitleWithMessage = function(title, message) {
if (OS_TYPE == "mac") {
controller.alertTitle_withMessage_(message);
} else {
controller.alertTitleWithMessage(message);
}
}
HostApp.authentificationDidNotSucceed = function(errorMessage) {
if (OS_TYPE == "mac") {
controller.authentificationDidNotSucceed_(errorMessage);
} else {
controller.authentificationDidNotSucceed(errorMessage);
}
}
return HostApp;
});

View file

@ -60,7 +60,7 @@ function(jQuery, HostApp, Hmac) {
});
}
Paths.findProfileURL = function(entity, callback) {
Paths.findProfileURL = function(entity, callback, errorCallback) {
jQuery.ajax({
url: entity,
@ -80,11 +80,14 @@ function(jQuery, HostApp, Hmac) {
if (profile_url) {
callback(profile_url);
} else {
if(errorCallback) errorCallback(entity + " has no profile URL");
}
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert("findProfileURL " + xhr.statusText + " (" + entity + "): " + xhr.responseText);
if (errorCallback) errorCallback(xhr.statusText + " - " + xhr.responseText)
}
});
}