Fixes the avatar Url from the menu

vnext
Paul Schneider 9 years ago
parent 303aaa5e1b
commit 424bb157e3
9 changed files with 71 additions and 27 deletions

@ -1,7 +1,7 @@
VERSION=1.1 VERSION=1.1
CONFIG=Debug CONFIG=Debug
LDYDESTDIR=build/web/$(CONFIG) LDYDESTDIR=dist/web/$(CONFIG)
COPYUNCHANGED="false" COPYUNCHANGED="false"
HOST_rsync_yavsc=lua.pschneider.fr HOST_rsync_yavsc=lua.pschneider.fr
@ -37,7 +37,7 @@ rsync_% : DESTDIR = $(DESTDIR_$@)
rsync_% : deploy rsync_% : deploy
echo "!Deploying to $(HOST)!" echo "!Deploying to $(HOST)!"
$(RSYNCCMD) build/web/$(CONFIG)/ root@$(HOST):$(DESTDIR) $(RSYNCCMD) dist/web/$(CONFIG)/ root@$(HOST):$(DESTDIR)
build: build:
xbuild /p:Configuration=$(CONFIG) /t:Build Yavsc.sln xbuild /p:Configuration=$(CONFIG) /t:Build Yavsc.sln

@ -40,7 +40,7 @@ namespace Yavsc.Admin
*/ */
Exec ("pg_dump", string.Format ( Exec ("pg_dump", string.Format (
"-f {0} -Ft -h {1} -U {2} -p {3} {4}", "-f {0} -Ft -h {1} -U {2} -p {3} {4}",
fileName, da.Host, da.Dbuser, da.Port, da.Dbname ),e); fileName, da.Host, da.DbUser, da.Port, da.DbName ),e);
return e; return e;
} }
@ -74,7 +74,7 @@ namespace Yavsc.Admin
var t = new TaskOutput (); var t = new TaskOutput ();
Exec ("pg_restore", (dataOnly?"-a ":"")+string.Format ( Exec ("pg_restore", (dataOnly?"-a ":"")+string.Format (
"-1 -Ft -O -h {0} -U {1} -p {2} -d {3} {4}", "-1 -Ft -O -h {0} -U {1} -p {2} -d {3} {4}",
da.Host, da.Dbuser, da.Port, da.Dbname, fileName ),t); da.Host, da.DbUser, da.Port, da.DbName, fileName ),t);
/* /*
Exec ("pg_restore", (dataOnly?"-a ":"")+string.Format ( Exec ("pg_restore", (dataOnly?"-a ":"")+string.Format (
"-1 -w -Fd -O -h {0} -U {1} -p {2} -d {3} {4}", "-1 -w -Fd -O -h {0} -U {1} -p {2} -d {3} {4}",
@ -149,7 +149,7 @@ namespace Yavsc.Admin
var t = new TaskOutput (); var t = new TaskOutput ();
Exec ("pg_restore", string.Format ( Exec ("pg_restore", string.Format (
"-a -w -Fd -O -h {0} -U {1} -p {2} -d {3} {4}", "-a -w -Fd -O -h {0} -U {1} -p {2} -d {3} {4}",
da.Host, da.Dbuser, da.Port, da.Dbname, fileName ),t); da.Host, da.DbUser, da.Port, da.DbName, fileName ),t);
return t; return t;
} }
} }

@ -1,7 +1,7 @@
using System; using System;
using System.ComponentModel; using System.ComponentModel;
namespace Yavsc.Admin namespace Yavsc.Model.Admin
{ {
/// <summary> /// <summary>
/// Export. /// Export.
@ -9,7 +9,7 @@ namespace Yavsc.Admin
public class Export: TaskOutput public class Export: TaskOutput
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Yavsc.Admin.Export"/> class. /// Initializes a new instance of the <see cref="Yavsc.Model.Admin.Export"/> class.
/// </summary> /// </summary>
public Export () public Export ()
{ {

@ -146,18 +146,30 @@ namespace Yavsc.ApiControllers
try try
{ {
// Read the form data. // Read the form data.
await Request.Content.ReadAsMultipartAsync(provider) ; IEnumerable<HttpContent> data = await Request.Content.ReadAsMultipartAsync(provider) ;
var invalidChars = Path.GetInvalidFileNameChars(); var invalidChars = Path.GetInvalidFileNameChars();
List<string> bodies = new List<string>(); List<string> parts = new List<string>();
List<string> text = new List<string>();
foreach (string fkey in provider.BodyPartFileNames.Keys) // filter files on their mime type
foreach ( var httpAudioContent in data
) {
string [] mimetype = httpAudioContent.Headers.ContentType.MediaType.Split('/');
switch (mimetype[0]) {
case "application": break;
case "text": break;
case "image": break;
case "audio": break;
case "video": break;
}
}
foreach (string fkey in text)
{ {
string filename = provider.BodyPartFileNames[fkey]; string filename = provider.BodyPartFileNames[fkey];
string nicename=fkey; string nicename=fkey;
if (fkey.StartsWith("\"") && fkey.EndsWith("\"") && fkey.Length > 2)
nicename = fkey.Substring(1,fkey.Length-2);
var filtered = new string (nicename.Where( x=> !invalidChars.Contains(x)).ToArray()); var filtered = new string (nicename.Where( x=> !invalidChars.Contains(x)).ToArray());
FileInfo fi = new FileInfo(filtered); FileInfo fi = new FileInfo(filtered);
@ -165,6 +177,10 @@ namespace Yavsc.ApiControllers
FileInfo fp = new FileInfo (Path.Combine(root,filename)); FileInfo fp = new FileInfo (Path.Combine(root,filename));
if (fi.Exists) fi.Delete(); if (fi.Exists) fi.Delete();
fp.MoveTo(fi.FullName); fp.MoveTo(fi.FullName);
// Get the mime type
using (Process p = new Process ()) { using (Process p = new Process ()) {
p.StartInfo.WorkingDirectory = root; p.StartInfo.WorkingDirectory = root;
p.StartInfo = new ProcessStartInfo (); p.StartInfo = new ProcessStartInfo ();
@ -187,14 +203,14 @@ namespace Yavsc.ApiControllers
); );
} }
} }
bodies.Add(fo.OpenText().ReadToEnd()); parts.Add(fo.OpenText().ReadToEnd());
fi.Delete(); fi.Delete();
fo.Delete(); fo.Delete();
} }
return Request.CreateResponse(HttpStatusCode.OK,string.Join("---\n",bodies),new SimpleFormatter("text/plain")); return Request.CreateResponse(HttpStatusCode.OK,string.Join("---\n",parts),new SimpleFormatter("text/plain"));
} }
catch (System.Exception e) catch (System.Exception e)

@ -33,21 +33,25 @@ namespace Yavsc.Controllers
/// <summary> /// <summary>
/// Avatar the specified user. /// Avatar the specified user.
/// </summary> /// </summary>
/// <param name="user">User.</param> /// <param name="id">User.</param>
[AcceptVerbs (HttpVerbs.Get)] [AcceptVerbs (HttpVerbs.Get)]
public ActionResult Avatar (string user) public ActionResult Avatar (string id)
{ {
ProfileBase pr = ProfileBase.Create (user); if (id == null)
string avpath = (string ) pr.GetPropertyValue("Avatar") ; return new EmptyResult ();
ProfileBase pr = ProfileBase.Create (id);
var avpath = pr.GetPropertyValue("Avatar");
if (avpath == null) { if (avpath == null) {
FileInfo fia = new FileInfo (Server.MapPath (defaultAvatar)); FileInfo fia = new FileInfo (Server.MapPath (defaultAvatar));
return File (fia.OpenRead (), defaultAvatarMimetype); return File (fia.OpenRead (), defaultAvatarMimetype);
} }
if (avpath.StartsWith ("~/")) { string avatarLocation = avpath as string;
avpath = Server.MapPath (avpath); if (avatarLocation.StartsWith ("~/")) {
avatarLocation = Server.MapPath (avatarLocation);
} }
WebRequest wr = WebRequest.Create (avpath); WebRequest wr = WebRequest.Create (avatarLocation);
FileContentResult res; FileContentResult res;
using (WebResponse resp = wr.GetResponse ()) { using (WebResponse resp = wr.GetResponse ()) {
using (Stream str = resp.GetResponseStream ()) { using (Stream str = resp.GetResponseStream ()) {
@ -303,6 +307,8 @@ namespace Yavsc.Controllers
// ASSERT("Membership.GetUser ().UserName is made of simple characters, no slash nor backslash" // ASSERT("Membership.GetUser ().UserName is made of simple characters, no slash nor backslash"
string logdu = Membership.GetUser ().UserName; string logdu = Membership.GetUser ().UserName;
if (string.IsNullOrWhiteSpace (id))
id = logdu;
ViewData ["UserName"] = id; ViewData ["UserName"] = id;
bool editsMyName = (string.Compare(id,logdu)==0); bool editsMyName = (string.Compare(id,logdu)==0);
if (!editsMyName) if (!editsMyName)
@ -310,15 +316,17 @@ namespace Yavsc.Controllers
if (!Roles.IsUserInRole ("FrontOffice")) if (!Roles.IsUserInRole ("FrontOffice"))
throw new UnauthorizedAccessException ("Your are not authorized to modify this profile"); throw new UnauthorizedAccessException ("Your are not authorized to modify this profile");
if (AvatarFile != null) { if (AvatarFile != null) {
// if said valid, move as avatar file // if said valid, move as avatar file
// else invalidate the model // else invalidate the model
if (AvatarFile.ContentType == "image/png") { if (AvatarFile.ContentType == "image/png") {
string avdir = Server.MapPath (AvatarDir); string avdir = Server.MapPath (AvatarDir);
var di = new DirectoryInfo (avdir);
if (!di.Exists)
di.Create ();
string avpath = Path.Combine (avdir, id + ".png"); string avpath = Path.Combine (avdir, id + ".png");
AvatarFile.SaveAs (avpath); AvatarFile.SaveAs (avpath);
model.avatar = Request.Url.Scheme + "://" + Request.Url.Authority + AvatarDir.Substring (1) + "/" + id + ".png"; model.avatar = Url.Content( AvatarDir + "/" + id + ".png");
} else } else
ModelState.AddModelError ("Avatar", ModelState.AddModelError ("Avatar",
string.Format ("Image type {0} is not supported (suported formats : {1})", string.Format ("Image type {0} is not supported (suported formats : {1})",
@ -336,7 +344,9 @@ namespace Yavsc.Controllers
if (AvatarFile != null) { if (AvatarFile != null) {
prf.SetPropertyValue ("Avatar", model.avatar); prf.SetPropertyValue ("Avatar", model.avatar);
} else { } else {
model.avatar = (string) prf.GetPropertyValue ("Avatar"); var av = prf.GetPropertyValue ("Avatar");
if (av != null)
model.avatar = av as string;
} }
prf.SetPropertyValue ("Address", model.Address); prf.SetPropertyValue ("Address", model.Address);
prf.SetPropertyValue ("CityAndState", model.CityAndState); prf.SetPropertyValue ("CityAndState", model.CityAndState);

@ -42,6 +42,10 @@ namespace Yavsc.Controllers
datac.BackupPrefix = Server.MapPath (datac.BackupPrefix); datac.BackupPrefix = Server.MapPath (datac.BackupPrefix);
DataManager mgr = new DataManager (datac); DataManager mgr = new DataManager (datac);
TaskOutput tcdb = mgr.CreateDb (); TaskOutput tcdb = mgr.CreateDb ();
ViewData ["DbName"] = datac.DbName;
ViewData ["DbUser"] = datac.DbUser;
ViewData ["Host"] = datac.Host;
ViewData ["Port"] = datac.Port;
return View ("Created", tcdb); return View ("Created", tcdb);
} }
} }

@ -150,7 +150,7 @@ namespace Yavsc.Helpers
/// <returns>The URL.</returns> /// <returns>The URL.</returns>
/// <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.WebPages.Html.HtmlHelper helper, string username) { public static string AvatarUrl (this System.Web.Mvc.UrlHelper helper, string username) {
ProfileBase pr = ProfileBase.Create (username); ProfileBase pr = ProfileBase.Create (username);
var a = pr.GetPropertyValue("Avatar") ; var a = pr.GetPropertyValue("Avatar") ;
if (a == null || a is DBNull) return "/avatars/" + helper.Encode(username)+".png"; if (a == null || a is DBNull) return "/avatars/" + helper.Encode(username)+".png";

@ -0,0 +1,14 @@
<%@ Page Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="initContent" ContentPlaceHolderID="init" runat="server">
</asp:Content>
<asp:Content ID="headContent" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="overHeaderOneContent" ContentPlaceHolderID="overHeaderOne" runat="server">
</asp:Content>
<asp:Content ID="headerContent" ContentPlaceHolderID="header" runat="server">
</asp:Content>
<asp:Content ID="MainContentContent" ContentPlaceHolderID="MainContent" runat="server">
kjgftkgt
</asp:Content>
<asp:Content ID="MASContentContent" ContentPlaceHolderID="MASContent" runat="server">
</asp:Content>
Loading…