* Web.csproj:

* T.cs:
* IModule.cs:
* App.master:
* IProvider.cs:
* Error.aspx:
* AOEMail.aspx:
* Login.aspx:
* Index.aspx:
* Admin.aspx:
* yavscModel.csproj:
* WFManager.cs:
* Index.aspx:
* AddRole.aspx:
* Profile.aspx:
* Edit.aspx:
* Register.aspx:
* Index.aspx:
* RoleList.aspx:
* UserList.aspx:
* Validate.aspx:
* RemovePost.aspx:
* Index.aspx:
* BasketImpact.cs:
* Brand.aspx:
* Delete.aspx:
* Create.aspx:
* Backups.aspx:
* HomeController.cs:
* BlogManager.cs:
* Restore.aspx:
* Details.aspx:
* TitleNotFound.aspx:
* Product.aspx:
* AdminController.cs:
* Command.aspx:
* Service.aspx:
* BlogProvider.cs:
* NewProject.aspx:
* Catalog.aspx:
* Restored.aspx:
* BasketController.cs:
* AccountController.cs:
* WorkFlowController.cs:
* BlogsApiController.cs:
* ChangePassword.aspx:
* RemoveRoleQuery.aspx:
* CreateBackup.aspx:
* IContentProvider.cs:
* BackOfficeController.cs:
* FrontOfficeController.cs:
* NpgsqlBlogProvider.cs:
* NpgsqlContentProvider.cs:
* RegistrationPending.aspx:
* ProductCategory.aspx:
* FrontOfficeApiController.cs:
* ChangePasswordSuccess.aspx:
* ReferenceNotFound.aspx: 
* BackupCreated.aspx

Fixes many HTTP 500
Refactoring on the go
This commit is contained in:
Paul Schneider
2014-10-06 03:05:57 +02:00
parent 301dbdcb6d
commit 685c03b37e
59 changed files with 385 additions and 393 deletions

View File

@ -100,11 +100,16 @@ namespace Yavsc.Controllers
return View (model);
case MembershipCreateStatus.Success:
FileInfo fi = new FileInfo (
Server.MapPath(registrationMessage));
Server.MapPath (registrationMessage));
if (!fi.Exists) {
ViewData["Error"] = "Erreur inattendue (pas de corps de message à envoyer)";
ViewData ["Error"] =
string.Format (
"Erreur inattendue (pas de corps de message " +
"à envoyer pour le message de confirmation ({0}))",
registrationMessage);
return View (model);
}
using (StreamReader sr = fi.OpenText()) {
string body = sr.ReadToEnd();
body = body.Replace("<%SiteName%>",YavscHelpers.SiteName);
@ -189,79 +194,8 @@ namespace Yavsc.Controllers
return View (model);
}
[Authorize()]
public ActionResult UserList ()
{
MembershipUserCollection c = Membership.GetAllUsers ();
return View (c);
}
private const string adminRoleName = "Admin";
[Authorize()]
public ActionResult Admin (NewAdminModel model)
{
string currentUser = Membership.GetUser ().UserName;
if (ModelState.IsValid) {
Roles.AddUserToRole (model.UserName, adminRoleName);
ViewData ["Message"] = model.UserName + " was added to the role '" + adminRoleName + "'";
} else {
if (!Roles.RoleExists (adminRoleName)) {
Roles.CreateRole (adminRoleName);
string.Format ("The role '{0}' has just been created. ",
adminRoleName);
}
string [] admins = Roles.GetUsersInRole (adminRoleName);
if (admins.Length > 0) {
if (! admins.Contains (Membership.GetUser ().UserName)) {
ModelState.Remove("UserName");
ModelState.AddModelError("UserName", "You're not administrator!");
return View ("Index");
}
} else {
Roles.AddUserToRole (currentUser, adminRoleName);
admins = new string[] { currentUser };
ViewData ["Message"] += string.Format (
"There was no user in the 'Admin' role. You ({0}) was just added as the firt user in the 'Admin' role. ", currentUser);
}
List<SelectListItem> users = new List<SelectListItem> ();
foreach (MembershipUser u in Membership.GetAllUsers ()) {
var i = new SelectListItem ();
i.Text = string.Format ("{0} <{1}>", u.UserName, u.Email);
i.Value = u.UserName;
users.Add (i);
}
ViewData ["useritems"] = users;
ViewData ["admins"] = admins;
}
return View (model);
}
[Authorize()]
public ActionResult RoleList ()
{
return View (Roles.GetAllRoles ());
}
[Authorize(Roles="Admin")]
public ActionResult RemoveFromRole(string username, string rolename, string returnUrl)
{
Roles.RemoveUserFromRole(username,rolename);
return Redirect(returnUrl);
}
[Authorize(Roles="Admin")]
public ActionResult RemoveUser (string username, string submitbutton)
{
if (submitbutton == "Supprimer") {
Membership.DeleteUser (username);
ViewData["Message"]=
string.Format("utilisateur \"{0}\" supprimé",username);
}
return RedirectToAction("UserList");
}
[Authorize]
[HttpPost]
//public ActionResult UpdateProfile(HttpPostedFileBase Avatar, string Address, string CityAndState, string ZipCode, string Country, string WebSite)
@ -304,30 +238,6 @@ namespace Yavsc.Controllers
return RedirectToAction ("Profile");
}
[Authorize(Roles="Admin")]
public ActionResult RemoveRole (string rolename, string submitbutton)
{
if (submitbutton == "Supprimer")
{
Roles.DeleteRole(rolename);
}
return RedirectToAction("RoleList");
}
[Authorize(Roles="Admin")]
public ActionResult RemoveRoleQuery(string rolename)
{
ViewData["roletoremove"] = rolename;
return View ();
}
[Authorize(Roles="Admin")]
public ActionResult RemoveUserQuery(string username)
{
ViewData["usertoremove"] = username;
return UserList();
}
[Authorize]
public ActionResult Logout (string returnUrl)
{
@ -335,20 +245,9 @@ namespace Yavsc.Controllers
return Redirect(returnUrl);
}
[Authorize(Roles="Admin")]
public ActionResult AddRole ()
{
return View ();
}
[Authorize(Roles="Admin")]
public ActionResult DoAddRole (string rolename)
{
Roles.CreateRole(rolename);
ViewData["Message"] = "Rôle créé : "+rolename;
return View ();
}
[HttpGet]
public ActionResult Validate (string id, string key)
{
MembershipUser u = Membership.GetUser (id, false);

View File

@ -0,0 +1,127 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Web.Security;
using yavscModel.RolesAndMembers;
namespace Yavsc.Controllers.Controllers
{
public class AdminController : Controller
{
[Authorize(Roles="Admin")]
public ActionResult RemoveFromRole(string username, string rolename, string returnUrl)
{
Roles.RemoveUserFromRole(username,rolename);
return Redirect(returnUrl);
}
[Authorize(Roles="Admin")]
public ActionResult RemoveUser (string username, string submitbutton)
{
if (submitbutton == "Supprimer") {
Membership.DeleteUser (username);
ViewData["Message"]=
string.Format("utilisateur \"{0}\" supprimé",username);
}
return RedirectToAction("UserList");
}
[Authorize(Roles="Admin")]
public ActionResult RemoveRole (string rolename, string submitbutton)
{
if (submitbutton == "Supprimer")
{
Roles.DeleteRole(rolename);
}
return RedirectToAction("RoleList");
}
[Authorize(Roles="Admin")]
public ActionResult RemoveRoleQuery(string rolename)
{
ViewData["roletoremove"] = rolename;
return View ();
}
[Authorize(Roles="Admin")]
public ActionResult RemoveUserQuery(string username)
{
ViewData["usertoremove"] = username;
return UserList();
}
//TODO no more than pageSize results per page
[Authorize()]
public ActionResult UserList ()
{
MembershipUserCollection c = Membership.GetAllUsers ();
return View (c);
}
[Authorize(Roles="Admin")]
public ActionResult AddRole ()
{
return View ();
}
[Authorize(Roles="Admin")]
public ActionResult DoAddRole (string rolename)
{
Roles.CreateRole(rolename);
ViewData["Message"] = "Rôle créé : "+rolename;
return View ();
}
[Authorize()]
public ActionResult RoleList ()
{
return View (Roles.GetAllRoles ());
}
private const string adminRoleName = "Admin";
protected override void Initialize (System.Web.Routing.RequestContext requestContext)
{
base.Initialize (requestContext);
if (!Roles.RoleExists (adminRoleName)) {
Roles.CreateRole (adminRoleName);
}
}
[Authorize()]
public ActionResult Admin (NewAdminModel model)
{
string currentUser = Membership.GetUser ().UserName;
if (ModelState.IsValid) {
Roles.AddUserToRole (model.UserName, adminRoleName);
ViewData ["Message"] = model.UserName + " was added to the role '" + adminRoleName + "'";
} else {
// assert (Roles.RoleExists (adminRoleName))
string [] admins = Roles.GetUsersInRole (adminRoleName);
if (admins.Length > 0) {
if (! admins.Contains (Membership.GetUser ().UserName)) {
ModelState.Remove("UserName");
ModelState.AddModelError("UserName", "You're not administrator!");
return View ("Index");
}
} else {
Roles.AddUserToRole (currentUser, adminRoleName);
admins = new string[] { currentUser };
ViewData ["Message"] += string.Format (
"There was no user in the 'Admin' role. You ({0}) was just added as the firt user in the 'Admin' role. ", currentUser);
}
List<SelectListItem> users = new List<SelectListItem> ();
foreach (MembershipUser u in Membership.GetAllUsers ()) {
var i = new SelectListItem ();
i.Text = string.Format ("{0} <{1}>", u.UserName, u.Email);
i.Value = u.UserName;
users.Add (i);
}
ViewData ["useritems"] = users;
ViewData ["admins"] = admins;
}
return View (model);
}
}
}

View File

@ -47,6 +47,10 @@ namespace Yavsc.Controllers
throw new NotImplementedException();
}
[Authorize(Roles="Admin")]
public ActionResult Upgrade(DataAccess datac) {
throw new NotImplementedException();
}
[Authorize(Roles="Admin")]
public ActionResult Restore(DataAccess datac,string backupName,bool dataOnly=true)

View File

@ -2,72 +2,54 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using System.Web.Http;
using yavscModel.WorkFlow;
namespace Yavsc.Controllers
namespace Yavsc.ApiControllers
{
// TODO should mostly be an API Controller
public class BasketController : Controller
public class BasketController : ApiController
{
public ActionResult Index()
{
return View ();
}
/// <summary>
/// Validates the order.
///
/// </summary>
/// <returns><c>true</c>, if order was validated, <c>false</c> otherwise.</returns>
/// <param name="orderid">Orderid.</param>
bool ValidateOrder(long orderid) {
throw new NotImplementedException ();
}
public ActionResult Details(int id)
{
return View ();
}
long CreateOrder(string title,string mesg)
{
throw new NotImplementedException ();
}
public ActionResult Create()
{
throw new NotImplementedException();
// var user = Membership.GetUser ();
// var username = (user != null)?user.UserName:Request.AnonymousID;
// get an existing basket
//return View ();
}
/// <summary>
/// Adds to basket, a product from the catalog, in the user's session.
/// </summary>
/// <returns>The to basket.</returns>
[HttpGet]
public long AddToOrder (long orderid, string prodref,int count, object prodparams=null)
{
//TODO find the basket for Membership.GetUser().UserName
//return WFManager.Write(estid << from the basket, desc, ucost, count, productid);
throw new NotImplementedException ();
}
[HttpPost]
public ActionResult Create(FormCollection collection)
{
try {
return RedirectToAction ("Index");
} catch {
return View ();
}
}
public ActionResult Edit(int id)
{
return View ();
}
[HttpGet]
[Authorize]
public Estimate[] YourEstimates()
{
return WorkFlowProvider.WFManager.GetEstimates (
Membership.GetUser().UserName);
}
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
try {
return RedirectToAction ("Index");
} catch {
return View ();
}
}
public ActionResult Delete(int id)
{
return View ();
}
[HttpPost]
public ActionResult Delete(int id, FormCollection collection)
{
try {
return RedirectToAction ("Index");
} catch {
return View ();
}
}
[HttpGet]
public object Order (BasketImpact bi)
{
return new { c="lmk,", message="Panier impacté", impactRef=bi.ProductRef, count=bi.Count};
}
}
}

View File

@ -15,7 +15,8 @@ namespace Yavsc.ApiControllers
public class BasketImpact
{
public string ProductRef { get; set; }
public int count { get; set; }
public int Count { get; set; }
public string Message { get; set; }
}
}

View File

@ -12,7 +12,16 @@ namespace Yavsc.Controllers
{
public class BlogsApiController : Controller
{
public void Tag (long postid,string tag) {
private const string adminRoleName = "Admin";
protected override void Initialize (System.Web.Routing.RequestContext requestContext)
{
base.Initialize (requestContext);
if (!Roles.RoleExists (adminRoleName)) {
Roles.CreateRole (adminRoleName);
}
}
public long Tag (long postid,string tag) {
BlogEntry e = BlogManager.GetPost (postid);
if (!Roles.IsUserInRole ("Admin")) {
string rguser = Membership.GetUser ().UserName;
@ -23,6 +32,7 @@ namespace Yavsc.Controllers
e.UserName));
}
}
return BlogManager.Tag (postid, tag);
}
public static HttpStatusCodeResult RemovePost(string user, string title) {
@ -44,6 +54,10 @@ namespace Yavsc.Controllers
BlogManager.RemovePost (user, title);
return new HttpStatusCodeResult (200);
}
public void RemoveTag(long tagid) {
throw new NotImplementedException ();
}
}
}

View File

@ -13,6 +13,7 @@ using System.IO;
using System.Net;
using WorkFlowProvider;
using System.Web.Security;
using yavscModel.WorkFlow;
namespace Yavsc.ApiControllers
{
@ -66,17 +67,21 @@ namespace Yavsc.ApiControllers
return result;
}
/// <summary>
/// Adds to basket, a product from the catalog, in the user's session.
/// </summary>
/// <returns>The to basket.</returns>
[Authorize]
[HttpGet]
public long AddToBasket (string prodref,int count, object prodparams=null)
/// <summary>
/// Gets the estimate.
/// </summary>
/// <returns>The estimate.</returns>
/// <param name="estid">Estid.</param>
public Estimate GetEstimate (long estid)
{
//TODO find the basket for Membership.GetUser().UserName
//return WFManager.Write(estid << from the basket, desc, ucost, count, productid);
throw new NotImplementedException ();
Estimate est = WFManager.ContentProvider.GetEstimate (estid);
return est;
}
}
}

View File

@ -10,14 +10,25 @@ using Yavsc.Controllers;
using System.Collections.Generic;
using yavscModel.WorkFlow;
using WorkFlowProvider;
using System.Web.Security;
namespace Yavsc.Controllers
{
public class FrontOfficeController : Controller
{
[HttpGet]
public Estimate GetEstimate(long estid) {
return WFManager.GetEstimate (estid);
[HttpPost]
public ActionResult Estimate(Estimate e)
{
if (ModelState.IsValid) {
if (e.Id > 0) {
Estimate f = WFManager.GetEstimate (e.Id);
if (e.Owner != f.Owner)
if (!Roles.IsUserInRole ("FrontOffice"))
throw new UnauthorizedAccessException ("You're not allowed to modify this estimate");
}
}
return View (e);
}
[AcceptVerbs("GET")]

View File

@ -60,12 +60,12 @@ namespace Yavsc.Controllers
public ActionResult Index ()
{
InitCatalog ();
InitCulture ();
ViewData ["Message"] = string.Format(T.GetString("Welcome")+"({0})",GetType ().Assembly.FullName);
return View ();
}
public void InitCatalog() {
public void InitCulture() {
CultureInfo culture = null;
string defaultCulture = "fr";

View File

@ -17,6 +17,5 @@ namespace Yavsc
{
return Mono.Unix.Catalog.GetString (msgid);
}
}
}

View File

@ -14,6 +14,16 @@ namespace Yavsc.ApiControllers
[HttpControllerConfiguration(ActionValueBinder=typeof(Basic.MvcActionValueBinder))]
public class WorkFlowController : ApiController
{
string adminRoleName="Admin";
protected override void Initialize (HttpControllerContext controllerContext)
{
base.Initialize (controllerContext);
if (!Roles.RoleExists (adminRoleName)) {
Roles.CreateRole (adminRoleName);
}
}
[HttpGet]
[Authorize]
public long CreateEstimate (string title)
@ -21,6 +31,7 @@ namespace Yavsc.ApiControllers
return WFManager.CreateEstimate (
Membership.GetUser().UserName,title);
}
[HttpGet]
[Authorize]
public void DropWritting(long wrid)
@ -49,11 +60,7 @@ namespace Yavsc.ApiControllers
return new { test=string.Format("Hello {0}!",username) };
}
[HttpGet]
public object Order (BasketImpact bi)
{
return new { c="lmk,", message="Panier impacté", impactRef=bi.ProductRef, count=bi.count};
}
[HttpGet]
[Authorize]
@ -63,18 +70,7 @@ namespace Yavsc.ApiControllers
return WFManager.Write(estid, desc, ucost, count, productid);
}
[Authorize]
[HttpGet]
/// <summary>
/// Gets the estimate.
/// </summary>
/// <returns>The estimate.</returns>
/// <param name="estid">Estid.</param>
public Estimate GetEstimate (long estid)
{
Estimate est = WFManager.ContentProvider.GetEstimate (estid);
return est;
}
/*
public object Details(int id)
{