Fixes the avatar Url from the menu

vnext
Paul Schneider 9 years ago
parent 424bb157e3
commit e540aed51c
3 changed files with 17 additions and 25 deletions

@ -24,7 +24,7 @@ namespace Yavsc.Controllers
/// </summary> /// </summary>
public class AccountController : Controller public class AccountController : Controller
{ {
string avatarDir = "~/avatars"; string avatarDir = "~/avatars";
string defaultAvatar; string defaultAvatar;
string defaultAvatarMimetype; string defaultAvatarMimetype;
@ -37,20 +37,7 @@ namespace Yavsc.Controllers
[AcceptVerbs (HttpVerbs.Get)] [AcceptVerbs (HttpVerbs.Get)]
public ActionResult Avatar (string id) public ActionResult Avatar (string id)
{ {
if (id == null) string avatarLocation = Url.AvatarUrl (id);
return new EmptyResult ();
ProfileBase pr = ProfileBase.Create (id);
var avpath = pr.GetPropertyValue("Avatar");
if (avpath == null) {
FileInfo fia = new FileInfo (Server.MapPath (defaultAvatar));
return File (fia.OpenRead (), defaultAvatarMimetype);
}
string avatarLocation = avpath as string;
if (avatarLocation.StartsWith ("~/")) {
avatarLocation = Server.MapPath (avatarLocation);
}
WebRequest wr = WebRequest.Create (avatarLocation); WebRequest wr = WebRequest.Create (avatarLocation);
FileContentResult res; FileContentResult res;
using (WebResponse resp = wr.GetResponse ()) { using (WebResponse resp = wr.GetResponse ()) {

@ -151,10 +151,18 @@ namespace Yavsc.Helpers
/// <param name="helper">Helper.</param> /// <param name="helper">Helper.</param>
/// <param name="username">Username.</param> /// <param name="username">Username.</param>
public static string AvatarUrl (this System.Web.Mvc.UrlHelper helper, string username) { public static string AvatarUrl (this System.Web.Mvc.UrlHelper helper, string username) {
if (username == null)
return null;
ProfileBase pr = ProfileBase.Create (username); ProfileBase pr = ProfileBase.Create (username);
var a = pr.GetPropertyValue("Avatar") ; object avpath = null;
if (a == null || a is DBNull) return "/avatars/" + helper.Encode(username)+".png"; if (pr != null) avpath = pr.GetPropertyValue("Avatar");
return helper.Encode ((string)a); if (avpath == null) return "/bfiles/"+username+".png";
string avatarLocation = avpath as string;
if (avatarLocation.StartsWith ("~/")) {
avatarLocation = helper.RequestContext.HttpContext.Server.MapPath(avatarLocation);
}
return avatarLocation;
} }
} }
} }

@ -80,15 +80,12 @@ $(document).ready(function(){
<asp:ContentPlaceHolder ID="overHeaderOne" runat="server"> <asp:ContentPlaceHolder ID="overHeaderOne" runat="server">
<h1><a href="<%= Html.Encode(Request.Url.AbsoluteUri.ToString()) %>"> <%=ViewState["orgtitle"]%> </a> <h1><a href="<%= Url.Content("~/") %>"> <%=ViewState["orgtitle"]%> </a></h1>
<span> -
<a href="<%= Url.Content("~/") %>"><%= YavscHelpers.SiteName %></a>
</span></h1>
</asp:ContentPlaceHolder> </asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="header" runat="server"></asp:ContentPlaceHolder> <asp:ContentPlaceHolder ID="header" runat="server"></asp:ContentPlaceHolder>
<div id="error"><%= (ViewData["Error"]!=null)? Html.Encode(ViewData["Error"]) : "" %></div> <div id="error"><%= (ViewData["Error"]!=null)? Html.Encode(ViewData["Error"]) : "" %></div>
<div id="message"><%= Html.Encode(ViewData["Message"]) %></div> <div id="message"><%= Html.Encode(ViewData["Message"]) %></div>
@ -104,7 +101,7 @@ $(document).ready(function(){
</a> </a>
<% } else { %> <% } else { %>
<a href="/Blog/<%= HttpContext.Current.User.Identity.Name%>" accesskey = "B" class="menuitem"> <a href="/Blog/<%= HttpContext.Current.User.Identity.Name%>" accesskey = "B" class="menuitem">
<img src="<%=Html.AvatarUrl(HttpContext.Current.User.Identity.Name)%>" alt="vos billets" class="iconsmall" /> <img src="<%=Url.AvatarUrl(HttpContext.Current.User.Identity.Name)%>" alt="vos billets" class="iconsmall" />
<div class="hint">Vos billets</div> <div class="hint">Vos billets</div>
</a> </a>
<a href="<%= Url.Content("~/Account/Profile/" + HttpContext.Current.User.Identity.Name) %>" accesskey="L" class="menuitem"> <a href="<%= Url.Content("~/Account/Profile/" + HttpContext.Current.User.Identity.Name) %>" accesskey="L" class="menuitem">

Loading…