* Web.config:
* Web.csproj: * Web.config: * Blog.cs: * Index.aspx: * BBCodeHelper.cs: * Comment.cs: * yavscModel.csproj: * BlogEntry.cs: * UserPost.aspx: * UserPosts.aspx: * Estimate.cs: * RemovePost.aspx: * TitleNotFound.aspx: * BlogProvider.cs: * AccountController.cs: * BlogsApiController.cs: * WorkFlowController.cs: * BlogEditEntryModel.cs: * FindBlogEntryFlags.cs: * BlogEntryCollection.cs: * Comment.cs: * BlogEditCommentModel.cs: * NpgsqlBlogProvider.cs: * NpgsqlContentProvider.cs: * BlogEntry.cs: * NpgsqlBlogProvider.csproj: * NpgsqlMembershipProvider.cs: * FindBlogEntryFlags.cs: * BlogEntryCollection.cs: * BlogHelper.cs: refactoring: moving code from NpgsqlBlogProvider to yavscModel.Blogs * BlogManager.cs: NpgsqlBlogProvider/BlogHelper.cs * BlogsController.cs: a successfull confirmed removal * Blog.cs: refactoring
This commit is contained in:
parent
bba917dcc0
commit
9fc7f82531
29 changed files with 213 additions and 114 deletions
|
|
@ -163,7 +163,7 @@ namespace Yavsc.Controllers
|
|||
|
||||
// ChangePassword will throw an exception rather
|
||||
// than return false in certain failure scenarios.
|
||||
bool changePasswordSucceeded;
|
||||
bool changePasswordSucceeded=false;
|
||||
try {
|
||||
var users = Membership.FindUsersByName (model.Username);
|
||||
|
||||
|
|
@ -172,9 +172,10 @@ namespace Yavsc.Controllers
|
|||
changePasswordSucceeded = user.ChangePassword (model.OldPassword, model.NewPassword);
|
||||
} else {
|
||||
changePasswordSucceeded = false;
|
||||
ModelState.AddModelError ("Username", "The user name not found.");
|
||||
}
|
||||
} catch (Exception) {
|
||||
changePasswordSucceeded = false;
|
||||
} catch (Exception ex) {
|
||||
ViewData ["Error"] = ex.ToString ();
|
||||
}
|
||||
|
||||
if (changePasswordSucceeded) {
|
||||
|
|
|
|||
36
web/Controllers/BlogsApiController.cs
Normal file
36
web/Controllers/BlogsApiController.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
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 Npgsql.Web.Blog;
|
||||
using yavscModel.Blogs;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
public class BlogsApiController : Controller
|
||||
{
|
||||
public static HttpStatusCodeResult RemovePost(string user, string title) {
|
||||
if (!Roles.IsUserInRole ("Admin")) {
|
||||
string rguser = Membership.GetUser ().UserName;
|
||||
if (rguser != user) {
|
||||
throw new AccessViolationException (
|
||||
string.Format (
|
||||
"Vous n'avez pas le droit de suprimer des billets du Blog de {0}",
|
||||
user));
|
||||
}
|
||||
}
|
||||
BlogEntry e = BlogManager.GetPost (user, title);
|
||||
if (e == null) {
|
||||
return new HttpNotFoundResult (
|
||||
string.Format("Aucun post portant le titre \"{0}\" pour l'utilisateur {1}",
|
||||
title, user));
|
||||
}
|
||||
BlogManager.RemovePost (user, title);
|
||||
return new HttpStatusCodeResult (200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -13,9 +13,9 @@ using System.Web.Profile;
|
|||
using System.Web.Security;
|
||||
using CodeKicker.BBCode;
|
||||
using Npgsql.Web.Blog;
|
||||
using Npgsql.Web.Blog.DataModel;
|
||||
using Yavsc;
|
||||
using yavscModel;
|
||||
using yavscModel.Blogs;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
|
|
@ -206,6 +206,8 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
return string.Format ("{0}'s blog", user);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Comment (BlogEditCommentModel model) {
|
||||
string username = Membership.GetUser ().UserName;
|
||||
ViewData ["SiteName"] = sitename;
|
||||
|
|
@ -231,30 +233,22 @@ namespace Yavsc.Controllers
|
|||
return File (fia.OpenRead (), defaultAvatarMimetype);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the specified blog entry, by its author and title,
|
||||
/// using returnUrl as the URL to return to,
|
||||
/// and confirm as a proof you really know what you do.
|
||||
/// </summary>
|
||||
/// <param name="user">User.</param>
|
||||
/// <param name="title">Title.</param>
|
||||
/// <param name="returnUrl">Return URL.</param>
|
||||
/// <param name="confirm">If set to <c>true</c> confirm.</param>
|
||||
[Authorize]
|
||||
public ActionResult Remove (string user, string title, string returnUrl)
|
||||
public ActionResult RemovePost (string user, string title, string returnUrl, bool confirm=false)
|
||||
{
|
||||
if (!Roles.IsUserInRole ("Admin")) {
|
||||
string rguser = Membership.GetUser ().UserName;
|
||||
if (rguser != user) {
|
||||
ModelState.AddModelError (
|
||||
"Title", string.Format (
|
||||
"Vous n'avez pas de droits sur le Blog de {0}",
|
||||
user));
|
||||
return Return (returnUrl);
|
||||
}
|
||||
}
|
||||
BlogEntry e = BlogManager.GetPost (user, title);
|
||||
if (e == null) {
|
||||
ModelState.AddModelError (
|
||||
"Title",
|
||||
string.Format (
|
||||
"Aucun post portant le titre \"{0}\" pour l'utilisateur {1}",
|
||||
title, user));
|
||||
return Return (returnUrl);
|
||||
}
|
||||
BlogManager.RemovePost (user, title);
|
||||
return Return (returnUrl);
|
||||
if (!confirm)
|
||||
return View ("RemovePost");
|
||||
HttpStatusCodeResult res = BlogsApiController.RemovePost (user,title);
|
||||
return (res.StatusCode==200? Return(returnUrl):res);
|
||||
}
|
||||
|
||||
private ActionResult Return (string returnUrl)
|
||||
|
|
|
|||
|
|
@ -35,6 +35,17 @@ 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)
|
||||
{
|
||||
return WFManager.ContentProvider.GetEstimate (estid);
|
||||
}
|
||||
/*
|
||||
public object Details(int id)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue