diff --git a/Makefile b/Makefile
index e1ca0257..6e65698c 100644
--- a/Makefile
+++ b/Makefile
@@ -50,7 +50,7 @@ clean:
rm -rf $(DESTDIR)
-rsync-all: rsync_local rsync_test rsync_preprod rsync_prod
+allrsync: rsync_local rsync_test rsync_preprod rsync_prod
sourcepkg:
git archive --format=tar --prefix=yavsc-$(CONFIG)/ $(CONFIG) | bzip2 > yavsc-$(CONFIG).tar.bz2
@@ -67,5 +67,4 @@ htmldoc: xmldoc
docdeploy-prod: htmldoc
rsync -ravu web/htmldoc root@$(PRODHOSTDIR)
-.PHONY: rsync-local
diff --git a/web/ApiControllers/FrontOfficeApiController.cs b/web/ApiControllers/FrontOfficeApiController.cs
index 6535c12b..cac2a6c2 100644
--- a/web/ApiControllers/FrontOfficeApiController.cs
+++ b/web/ApiControllers/FrontOfficeApiController.cs
@@ -89,30 +89,10 @@ namespace Yavsc.ApiControllers
[AcceptVerbs ("GET")]
public HttpResponseMessage EstimateToTex (long id)
{
- string texest = null;
- try {
- texest = estimateToTex (id);
- } catch (TemplateException ex) {
- return new HttpResponseMessage (HttpStatusCode.OK) { Content =
- new ObjectContent (typeof(string),
- ex.Message, new ErrorHtmlFormatter (HttpStatusCode.NotAcceptable,
- LocalizedText.DocTemplateException
- ))
- };
- } catch (Exception ex) {
- return new HttpResponseMessage (HttpStatusCode.OK) { Content =
- new ObjectContent (typeof(string),
- ex.Message, new ErrorHtmlFormatter (HttpStatusCode.InternalServerError,
- LocalizedText.DocTemplateException))
- };
- }
+ string texest = estimateToTex (id);
if (texest == null)
- return new HttpResponseMessage (HttpStatusCode.OK) { Content =
- new ObjectContent (typeof(string), "Not an estimation id:" + id,
- new ErrorHtmlFormatter (HttpStatusCode.NotFound,
- LocalizedText.Estimate_not_found))
- };
-
+ throw new InvalidOperationException (
+ "Not an estimate");
return new HttpResponseMessage () {
Content = new ObjectContent (typeof(string),
texest,
@@ -146,11 +126,11 @@ namespace Yavsc.ApiControllers
/// The to pdf.
/// Estimid.
[AcceptVerbs("GET")]
- public HttpResponseMessage EstimateToPdf (long estimid)
+ public HttpResponseMessage EstimateToPdf (long id)
{
string texest = null;
try {
- texest = estimateToTex (estimid);
+ texest = estimateToTex (id);
} catch (TemplateException ex) {
return new HttpResponseMessage (HttpStatusCode.OK) { Content =
new ObjectContent (typeof(string),
@@ -167,7 +147,7 @@ namespace Yavsc.ApiControllers
}
if (texest == null)
return new HttpResponseMessage (HttpStatusCode.OK) { Content =
- new ObjectContent (typeof(string), "Not an estimation id:" + estimid,
+ new ObjectContent (typeof(string), "Not an estimation id:" + id,
new ErrorHtmlFormatter (HttpStatusCode.NotFound,
LocalizedText.Estimate_not_found))
};
@@ -193,7 +173,7 @@ namespace Yavsc.ApiControllers
/// Model.
[Authorize()]
[ValidateAjaxAttribute]
- public HttpResponseMessage Register ([FromBody] RegisterModel model)
+ public HttpResponseMessage Register ([FromBody] RegisterClientModel model)
{
if (ModelState.IsValid) {
if (model.IsApprouved)
@@ -225,6 +205,14 @@ namespace Yavsc.ApiControllers
case MembershipCreateStatus.Success:
if (!model.IsApprouved)
Yavsc.Helpers.YavscHelpers.SendActivationEmail (user);
+ ProfileBase prtu = ProfileBase.Create (model.UserName);
+ prtu.SetPropertyValue("Name",model.Name);
+ prtu.SetPropertyValue("Address",model.Address);
+ prtu.SetPropertyValue("CityAndState",model.CityAndState);
+ prtu.SetPropertyValue("Mobile",model.Mobile);
+ prtu.SetPropertyValue("Phone",model.Phone);
+ prtu.SetPropertyValue("ZipCode",model.ZipCode);
+
break;
default:
break;
diff --git a/web/ApiControllers/WorkFlowController.cs b/web/ApiControllers/WorkFlowController.cs
index ee96bfb2..9b78b2d0 100644
--- a/web/ApiControllers/WorkFlowController.cs
+++ b/web/ApiControllers/WorkFlowController.cs
@@ -7,11 +7,10 @@ using System.Web.Security;
using Yavsc;
using Yavsc.Model.WorkFlow;
using System.Web.Http;
-using System.Web.Http.Controllers;
-using System.Web.Http.ModelBinding;
using Yavsc.Model.RolesAndMembers;
using Yavsc.Helpers;
using Yavsc.Model;
+using System.Web.Http.Controllers;
namespace Yavsc.ApiControllers
{
@@ -135,18 +134,6 @@ namespace Yavsc.ApiControllers
return new { test=string.Format("Hello {0}!",username) };
}
- private HttpResponseMessage CreateModelStateErrorResponse () {
- // strip exceptions
- Dictionary errs = new Dictionary ();
-
- foreach (KeyValuePair st
- in ModelState.Where (x => x.Value.Errors.Count > 0))
- errs.Add(st.Key, st.Value.Errors.Select(x=>x.ErrorMessage).ToArray());
-
- return Request.CreateResponse(System.Net.HttpStatusCode.BadRequest,
- errs);
- }
-
///
/// Updates the writting.
///
diff --git a/web/CatExts/WebCatalogExtensions.cs b/web/CatExts/WebCatalogExtensions.cs
index e811e836..178db006 100644
--- a/web/CatExts/WebCatalogExtensions.cs
+++ b/web/CatExts/WebCatalogExtensions.cs
@@ -3,8 +3,8 @@ using System.Web;
using System.Text;
using System.Web.Mvc;
using System.Web.Routing;
-using System.Web.Mvc.Html;
using Yavsc.Model.FrontOffice;
+using System.Web.Mvc.Html;
namespace Yavsc.CatExts
{
diff --git a/web/Controllers/AccountController.cs b/web/Controllers/AccountController.cs
index ee4f9095..bcbc9bc9 100644
--- a/web/Controllers/AccountController.cs
+++ b/web/Controllers/AccountController.cs
@@ -5,13 +5,12 @@ using System.Linq;
using System.Net.Mail;
using System.Web;
using System.Web.Configuration;
-using System.Web.Mvc;
-using System.Web.Mvc.Ajax;
using System.Web.Profile;
using System.Web.Security;
using Yavsc;
using Yavsc.Model.RolesAndMembers;
using Yavsc.Helpers;
+using System.Web.Mvc;
namespace Yavsc.Controllers
{
@@ -34,6 +33,7 @@ namespace Yavsc.Controllers
get { return avatarDir; }
set { avatarDir = value; }
}
+
///
/// Index this instance.
///
@@ -68,6 +68,7 @@ namespace Yavsc.Controllers
// If we got this far, something failed, redisplay form
return View (model);
}
+
///
/// Register the specified model and returnUrl.
///
@@ -122,6 +123,7 @@ namespace Yavsc.Controllers
}
return View (model);
}
+
///
/// Changes the password success.
///
@@ -142,6 +144,7 @@ namespace Yavsc.Controllers
{
return View ();
}
+
///
/// Unregister the specified confirmed.
///
@@ -211,70 +214,75 @@ namespace Yavsc.Controllers
ViewData ["UserName"] = logdu;
if (user == null)
user = logdu;
- Profile model= new Profile (ProfileBase.Create (user));
+ Profile model = new Profile (ProfileBase.Create (user));
model.RememberMe = FormsAuthentication.GetAuthCookie (user, true) == null;
return View (model);
}
///
- /// Profile the specified model and AvatarFile.
+ /// Profile the specified user, model and AvatarFile.
///
+ /// User.
/// Model.
/// Avatar file.
[Authorize]
[HttpPost]
- // ASSERT("Membership.GetUser ().UserName is made of simple characters, no slash nor backslash"
- public ActionResult Profile (string username, Profile model, HttpPostedFileBase AvatarFile)
+ public ActionResult Profile (string user, Profile model, HttpPostedFileBase AvatarFile)
{
+ // ASSERT("Membership.GetUser ().UserName is made of simple characters, no slash nor backslash"
string logdu = Membership.GetUser ().UserName;
ViewData ["UserName"] = logdu;
- if (username != logdu)
+ bool editsMyProfile = (user == logdu);
+ if (!editsMyProfile)
if (!Roles.IsUserInRole ("Admin"))
if (!Roles.IsUserInRole ("FrontOffice"))
throw new UnauthorizedAccessException ("Your are not authorized to modify this profile");
- ProfileBase prtoup = ProfileBase.Create (username);
- if (AvatarFile != null) {
+
+ if (AvatarFile != null) {
// if said valid, move as avatar file
// else invalidate the model
if (AvatarFile.ContentType == "image/png") {
string avdir = Server.MapPath (AvatarDir);
- string avpath = Path.Combine (avdir, username + ".png");
+ string avpath = Path.Combine (avdir, user + ".png");
AvatarFile.SaveAs (avpath);
- model.avatar = Request.Url.Scheme+ "://"+ Request.Url.Authority + AvatarDir.Substring (1)+ "/" + username + ".png";
- } else
+ model.avatar = Request.Url.Scheme + "://" + Request.Url.Authority + AvatarDir.Substring (1) + "/" + user + ".png";
+ } else
ModelState.AddModelError ("Avatar",
string.Format ("Image type {0} is not supported (suported formats : {1})",
AvatarFile.ContentType, "image/png"));
}
- /* Sync the property in the Profile model to display :
+ /* Sync the property in the Profile model to display :
* string cAvat = HttpContext.Profile.GetPropertyValue ("avatar") as string;
if (cAvat != null) if (model.avatar == null) model.avatar = cAvat;
*/
if (ModelState.IsValid) {
- if (model.avatar != null)
- prtoup.SetPropertyValue ("avatar", model.avatar);
- prtoup.SetPropertyValue ("Address", model.Address);
- prtoup.SetPropertyValue ("BlogTitle", model.BlogTitle);
- prtoup.SetPropertyValue ("BlogVisible", model.BlogVisible);
- prtoup.SetPropertyValue ("CityAndState", model.CityAndState);
- prtoup.SetPropertyValue ("ZipCode", model.ZipCode);
- prtoup.SetPropertyValue ("Country", model.Country);
- prtoup.SetPropertyValue ("WebSite", model.WebSite);
- prtoup.SetPropertyValue ("Name", model.Name);
- prtoup.SetPropertyValue ("Phone", model.Phone);
- prtoup.SetPropertyValue ("Mobile", model.Mobile);
- prtoup.SetPropertyValue ("BankCode", model.BankCode);
- prtoup.SetPropertyValue ("WicketCode", model.WicketCode);
- prtoup.SetPropertyValue ("AccountNumber", model.AccountNumber);
- prtoup.SetPropertyValue ("BankedKey", model.BankedKey);
- prtoup.SetPropertyValue ("BIC", model.BIC);
- prtoup.SetPropertyValue ("IBAN", model.IBAN);
- prtoup.Save ();
- FormsAuthentication.SetAuthCookie (username, model.RememberMe);
- ViewData ["Message"] = "Profile enregistré, cookie modifié.";
+ ProfileBase prf = ProfileBase .Create (model.UserName);
+ prf.SetPropertyValue ("BlogVisible", model.BlogVisible);
+ prf.SetPropertyValue ("BlogTitle", model.BlogTitle);
+ prf.SetPropertyValue ("avatar", model.avatar);
+ prf.SetPropertyValue ("Address", model.Address);
+ prf.SetPropertyValue ("CityAndState", model.CityAndState);
+ prf.SetPropertyValue ("Country", model.Country);
+ prf.SetPropertyValue ("ZipCode", model.ZipCode);
+ prf.SetPropertyValue ("WebSite", model.WebSite);
+ prf.SetPropertyValue ("Name", model.Name);
+ prf.SetPropertyValue ("Phone", model.Phone);
+ prf.SetPropertyValue ("Mobile", model.Mobile);
+ prf.SetPropertyValue ("BankCode", model.BankCode);
+ prf.SetPropertyValue ("IBAN", model.IBAN);
+ prf.SetPropertyValue ("BIC", model.BIC);
+ prf.SetPropertyValue ("WicketCode", model.WicketCode);
+ prf.SetPropertyValue ("AccountNumber", model.AccountNumber);
+ prf.SetPropertyValue ("BankedKey", model.BankedKey);
+ prf.SetPropertyValue ("gcalid", model.GoogleCalendar);
+ prf.Save ();
+ // only do the following if this profile belongs to current user
+ if (editsMyProfile)
+ FormsAuthentication.SetAuthCookie (user, model.RememberMe);
+ ViewData ["Message"] = "Profile enregistré"+((editsMyProfile)?", cookie modifié.":"");
}
return View (model);
}
@@ -290,7 +298,6 @@ namespace Yavsc.Controllers
return Redirect (returnUrl);
}
-
///
/// Validate the specified id and key.
///
diff --git a/web/Controllers/BlogsController.cs b/web/Controllers/BlogsController.cs
index 63d69fd0..43d6f12a 100644
--- a/web/Controllers/BlogsController.cs
+++ b/web/Controllers/BlogsController.cs
@@ -7,8 +7,6 @@ using System.Net.Mime;
using System.Runtime.Serialization.Formatters.Binary;
using System.Web;
using System.Web.Configuration;
-using System.Web.Mvc;
-using System.Web.Mvc.Ajax;
using System.Web.Profile;
using System.Web.Security;
using CodeKicker.BBCode;
@@ -19,6 +17,7 @@ using Yavsc.Model.Blogs;
using Yavsc.ApiControllers;
using Yavsc.Model.RolesAndMembers;
using System.Net;
+using System.Web.Mvc;
namespace Yavsc.Controllers
{
diff --git a/web/Controllers/GoogleController.cs b/web/Controllers/GoogleController.cs
index 15b6dc1a..ac43f3d0 100644
--- a/web/Controllers/GoogleController.cs
+++ b/web/Controllers/GoogleController.cs
@@ -11,7 +11,6 @@ using System.Web;
using System.Web.Mvc;
using System.Web.Profile;
using System.Web.Security;
-using Mono.Security.Protocol.Tls;
using Newtonsoft.Json;
using Yavsc.Model;
using Yavsc.Model.Google;
diff --git a/web/Controllers/HomeController.cs b/web/Controllers/HomeController.cs
index 9300a66a..357aaff2 100644
--- a/web/Controllers/HomeController.cs
+++ b/web/Controllers/HomeController.cs
@@ -5,16 +5,15 @@ using System.Linq;
using System.Net.Mail;
using System.Web;
using System.Web.Configuration;
-using System.Web.Mvc;
-using System.Web.Mvc.Ajax;
using System.Reflection;
using System.Resources;
using Yavsc.Model;
using Npgsql.Web;
-using ITContentProvider;
using Npgsql.Web.Blog;
using Yavsc.Helpers;
using Yavsc;
+using System.Web.Mvc;
+using ITContentProvider;
namespace Yavsc.Controllers
{
diff --git a/web/Formatters/EstimToPdfFormatter.MSAN.cs b/web/Formatters/EstimToPdfFormatter.MSAN.cs
new file mode 100644
index 00000000..87339dfc
--- /dev/null
+++ b/web/Formatters/EstimToPdfFormatter.MSAN.cs
@@ -0,0 +1,138 @@
+//
+// EstimToPdfFormatter.cs
+//
+// Author:
+// Paul Schneider
+//
+// Copyright (c) 2014 Paul Schneider
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see .
+
+#if MicrosoftAspNetMvc
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Web;
+using System.Web.Profile;
+using Yavsc.Model.RolesAndMembers;
+using Yavsc.Model.WorkFlow;
+using System.Net.Http.Formatting;
+using System.Net.Http.Headers;
+
+namespace Yavsc.Formatters
+{
+ ///
+ /// Estim to pdf formatter.
+ ///
+ public class EstimToPdfFormatter: BufferedMediaTypeFormatter
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public EstimToPdfFormatter ()
+ {
+ SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/pdf"));
+ }
+ ///
+ /// Determines whether this instance can read type the specified type.
+ ///
+ /// true if this instance can read type the specified type; otherwise, false.
+ /// Type.
+ public override bool CanReadType(Type type)
+ {
+ return false;
+ }
+ ///
+ /// Determines whether this instance can write type the specified type.
+ ///
+ /// true if this instance can write type the specified type; otherwise, false.
+ /// Type.
+ public override bool CanWriteType(System.Type type)
+ {
+ if (type == typeof(Estimate))
+ {
+ return true;
+ }
+ else
+ {
+ Type enumerableType = typeof(IEnumerable);
+ return enumerableType.IsAssignableFrom(type);
+ }
+ }
+ public override void WriteToStream (Type type, object value, Stream writeStream, System.Net.Http.HttpContent content)
+ {
+
+ // TODO create a type containing generation parameters, including a template path, and generate from them
+
+ Yavsc.templates.Estim tmpe = new Yavsc.templates.Estim();
+ tmpe.Session = new Dictionary();
+ Estimate e = value as Estimate;
+ tmpe.Session.Add ("estim", e);
+
+ Profile prpro = new Profile (ProfileBase.Create (e.Responsible));
+
+ var pbc = ProfileBase.Create (e.Client);
+ Profile prcli = new Profile (pbc);
+
+ if (!prpro.HasBankAccount || !prcli.IsBillable)
+ throw new Exception("account number for provider, or client not billable.");
+
+ tmpe.Session.Add ("from", prpro);
+ tmpe.Session.Add ("to", prcli);
+ tmpe.Init ();
+
+ string contentStr = tmpe.TransformText ();
+
+ string name = string.Format ("tmpestimtex-{0}", e.Id);
+ string fullname = Path.Combine (
+ HttpRuntime.CodegenDir, name);
+ FileInfo fi = new FileInfo(fullname + ".tex");
+ FileInfo fo = new FileInfo(fullname + ".pdf");
+ using (StreamWriter sw = new StreamWriter (fi.FullName))
+ {
+ sw.Write (contentStr);
+ }
+ using (Process p = new Process ()) {
+ p.StartInfo.WorkingDirectory = HttpRuntime.CodegenDir;
+ p.StartInfo = new ProcessStartInfo ();
+ p.StartInfo.UseShellExecute = false;
+ p.StartInfo.FileName = "/usr/bin/texi2pdf";
+ p.StartInfo.Arguments =
+ string.Format ("--batch --build-dir={2} -o {0} {1}",
+ fo.FullName,
+ fi.FullName,HttpRuntime.CodegenDir);
+ p.Start ();
+ p.WaitForExit ();
+ if (p.ExitCode != 0)
+ throw new Exception ("Pdf generation failed with exit code:" + p.ExitCode);
+ }
+
+ using (StreamReader sr = new StreamReader (fo.FullName)) {
+ byte[] buffer = File.ReadAllBytes (fo.FullName);
+ writeStream.Write(buffer,0,buffer.Length);
+ }
+ fi.Delete();
+ fo.Delete();
+
+ }
+
+
+ }
+}
+
+
+
+#endif
diff --git a/web/Global.asax.cs b/web/Global.asax.cs
index 354ee3dd..a4a20bd1 100644
--- a/web/Global.asax.cs
+++ b/web/Global.asax.cs
@@ -4,12 +4,14 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
-using System.Web.Mvc;
using System.Web.Routing;
using Yavsc.Formatters;
using Yavsc.Model.FrontOffice;
-using System.Web.Http;
using System.Web.SessionState;
+using System.Web.Mvc;
+using System.Web.Http;
+using System.Web.WebPages.Scope;
+using System.Reflection;
namespace Yavsc
{
@@ -86,5 +88,14 @@ namespace Yavsc
return HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath.StartsWith(WebApiConfig.UrlPrefixRelative);
}
+ protected void Application_BeginRequest()
+ {
+ var ob = typeof(
+ AspNetRequestScopeStorageProvider).Assembly.GetType(
+ "System.Web.WebPages.WebPageHttpModule").GetProperty
+ ("AppStartExecuteCompleted",
+ BindingFlags.NonPublic | BindingFlags.Static);
+ ob.SetValue(null, true, null);
+ }
}
}
diff --git a/web/Models/App.master b/web/Models/App.master
index c65d3f50..54b3a9ca 100644
--- a/web/Models/App.master
+++ b/web/Models/App.master
@@ -48,7 +48,7 @@ ViewState["orgtitle"] = T.GetString(Page.Title);
S'authentifier avec son compte Google+
<% } else { %>
- <%= Html.ActionLink(HttpContext.Current.User.Identity.Name, "Profile", "Account", null, new { @class="actionlink" }) %>
+ <%= Html.ActionLink(HttpContext.Current.User.Identity.Name, "Profile", "Account", new { user= HttpContext.Current.User.Identity.Name}, new { @class="actionlink" }) %>
Édition de votre profile
@ <%= Html.ActionLink( YavscHelpers.SiteName, "Index", "Home" ,null, new { @class="actionlink" }) %>
Page d'accueil
diff --git a/web/ValidateAjaxAttribute.cs b/web/ValidateAjaxAttribute.cs
index 759df742..2070c6f4 100644
--- a/web/ValidateAjaxAttribute.cs
+++ b/web/ValidateAjaxAttribute.cs
@@ -21,8 +21,8 @@
using System;
using System.Linq;
using System.Net;
-using System.Web.Http.Filters;
using System.Net.Http;
+using System.Web.Http.Filters;
using System.Web.Http.ModelBinding;
namespace Yavsc
@@ -51,18 +51,16 @@ namespace Yavsc
return errorModel;
}
- ///
- /// Raises the action executing event.
- ///
- /// Action context.
- public override void OnActionExecuting (System.Web.Http.Controllers.HttpActionContext actionContext)
+
+ public override void OnActionExecuted (HttpActionExecutedContext actionExecutedContext)
{
- var modelState = actionContext.ModelState;
+ var modelState = actionExecutedContext.ActionContext.ModelState;
+
if (!modelState.IsValid)
{
- actionContext.Response =
- actionContext.Request.CreateResponse
- (HttpStatusCode.BadRequest,GetErrorModelObject(modelState));
+ actionExecutedContext.Response =
+ actionExecutedContext.Request.CreateResponse (System.Net.HttpStatusCode.BadRequest,
+ ValidateAjaxAttribute.GetErrorModelObject (modelState));
}
}
}
diff --git a/web/Views/Account/Profile.aspx b/web/Views/Account/Profile.aspx
index 54503ee1..1861f860 100644
--- a/web/Views/Account/Profile.aspx
+++ b/web/Views/Account/Profile.aspx
@@ -12,8 +12,9 @@ table.layout TR TD { max-width:40%; }
<%= Html.ValidationSummary() %>
<% using(Html.BeginForm("Profile", "Account", FormMethod.Post, new { enctype = "multipart/form-data" })) %>
<% { %>
+
+ <%= Html.Hidden("UserName",ViewData["ProfileUserName"]) %>
- ">