Merge pull request #1282 from umbraco/temp-U4-7332

U4-7332 Default gravatar link broken
This commit is contained in:
Shannon Deminick
2016-05-25 12:00:38 +02:00
4 changed files with 81 additions and 36 deletions

View File

@@ -19,7 +19,7 @@ function MainController($scope, $rootScope, $location, $routeParams, $timeout, $
{ value: "assets/img/application/logo@3x.png" }
];
$scope.touchDevice = appState.getGlobalState("touchDevice");
$scope.removeNotification = function (index) {
notificationsService.remove(index);
@@ -28,12 +28,12 @@ function MainController($scope, $rootScope, $location, $routeParams, $timeout, $
$scope.closeDialogs = function (event) {
//only close dialogs if non-link and non-buttons are clicked
var el = event.target.nodeName;
var els = ["INPUT","A","BUTTON"];
var els = ["INPUT", "A", "BUTTON"];
if(els.indexOf(el) >= 0){return;}
if (els.indexOf(el) >= 0) { return; }
var parents = $(event.target).parents("a,button");
if(parents.length > 0){
if (parents.length > 0) {
return;
}
@@ -49,31 +49,31 @@ function MainController($scope, $rootScope, $location, $routeParams, $timeout, $
var evts = [];
//when a user logs out or timesout
evts.push(eventsService.on("app.notAuthenticated", function() {
evts.push(eventsService.on("app.notAuthenticated", function () {
$scope.authenticated = null;
$scope.user = null;
}));
//when the app is read/user is logged in, setup the data
evts.push(eventsService.on("app.ready", function (evt, data) {
$scope.authenticated = data.authenticated;
$scope.user = data.user;
updateChecker.check().then(function(update){
if(update && update !== "null"){
if(update.type !== "None"){
updateChecker.check().then(function(update) {
if (update && update !== "null") {
if (update.type !== "None") {
var notification = {
headline: "Update available",
message: "Click to download",
sticky: true,
type: "info",
url: update.url
headline: "Update available",
message: "Click to download",
sticky: true,
type: "info",
url: update.url
};
notificationsService.add(notification);
}
}
})
});
//if the user has changed we need to redirect to the root so they don't try to continue editing the
//last item in the URL (NOTE: the user id can equal zero, so we cannot just do !data.lastUserId since that will resolve to true)
@@ -91,38 +91,40 @@ function MainController($scope, $rootScope, $location, $routeParams, $timeout, $
if ($scope.user.emailHash) {
//let's attempt to load the avatar, it might not exist or we might not have
// internet access so we'll detect it first
$http.get("https://www.gravatar.com/avatar/" + $scope.user.emailHash + ".jpg?s=64&d=404")
// internet access, well get an empty string back
$http.get(umbRequestHelper.getApiUrl("gravatarApiBaseUrl", "GetCurrentUserGravatarUrl"))
.then(
function successCallback(response) {
$("#avatar-img").fadeTo(1000, 0, function () {
$scope.$apply(function () {
//this can be null if they time out
if ($scope.user && $scope.user.emailHash) {
var avatarBaseUrl = "https://www.gravatar.com/avatar/",
hash = $scope.user.emailHash;
function successCallback(response) {
// if we can't download the gravatar for some reason, an null gets returned, we cannot do anything
if (response.data !== "null") {
$("#avatar-img").fadeTo(1000, 0, function () {
$scope.$apply(function () {
//this can be null if they time out
if ($scope.user && $scope.user.emailHash) {
var avatarBaseUrl = "https://www.gravatar.com/avatar/",
hash = $scope.user.emailHash;
$scope.avatar = [
{ value: avatarBaseUrl + hash + ".jpg?s=30&d=mm" },
{ value: avatarBaseUrl + hash + ".jpg?s=60&d=mm" },
{ value: avatarBaseUrl + hash + ".jpg?s=90&d=mm" }
];
}
$scope.avatar = [
{ value: avatarBaseUrl + hash + ".jpg?s=30&d=mm" },
{ value: avatarBaseUrl + hash + ".jpg?s=60&d=mm" },
{ value: avatarBaseUrl + hash + ".jpg?s=90&d=mm" }
];
}
});
$("#avatar-img").fadeTo(1000, 1);
});
$("#avatar-img").fadeTo(1000, 1);
});
}
}, function errorCallback(response) {
//cannot load it from the server so we cannot do anything
});
}
}));
evts.push(eventsService.on("app.ysod", function(name, error) {
evts.push(eventsService.on("app.ysod", function (name, error) {
$scope.ysodOverlay = {
view: "ysod",
error: error,
show: true
show: true
};
}));

View File

@@ -291,6 +291,10 @@ namespace Umbraco.Web.Editors
"logApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl<LogController>(
controller => controller.GetEntityLog(0))
},
{
"gravatarApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl<GravatarController>(
controller => controller.GetCurrentUserGravatarUrl())
},
{
"memberApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl<MemberController>(
controller => controller.GetByKey(Guid.Empty))

View File

@@ -0,0 +1,38 @@
using System;
using System.Net;
using Umbraco.Core;
using Umbraco.Web.Mvc;
namespace Umbraco.Web.Editors
{
/// <summary>
/// API controller used for getting Gravatar urls
/// </summary>
[PluginController("UmbracoApi")]
public class GravatarController : UmbracoAuthorizedJsonController
{
public string GetCurrentUserGravatarUrl()
{
var userService = Services.UserService;
var user = userService.GetUserById(UmbracoContext.Security.CurrentUser.Id);
var gravatarHash = user.Email.ToMd5();
var gravatarUrl = "https://www.gravatar.com/avatar/" + gravatarHash;
// Test if we can reach this URL, will fail when there's network or firewall errors
var request = (HttpWebRequest)WebRequest.Create(gravatarUrl);
// Require response within 10 seconds
request.Timeout = 10000;
try
{
using ((HttpWebResponse)request.GetResponse()) { }
}
catch (Exception)
{
// There was an HTTP or other error, return an null instead
return null;
}
return gravatarUrl;
}
}
}

View File

@@ -318,6 +318,7 @@
<Compile Include="Editors\BackOfficeNotificationsController.cs" />
<Compile Include="Editors\EditorValidationResolver.cs" />
<Compile Include="Editors\EditorValidator.cs" />
<Compile Include="Editors\GravatarController.cs" />
<Compile Include="IHttpContextAccessor.cs" />
<Compile Include="Models\ContentEditing\GetAvailableCompositionsFilter.cs" />
<Compile Include="Editors\IEditorValidator.cs" />