Navigation Menu

Skip to content

Commit

Permalink
disabled avatar validation fetching by default, in favor of a CSS-onl…
Browse files Browse the repository at this point in the history
…y solution for broken avatars
  • Loading branch information
albogdano committed Aug 19, 2021
1 parent 1f71ee2 commit 820664d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/main/java/com/erudika/scoold/utils/HttpUtils.java
Expand Up @@ -196,6 +196,12 @@ public static String getCookieValue(HttpServletRequest req, String name) {

/**
* Fetches an avatar at a given URL.
*
* /////////////////////////////////////
* THIS CODE IS CAUSING MORE PROBLEMS
* THAN IT SOLVES! CONSIDER DELETING!!!
* ////////////////////////////////////
*
* @param url image URL
* @param req request
* @param res response
Expand All @@ -206,6 +212,9 @@ public static void getAvatar(String url, HttpServletRequest req, HttpServletResp
getDefaultAvatarImage(res);
return;
}
if (!ScooldUtils.getInstance().isAvatarValidationEnabled()) {
return;
}
HttpGet get = new HttpGet(url);
// attach auth cookie to requests for locally uploaded avatars - without this custom avatars will not be loaded!
if (StringUtils.startsWithIgnoreCase(url, ScooldServer.getServerURL())) {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/erudika/scoold/utils/ScooldUtils.java
Expand Up @@ -745,6 +745,10 @@ public boolean isDarkModeEnabled() {
return Config.getConfigBoolean("dark_mode_enabled", true);
}

public boolean isAvatarValidationEnabled() {
return Config.getConfigBoolean("avatar_validation_enabled", false); // this should be deleted in the future
}

public String getFooterHTML() {
return Config.getConfigParam("footer_html", "");
}
Expand Down Expand Up @@ -1328,6 +1332,14 @@ public static String getGravatar(Profile profile) {
}
}

public String getFullAvatarURL(Profile profile) {
if (profile == null) {
return getGravatar("");
}
return isAvatarValidationEnabled() ? PEOPLELINK + "/avatar?url=" + Utils.urlEncode(profile.getPicture()) :
profile.getPicture();
}

public void clearSession(HttpServletRequest req, HttpServletResponse res) {
if (req != null) {
HttpUtils.removeStateParam(AUTH_COOKIE, req, res);
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/checkstyle.xml
Expand Up @@ -10,7 +10,9 @@
<property name="fileExtensions" value="java, xml, properties, js, html, css" />
</module>

<module name="FileLength"/>
<module name="FileLength">
<property name="max" value="4000"/>
</module>

<module name="TreeWalker">
<module name="RegexpSinglelineJava">
Expand Down
17 changes: 17 additions & 0 deletions src/main/resources/static/styles/style.css
Expand Up @@ -347,6 +347,19 @@ img.profile-pic {
.user-card img.profile-pic {
width: 100%;
}
img.profile-pic:before {
content: " ";
display: block;
position: absolute;
box-sizing: border-box;
background-image: url('/people/avatar');
background-clip: initial;
background-attachment: initial;
background-position: initial;
background-size: cover;
height: calc(100% - 11%);
width: calc(100% - 71%);
}
.card .card-website a:not(.btn):not(.btn-large):not(.btn-small):not(.btn-large):not(.btn-floating) {
margin-right: 0;
text-transform: lowercase;
Expand Down Expand Up @@ -523,6 +536,10 @@ img.profile-pic {
.approve-answer-btn {
padding: 0 10px;
}
img.profile-pic:before {
height: calc(100% - 14%);
width: calc(100% - 79%);
}
}

/**** FEEL FREE TO MODIFY THIS THEME ****/
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/macro.vm
Expand Up @@ -988,7 +988,7 @@ $utils.formatDate($date, $format, $currentLocale)
<div class="progress ajaxwait $!{hidden}"><div class="indeterminate"></div></div>
#end
#####################################
#macro(profilepic $user)#if($user && $user.picture && $user.picture.matches("^(http:|https:).*"))$peoplelink/avatar?url=$utils.urlEncode($!user.picture)#elseif($user && $user.picture && $user.picture.matches("^(data:).*"))$user.picture #else $!imageslink/anon.svg #end#end
#macro(profilepic $user)#if($user && $user.picture && $user.picture.matches("^(http:|https:).*"))$scooldUtils.getFullAvatarURL($user)#elseif($user && $user.picture && $user.picture.matches("^(data:).*"))$user.picture #else $!imageslink/anon.svg #end#end
#####################################
#macro(infostrip )
#if ($request.getParameter("success"))
Expand Down

0 comments on commit 820664d

Please sign in to comment.