totem custo: new routes
This commit is contained in:
4
NpgsqlBlogProvider/ChangeLog
Normal file
4
NpgsqlBlogProvider/ChangeLog
Normal file
@ -0,0 +1,4 @@
|
||||
2015-10-10 Paul Schneider <paul@pschneider.fr>
|
||||
|
||||
* NpgsqlBlogProvider.cs:
|
||||
|
@ -28,9 +28,9 @@ namespace Npgsql.Web.Blog
|
||||
{
|
||||
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
||||
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
||||
cmd.CommandText = "insert into bltag (blid,tag) values (@postid,@tag) returning _id";
|
||||
cmd.Parameters.AddWithValue("@tag",tag);
|
||||
cmd.Parameters.AddWithValue("@postid",postid);
|
||||
cmd.CommandText = "insert into bltag (blid,tag) values (:postid,:tag) returning _id";
|
||||
cmd.Parameters.AddWithValue("tag",tag);
|
||||
cmd.Parameters.AddWithValue("postid",postid);
|
||||
cnx.Open ();
|
||||
return (long) cmd.ExecuteScalar ();
|
||||
}
|
||||
@ -43,8 +43,8 @@ namespace Npgsql.Web.Blog
|
||||
{
|
||||
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
||||
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
||||
cmd.CommandText = "delete from bltag where _id = @tagid";
|
||||
cmd.Parameters.AddWithValue("@tagid",tagid);
|
||||
cmd.CommandText = "delete from bltag where _id = :tagid";
|
||||
cmd.Parameters.AddWithValue("tagid",tagid);
|
||||
cnx.Open ();
|
||||
cmd.ExecuteNonQuery ();
|
||||
}
|
||||
@ -63,11 +63,11 @@ namespace Npgsql.Web.Blog
|
||||
using (NpgsqlCommand cmd = cnx.CreateCommand()) {
|
||||
|
||||
cmd.CommandText = "select _id, username, bcontent, modified, posted, visible from comment " +
|
||||
"where applicationname = @appname and postid = @id" +
|
||||
"where applicationname = :appname and postid = :id" +
|
||||
((getHidden) ? " and visible = true ":" ") +
|
||||
"order by posted asc" ;
|
||||
cmd.Parameters.AddWithValue ("@appname", applicationName);
|
||||
cmd.Parameters.AddWithValue ("@id", postid);
|
||||
cmd.Parameters.AddWithValue ("appname", applicationName);
|
||||
cmd.Parameters.AddWithValue ("id", postid);
|
||||
cnx.Open ();
|
||||
using (NpgsqlDataReader rdr = cmd.ExecuteReader()) {
|
||||
while (rdr.Read ()) {
|
||||
@ -100,16 +100,16 @@ namespace Npgsql.Web.Blog
|
||||
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
||||
DateTime now = DateTime.Now;
|
||||
cmd.CommandText =
|
||||
"update blog set modified=@now," +
|
||||
" title = @title," +
|
||||
" bcontent=@content, " +
|
||||
" visible = @visible " +
|
||||
"where _id = @id";
|
||||
cmd.Parameters.AddWithValue ("@now", now);
|
||||
cmd.Parameters.AddWithValue ("@title", title);
|
||||
cmd.Parameters.AddWithValue ("@content", content);
|
||||
cmd.Parameters.AddWithValue ("@visible", visible);
|
||||
cmd.Parameters.AddWithValue ("@id", postid);
|
||||
"update blog set modified=:now," +
|
||||
" title = :title," +
|
||||
" bcontent=:content, " +
|
||||
" visible = :visible " +
|
||||
"where _id = :id";
|
||||
cmd.Parameters.AddWithValue ("now", now);
|
||||
cmd.Parameters.AddWithValue ("title", title);
|
||||
cmd.Parameters.AddWithValue ("content", content);
|
||||
cmd.Parameters.AddWithValue ("visible", visible);
|
||||
cmd.Parameters.AddWithValue ("id", postid);
|
||||
cnx.Open ();
|
||||
cmd.ExecuteNonQuery ();
|
||||
}
|
||||
@ -125,7 +125,7 @@ namespace Npgsql.Web.Blog
|
||||
{
|
||||
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
||||
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
||||
cmd.CommandText = "delete from blog where _id = @id";
|
||||
cmd.CommandText = "delete from blog where _id = :id";
|
||||
cmd.Parameters.AddWithValue ("id", postid);
|
||||
cnx.Open ();
|
||||
cmd.ExecuteNonQuery();
|
||||
@ -149,16 +149,16 @@ namespace Npgsql.Web.Blog
|
||||
using (NpgsqlCommand cmd = cnx.CreateCommand()) {
|
||||
cmd.CommandText = "insert into comment (postid,bcontent," +
|
||||
"modified,posted,visible,username,applicationname)" +
|
||||
"values (@postid,@bcontent,@modified,@posted," +
|
||||
"@visible,@username,@appname) returning _id";
|
||||
cmd.Parameters.AddWithValue ("@postid", postid);
|
||||
cmd.Parameters.AddWithValue ("@bcontent", content);
|
||||
"values (:postid,:bcontent,:modified,:posted," +
|
||||
":visible,:username,:appname) returning _id";
|
||||
cmd.Parameters.AddWithValue ("postid", postid);
|
||||
cmd.Parameters.AddWithValue ("bcontent", content);
|
||||
DateTime now = DateTime.Now;
|
||||
cmd.Parameters.AddWithValue ("@modified", now);
|
||||
cmd.Parameters.AddWithValue ("@posted", now);
|
||||
cmd.Parameters.AddWithValue ("@visible", visible);
|
||||
cmd.Parameters.AddWithValue ("@username", from);
|
||||
cmd.Parameters.AddWithValue ("@appname", applicationName);
|
||||
cmd.Parameters.AddWithValue ("modified", now);
|
||||
cmd.Parameters.AddWithValue ("posted", now);
|
||||
cmd.Parameters.AddWithValue ("visible", visible);
|
||||
cmd.Parameters.AddWithValue ("username", from);
|
||||
cmd.Parameters.AddWithValue ("appname", applicationName);
|
||||
cnx.Open ();
|
||||
return (long) cmd.ExecuteScalar();
|
||||
}
|
||||
@ -237,9 +237,9 @@ namespace Npgsql.Web.Blog
|
||||
using (NpgsqlConnection cnx=new NpgsqlConnection(connectionString))
|
||||
using (NpgsqlCommand cmd = cnx.CreateCommand()) {
|
||||
cmd.CommandText = "select username, title, bcontent, modified, posted, visible, photo from blog " +
|
||||
"where applicationname = @appname and _id = @id";
|
||||
cmd.Parameters.AddWithValue ("@appname", applicationName);
|
||||
cmd.Parameters.AddWithValue ("@id", postid);
|
||||
"where applicationname = :appname and _id = :id";
|
||||
cmd.Parameters.AddWithValue ("appname", applicationName);
|
||||
cmd.Parameters.AddWithValue ("id", postid);
|
||||
cnx.Open ();
|
||||
using (NpgsqlDataReader rdr = cmd.ExecuteReader()) {
|
||||
if (rdr.Read ()) {
|
||||
@ -271,7 +271,7 @@ namespace Npgsql.Web.Blog
|
||||
long postid = 0;
|
||||
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
||||
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
||||
cmd.CommandText = "delete from comment where _id = @id returning postid";
|
||||
cmd.CommandText = "delete from comment where _id = :id returning postid";
|
||||
cmd.Parameters.AddWithValue ("id", cmtid);
|
||||
cnx.Open ();
|
||||
postid = (long) cmd.ExecuteScalar ();
|
||||
@ -463,7 +463,7 @@ namespace Npgsql.Web.Blog
|
||||
using (NpgsqlCommand cmd = cnx.CreateCommand()) {
|
||||
if (readersName != null) {
|
||||
cmd.CommandText = "select _id, title,bcontent, modified," +
|
||||
"posted,username,visible " +
|
||||
"posted,username,visible,photo " +
|
||||
"from blog b left outer join " +
|
||||
"(select count(*)>0 acc, a.post_id pid " +
|
||||
"from blog_access a," +
|
||||
@ -475,7 +475,7 @@ namespace Npgsql.Web.Blog
|
||||
cmd.Parameters.AddWithValue ("uname", readersName);
|
||||
} else {
|
||||
cmd.CommandText = "select _id, title,bcontent,modified," +
|
||||
"posted,username,visible " +
|
||||
"posted,username,visible,photo " +
|
||||
"from blog b left outer join " +
|
||||
"(select count(*)>0 acc, a.post_id pid " +
|
||||
"from blog_access a" +
|
||||
@ -485,18 +485,20 @@ namespace Npgsql.Web.Blog
|
||||
" b.Visible IS TRUE and " +
|
||||
" applicationname = :appname";
|
||||
}
|
||||
cmd.Parameters.AddWithValue ("@appname", applicationName);
|
||||
if ((searchflags & FindBlogEntryFlags.MatchContent) > 0) {
|
||||
cmd.CommandText += " and bcontent like :bcontent";
|
||||
cmd.Parameters.AddWithValue (":bcontent", pattern);
|
||||
}
|
||||
if ((searchflags & FindBlogEntryFlags.MatchTitle) > 0) {
|
||||
cmd.CommandText += " and title like :title";
|
||||
cmd.Parameters.AddWithValue (":title", pattern);
|
||||
}
|
||||
if ((searchflags & FindBlogEntryFlags.MatchUserName) > 0) {
|
||||
cmd.CommandText += " and username like :username";
|
||||
cmd.Parameters.AddWithValue (":username", pattern);
|
||||
cmd.Parameters.AddWithValue ("appname", applicationName);
|
||||
if (pattern != null) {
|
||||
if ((searchflags & FindBlogEntryFlags.MatchContent) > 0) {
|
||||
cmd.CommandText += " and bcontent like :bcontent";
|
||||
cmd.Parameters.AddWithValue ("bcontent", pattern);
|
||||
}
|
||||
if ((searchflags & FindBlogEntryFlags.MatchTitle) > 0) {
|
||||
cmd.CommandText += " and title like :title";
|
||||
cmd.Parameters.AddWithValue ("title", pattern);
|
||||
}
|
||||
if ((searchflags & FindBlogEntryFlags.MatchUserName) > 0) {
|
||||
cmd.CommandText += " and username like :username";
|
||||
cmd.Parameters.AddWithValue ("username", pattern);
|
||||
}
|
||||
}
|
||||
if ((searchflags & FindBlogEntryFlags.MatchInvisible) == 0) {
|
||||
cmd.CommandText += " and visible = true";
|
||||
@ -518,6 +520,11 @@ namespace Npgsql.Web.Blog
|
||||
be.Posted = rdr.GetDateTime (rdr.GetOrdinal ("posted"));
|
||||
be.Modified = rdr.GetDateTime (rdr.GetOrdinal ("modified"));
|
||||
be.Visible = rdr.GetBoolean (rdr.GetOrdinal ("visible"));
|
||||
{
|
||||
int oph = rdr.GetOrdinal ("photo");
|
||||
if (!rdr.IsDBNull (oph))
|
||||
be.Photo = rdr.GetString (oph);
|
||||
}
|
||||
c.Add (be);
|
||||
}
|
||||
totalRecords++;
|
||||
@ -539,10 +546,10 @@ namespace Npgsql.Web.Blog
|
||||
{
|
||||
using (NpgsqlConnection cnx=new NpgsqlConnection(connectionString))
|
||||
using (NpgsqlCommand cmd = cnx.CreateCommand()) {
|
||||
cmd.CommandText = "delete from blog where username = @username and applicationname = @appname and title=@title";
|
||||
cmd.Parameters.AddWithValue ("@username",username);
|
||||
cmd.Parameters.AddWithValue ("@appname", applicationName);
|
||||
cmd.Parameters.AddWithValue ("@title",title);
|
||||
cmd.CommandText = "delete from blog where username = :username and applicationname = :appname and title=:title";
|
||||
cmd.Parameters.AddWithValue ("username",username);
|
||||
cmd.Parameters.AddWithValue ("appname", applicationName);
|
||||
cmd.Parameters.AddWithValue ("title",title);
|
||||
cnx.Open ();
|
||||
cmd.ExecuteNonQuery ();
|
||||
cnx.Close();
|
||||
@ -563,13 +570,6 @@ namespace Npgsql.Web.Blog
|
||||
BlogEntryCollection c = new BlogEntryCollection ();
|
||||
using (NpgsqlConnection cnx=new NpgsqlConnection(connectionString))
|
||||
using (NpgsqlCommand cmd = cnx.CreateCommand()) {
|
||||
|
||||
/*cmd.CommandText = "select blog.* from blog, " +
|
||||
"(select max(posted) lpost, username " +
|
||||
"from blog where applicationname = @appname " +
|
||||
"group by username) as lblog " +
|
||||
"where blog.posted = lblog.lpost and blog.username = lblog.username " ;
|
||||
*/
|
||||
cmd.CommandText = "select * " +
|
||||
"from blog where applicationname = :appname and visible = true " +
|
||||
" order by posted desc limit :len" ;
|
||||
@ -591,6 +591,11 @@ namespace Npgsql.Web.Blog
|
||||
be.Posted = rdr.GetDateTime (rdr.GetOrdinal ("posted"));
|
||||
be.Modified = rdr.GetDateTime (rdr.GetOrdinal ("modified"));
|
||||
be.Visible = true; // because of sql code used
|
||||
{
|
||||
int oph = rdr.GetOrdinal ("photo");
|
||||
if (!rdr.IsDBNull (oph))
|
||||
be.Photo = rdr.GetString (oph);
|
||||
}
|
||||
c.Add (be);
|
||||
}
|
||||
totalRecords++;
|
||||
|
17
web/ChangeLog
Normal file
17
web/ChangeLog
Normal file
@ -0,0 +1,17 @@
|
||||
2015-10-10 Paul Schneider <paul@pschneider.fr>
|
||||
|
||||
* Web.csproj:
|
||||
* Global.asax.cs:
|
||||
* App.master:
|
||||
* Index.aspx:
|
||||
* NoLogin.master:
|
||||
* Title.aspx:
|
||||
* Index.aspx:
|
||||
* YavscHelpers.cs:
|
||||
* Profile.aspx:
|
||||
* UserPosts.aspx:
|
||||
* HomeController.cs:
|
||||
* BlogsController.cs:
|
||||
* GoogleController.cs:
|
||||
* AccountController.cs:
|
||||
|
@ -24,12 +24,6 @@ namespace Yavsc.Controllers
|
||||
/// </summary>
|
||||
public class AccountController : Controller
|
||||
{
|
||||
|
||||
string avatarDir = "~/avatars";
|
||||
string defaultAvatar;
|
||||
string defaultAvatarMimetype;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Avatar the specified user.
|
||||
/// </summary>
|
||||
@ -50,17 +44,7 @@ namespace Yavsc.Controllers
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets or sets the avatar dir.
|
||||
/// This value is past to <c>Server.MapPath</c>,
|
||||
/// it should start with <c>~/</c>, and we assume it
|
||||
/// to be relative to the application path.
|
||||
/// </summary>
|
||||
/// <value>The avatar dir.</value>
|
||||
public string AvatarDir {
|
||||
get { return avatarDir; }
|
||||
set { avatarDir = value; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Index this instance.
|
||||
@ -94,17 +78,7 @@ namespace Yavsc.Controllers
|
||||
ViewData ["returnUrl"] = returnUrl;
|
||||
return View (model);
|
||||
}
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Yavsc.Controllers.BlogsController"/> class.
|
||||
/// </summary>
|
||||
private void GetAvatarConfig ()
|
||||
{
|
||||
string[] defaultAvatarSpec = ConfigurationManager.AppSettings.Get ("DefaultAvatar").Split (';');
|
||||
if (defaultAvatarSpec.Length != 2)
|
||||
throw new ConfigurationErrorsException ("the DefaultAvatar spec should be found as <fileName>;<mime-type> ");
|
||||
defaultAvatar = defaultAvatarSpec [0];
|
||||
defaultAvatarMimetype = defaultAvatarSpec [1];
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Login the specified returnUrl.
|
||||
@ -117,6 +91,10 @@ namespace Yavsc.Controllers
|
||||
return View ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers the form.
|
||||
/// </summary>
|
||||
/// <returns>The form.</returns>
|
||||
public ActionResult RegisterForm()
|
||||
{
|
||||
return View ("Register");
|
||||
@ -307,13 +285,13 @@ namespace Yavsc.Controllers
|
||||
// if said valid, move as avatar file
|
||||
// else invalidate the model
|
||||
if (AvatarFile.ContentType == "image/png") {
|
||||
string avdir = Server.MapPath (AvatarDir);
|
||||
string avdir = Server.MapPath (YavscHelpers.AvatarDir);
|
||||
var di = new DirectoryInfo (avdir);
|
||||
if (!di.Exists)
|
||||
di.Create ();
|
||||
string avpath = Path.Combine (avdir, id + ".png");
|
||||
AvatarFile.SaveAs (avpath);
|
||||
model.avatar = Url.Content( AvatarDir + "/" + id + ".png");
|
||||
model.avatar = Url.Content( YavscHelpers.AvatarDir + "/" + id + ".png");
|
||||
} else
|
||||
ModelState.AddModelError ("Avatar",
|
||||
string.Format ("Image type {0} is not supported (suported formats : {1})",
|
||||
|
@ -29,46 +29,22 @@ namespace Yavsc.Controllers
|
||||
{
|
||||
private string sitename =
|
||||
WebConfigurationManager.AppSettings ["Name"];
|
||||
string avatarDir = "~/avatars";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the avatar dir.
|
||||
/// Index the specified title, pageIndex and pageSize.
|
||||
/// </summary>
|
||||
/// <value>The avatar dir.</value>
|
||||
public string AvatarDir {
|
||||
get { return avatarDir; }
|
||||
set { avatarDir = value; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Index the specified user, title, pageIndex and pageSize.
|
||||
/// </summary>
|
||||
/// <param name="user">User.</param>
|
||||
/// <param name="title">Title.</param>
|
||||
/// <param name="pageIndex">Page index.</param>
|
||||
/// <param name="pageSize">Page size.</param>
|
||||
public ActionResult Index (string user = null, string title = null, int pageIndex = 0, int pageSize = 10)
|
||||
public ActionResult Index (int pageIndex = 0, int pageSize = 10)
|
||||
{
|
||||
if (string.IsNullOrEmpty (user)) {
|
||||
return BlogList (pageIndex, pageSize);
|
||||
} else {
|
||||
MembershipUser u = null;
|
||||
if (Membership.FindUsersByName (user) != null)
|
||||
u = Membership.GetUser (user, false);
|
||||
if (u == null) {
|
||||
ModelState.AddModelError ("Author",
|
||||
string.Format ("Utilisateur inconu : {0}", user));
|
||||
return BlogList ();
|
||||
} else {
|
||||
if (string.IsNullOrEmpty (title))
|
||||
return UserPosts (user, pageIndex, pageSize);
|
||||
return UserPost (user, title, pageIndex, pageSize);
|
||||
}
|
||||
}
|
||||
return BlogList (pageIndex, pageSize);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Chooses the media.
|
||||
/// </summary>
|
||||
/// <returns>The media.</returns>
|
||||
/// <param name="id">Identifier.</param>
|
||||
public ActionResult ChooseMedia(long id)
|
||||
{
|
||||
return View ();
|
||||
@ -87,7 +63,33 @@ namespace Yavsc.Controllers
|
||||
ViewData ["ResultCount"] = totalRecords;
|
||||
ViewData ["PageSize"] = pageSize;
|
||||
ViewData ["PageIndex"] = pageIndex;
|
||||
return View ("Index", new BlogEntryCollection(bs) );
|
||||
var bec = new BlogEntryCollection (bs);
|
||||
return View ("Index", bec );
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Title the specified title, pageIndex and pageSize.
|
||||
/// </summary>
|
||||
/// <param name="title">Title.</param>
|
||||
/// <param name="pageIndex">Page index.</param>
|
||||
/// <param name="pageSize">Page size.</param>
|
||||
///
|
||||
[HttpGet]
|
||||
public ActionResult Title (string id, int pageIndex = 0, int pageSize = 10)
|
||||
{
|
||||
int recordCount;
|
||||
MembershipUser u = Membership.GetUser ();
|
||||
string username = u == null ? null : u.UserName;
|
||||
FindBlogEntryFlags sf = FindBlogEntryFlags.MatchTitle;
|
||||
BlogEntryCollection c =
|
||||
BlogManager.FindPost (username, id, sf, pageIndex, pageSize, out recordCount);
|
||||
var utc = new UTBlogEntryCollection (id);
|
||||
utc.AddRange (c);
|
||||
ViewData ["RecordCount"] = recordCount;
|
||||
ViewData ["PageIndex"] = pageIndex;
|
||||
ViewData ["PageSize"] = pageSize;
|
||||
return View (utc);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -98,33 +100,37 @@ namespace Yavsc.Controllers
|
||||
/// <param name="pageIndex">Page index.</param>
|
||||
/// <param name="pageSize">Page size.</param>
|
||||
[HttpGet]
|
||||
public ActionResult UserPosts (string user, int pageIndex = 0, int pageSize = 10)
|
||||
public ActionResult UserPosts (string id, int pageIndex = 0, int pageSize = 10)
|
||||
{
|
||||
int tr;
|
||||
int recordcount=0;
|
||||
MembershipUser u = Membership.GetUser ();
|
||||
FindBlogEntryFlags sf = FindBlogEntryFlags.MatchUserName;
|
||||
ViewData ["SiteName"] = sitename;
|
||||
ViewData ["BlogUser"] = user;
|
||||
ViewData ["BlogUser"] = id;
|
||||
string readersName = null;
|
||||
ViewData ["PageIndex"] = pageIndex;
|
||||
ViewData ["pageSize"] = pageSize;
|
||||
// displays invisible items when the logged user is also the author
|
||||
if (u != null) {
|
||||
if (u.UserName == user || Roles.IsUserInRole ("Admin"))
|
||||
if (u.UserName == id || Roles.IsUserInRole ("Admin"))
|
||||
sf |= FindBlogEntryFlags.MatchInvisible;
|
||||
readersName = u.UserName;
|
||||
}
|
||||
// find entries
|
||||
BlogEntryCollection c =
|
||||
BlogManager.FindPost (readersName, user, sf, pageIndex, pageSize, out tr);
|
||||
BlogManager.FindPost (readersName, id, sf, pageIndex, pageSize, out recordcount);
|
||||
// Get author's meta data
|
||||
Profile bupr = new Profile (ProfileBase.Create (user));
|
||||
ViewData ["BlogUserProfile"] = bupr;
|
||||
var pr = ProfileBase.Create (id);
|
||||
if (pr != null) {
|
||||
Profile bupr = new Profile (pr);
|
||||
ViewData ["BlogUserProfile"] = bupr;
|
||||
|
||||
// Inform of listing meta data
|
||||
ViewData ["BlogTitle"] = bupr.BlogTitle;
|
||||
ViewData ["Avatar"] = bupr.avatar;
|
||||
ViewData ["RecordCount"] = tr;
|
||||
UUBlogEntryCollection uuc = new UUBlogEntryCollection (user, c);
|
||||
}
|
||||
ViewData ["RecordCount"] = recordcount;
|
||||
UUBlogEntryCollection uuc = new UUBlogEntryCollection (id, c);
|
||||
return View ("UserPosts", uuc);
|
||||
}
|
||||
|
||||
@ -180,7 +186,12 @@ namespace Yavsc.Controllers
|
||||
if (pr == null)
|
||||
// the owner's profile must exist
|
||||
// in order to publish its bills
|
||||
return View ("NotAuthorized");
|
||||
// This should'nt occur, as long as
|
||||
// a profile must exist for each one of
|
||||
// existing user record in data base
|
||||
// and each post is deleted with user deletion
|
||||
// a post => an author => a profile
|
||||
throw new Exception("Unexpected error retreiving author's profile");
|
||||
ViewData ["BlogUserProfile"] = pr;
|
||||
ViewData ["Avatar"] = pr.avatar;
|
||||
ViewData ["BlogTitle"] = pr.BlogTitle;
|
||||
@ -241,7 +252,7 @@ namespace Yavsc.Controllers
|
||||
/// </summary>
|
||||
/// <param name="title">Title.</param>
|
||||
[Authorize]
|
||||
public ActionResult Post ( string title)
|
||||
public ActionResult Post (string title)
|
||||
{
|
||||
string un = Membership.GetUser ().UserName;
|
||||
if (String.IsNullOrEmpty (title))
|
||||
@ -340,26 +351,26 @@ namespace Yavsc.Controllers
|
||||
/// using returnUrl as the URL to return to,
|
||||
/// and confirm as a proof you really know what you do.
|
||||
/// </summary>
|
||||
/// <param name="id">Title.</param>
|
||||
/// <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 RemoveTitle (string user, string title, string returnUrl, bool confirm = false)
|
||||
public ActionResult RemoveTitle (string id, string user, string returnUrl, bool confirm = false)
|
||||
{
|
||||
if (returnUrl == null)
|
||||
if (Request.UrlReferrer != null)
|
||||
returnUrl = Request.UrlReferrer.AbsoluteUri;
|
||||
ViewData ["returnUrl"] = returnUrl;
|
||||
ViewData ["Author"] = user;
|
||||
ViewData ["Title"] = title;
|
||||
ViewData ["Title"] = id;
|
||||
|
||||
if (Membership.GetUser ().UserName != user)
|
||||
if (!Roles.IsUserInRole("Admin"))
|
||||
throw new AuthorizationDenied (user);
|
||||
if (!confirm)
|
||||
return View ("RemoveTitle");
|
||||
BlogManager.RemoveTitle (user, title);
|
||||
BlogManager.RemoveTitle (user, id);
|
||||
if (returnUrl == null)
|
||||
RedirectToAction ("Index", new { user = user });
|
||||
return Redirect (returnUrl);
|
||||
|
@ -26,6 +26,11 @@ namespace Yavsc.Controllers
|
||||
/// </summary>
|
||||
public class GoogleController : Controller
|
||||
{
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
|
||||
private string SetSessionSate ()
|
||||
{
|
||||
string state = "security_token";
|
||||
|
@ -86,6 +86,7 @@ namespace Yavsc.Controllers
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
|
||||
public ActionResult Credits ()
|
||||
{
|
||||
return View ();
|
||||
|
@ -46,29 +46,30 @@ namespace Yavsc
|
||||
routes.IgnoreRoute ("favicon.ico"); // favorite icon
|
||||
routes.IgnoreRoute ("favicon.png"); // favorite icon
|
||||
routes.IgnoreRoute ("robots.txt"); // for search engine robots
|
||||
routes.MapRoute (
|
||||
"View",
|
||||
"v/{title}",
|
||||
new { controller = "Blogs", action = "Index",
|
||||
title=UrlParameter.Optional }
|
||||
);
|
||||
routes.MapRoute (
|
||||
"Blogs",
|
||||
"Blogs/{action}/{user}/{title}",
|
||||
new { controller = "Blogs", action = "Index", user=UrlParameter.Optional, title = UrlParameter.Optional }
|
||||
);
|
||||
routes.MapRoute (
|
||||
"BlogByTitleRO",
|
||||
"Blog/{user}/{title}",
|
||||
new { controller = "Blogs", action = "Index", user=UrlParameter.Optional, title = UrlParameter.Optional }
|
||||
);
|
||||
routes.MapRoute (
|
||||
"BlogById",
|
||||
"B/{action}/{id}",
|
||||
new { controller = "Blogs", action = "UserPost", id = UrlParameter.Optional }
|
||||
"b/{user}/{title}",
|
||||
new { controller = "Blogs", action = "Index",
|
||||
user=UrlParameter.Optional,
|
||||
title=UrlParameter.Optional }
|
||||
);
|
||||
/* routes.MapRoute (
|
||||
"Artistes",
|
||||
"a/{artiste}",
|
||||
new { controller = "Artistes", action = "Index", artiste = UrlParameter.Optional }
|
||||
); */
|
||||
routes.MapRoute (
|
||||
"Default",
|
||||
"{controller}/{action}/{id}",
|
||||
new { controller = defaultController,
|
||||
action = "Index",
|
||||
user=UrlParameter.Optional,
|
||||
id = UrlParameter.Optional }
|
||||
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -157,7 +157,7 @@ namespace Yavsc.Helpers
|
||||
ProfileBase pr = ProfileBase.Create (username);
|
||||
object avpath = null;
|
||||
if (pr != null) avpath = pr.GetPropertyValue("Avatar");
|
||||
if (avpath == null) return "/bfiles/"+username+".png";
|
||||
if (avpath == null) return DefaultAvatar==null?"/bfiles/"+username+".png":DefaultAvatar;
|
||||
string avatarLocation = avpath as string;
|
||||
if (avatarLocation.StartsWith ("~/")) {
|
||||
avatarLocation = helper.RequestContext.HttpContext.Server.MapPath(avatarLocation);
|
||||
@ -165,6 +165,34 @@ namespace Yavsc.Helpers
|
||||
return avatarLocation;
|
||||
|
||||
}
|
||||
|
||||
private static string avatarDir = "~/avatars";
|
||||
private static string defaultAvatar = null;
|
||||
private static string defaultAvatarMimetype = null;
|
||||
public static string DefaultAvatar {
|
||||
get {
|
||||
if (defaultAvatar == null)
|
||||
GetAvatarConfig ();
|
||||
return defaultAvatar;
|
||||
}
|
||||
}
|
||||
public static string AvatarDir {
|
||||
get {
|
||||
return avatarDir;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Yavsc.Controllers.BlogsController"/> class.
|
||||
/// </summary>
|
||||
private static void GetAvatarConfig ()
|
||||
{
|
||||
string[] defaultAvatarSpec = ConfigurationManager.AppSettings.Get ("DefaultAvatar").Split (';');
|
||||
if (defaultAvatarSpec.Length != 2)
|
||||
throw new ConfigurationErrorsException ("the DefaultAvatar spec should be found as <fileName>;<mime-type> ");
|
||||
defaultAvatar = defaultAvatarSpec [0];
|
||||
defaultAvatarMimetype = defaultAvatarSpec [1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Javas the script.
|
||||
/// </summary>
|
||||
|
@ -50,7 +50,7 @@ Yavsc.notice('<%=notice%>');
|
||||
<i class="fa fa-sign-in">Connexion</i>
|
||||
</a>
|
||||
<% } else { %>
|
||||
<a href="/Blog/<%= HttpContext.Current.User.Identity.Name%>" accesskey = "B" class="menuitem" >
|
||||
<a href="<%=Url.Content("~/b/"+HttpContext.Current.User.Identity.Name)%>" accesskey = "B" class="menuitem" >
|
||||
<img src="<%=Url.AvatarUrl(HttpContext.Current.User.Identity.Name)%>" alt="vos billets" class="iconsmall" />
|
||||
<span class="hint">Vos billets</span>
|
||||
</a>
|
||||
|
@ -19,7 +19,7 @@ ViewState["orgtitle"] = T.GetString(Page.Title);
|
||||
<body>
|
||||
<header>
|
||||
<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> -
|
||||
<a href="<%=Request.Url.Scheme + "://" + Request.Url.Authority%>"><%= YavscHelpers.SiteName %></a>
|
||||
</h1>
|
||||
</asp:ContentPlaceHolder><asp:ContentPlaceHolder ID="header" runat="server"></asp:ContentPlaceHolder><%
|
||||
|
@ -28,7 +28,7 @@ table.layout TR TD { max-width:40%; }
|
||||
<%= Html.ValidationMessage("WebSite", "*") %>
|
||||
<br>
|
||||
|
||||
Avatar : <img src="<%=Html.AvatarUrl(HttpContext.Current.User.Identity.Name)%>" alt="avatar" class="iconsmall" />
|
||||
Avatar : <img src="<%=Url.AvatarUrl(HttpContext.Current.User.Identity.Name)%>" alt="avatar" class="iconsmall" />
|
||||
|
||||
<input type="file" id="AvatarFile" name="AvatarFile"/>
|
||||
<%= Html.ValidationMessage("AvatarFile", "*") %>
|
||||
|
@ -1,15 +1,12 @@
|
||||
<%@ Page Title="Blogs - Index" Language="C#" Inherits="System.Web.Mvc.ViewPage<BlogEntryCollection>" MasterPageFile="~/Models/App.master" EnableTheming="True" StylesheetTheme="dark" %>
|
||||
<%@ Page Title="Articles" Language="C#" Inherits="System.Web.Mvc.ViewPage<BlogEntryCollection>" MasterPageFile="~/Models/App.master" EnableTheming="True" StylesheetTheme="dark" %>
|
||||
<%@ Register Assembly="Yavsc.WebControls" TagPrefix="yavsc" Namespace="Yavsc.WebControls" %>
|
||||
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
|
||||
|
||||
<div>
|
||||
<% foreach (var g in Model.GroupByUser()) { %>
|
||||
<h2><a href="<%= Url.Content("~/Blog/"+g.Key) %>" class="actionlink userref">
|
||||
<%=g.Key%></a></h2>
|
||||
<% foreach (var g in Model.GroupByTitle()) { %>
|
||||
<h2><%=Html.ActionLink(g.Key, "Title", "Blogs", new { id = g.Key } , new { @class="userref" } )%></h2>
|
||||
<% foreach (var p in g) { %>
|
||||
<div class="postpreview">
|
||||
<%= Html.ActionLink(p.Title, "UserPost",
|
||||
new { user = g.Key, title = p.Title }, new { @class = "usertitleref" } ) %>
|
||||
<p><%= Html.Markdown(p.Intro,"/bfiles/"+p.Id+"/") %></p>
|
||||
<aside>
|
||||
(Posté le <%=p.Posted.ToString("D") %>)
|
||||
@ -25,7 +22,8 @@
|
||||
<% } %>
|
||||
</div>
|
||||
<form runat="server" id="form1" method="GET">
|
||||
<% rp1.ResultCount = (int) ViewData["ResultCount"];
|
||||
<%
|
||||
rp1.ResultCount = (int) ViewData["ResultCount"];
|
||||
rp1.PageSize = (int) ViewData ["PageSize"];
|
||||
rp1.PageIndex = (int) ViewData["PageIndex"];
|
||||
rp1.None = Html.Translate("no content");
|
||||
|
45
web/Views/Blogs/Title.aspx
Normal file
45
web/Views/Blogs/Title.aspx
Normal file
@ -0,0 +1,45 @@
|
||||
<%@ Page Title="Titre" Language="C#" Inherits="System.Web.Mvc.ViewPage<UTBlogEntryCollection>" MasterPageFile="~/Models/App.master"%>
|
||||
<%@ Register Assembly="Yavsc.WebControls" TagPrefix="yavsc" Namespace="Yavsc.WebControls" %>
|
||||
<asp:Content ContentPlaceHolderID="init" ID="init1" runat="server">
|
||||
<% Title = Model.Title + " - " + YavscHelpers.SiteName; %>
|
||||
</asp:Content>
|
||||
|
||||
<asp:Content ContentPlaceHolderID="overHeaderOne" ID="header1" runat="server">
|
||||
<h1 class="post">
|
||||
<%=Html.ActionLink(Model.Title, "Title", new{id=Model.Title}, null)%>
|
||||
- <a href="<%= Url.Content("~/") %>"><%= YavscHelpers.SiteName %></a>
|
||||
</h1>
|
||||
</asp:Content>
|
||||
|
||||
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
|
||||
<% foreach (BlogEntry e in this.Model) { %>
|
||||
<div class="post<% if (!e.Visible) { %> hiddenpost<% } %>" >
|
||||
<% if (e.Photo!=null) { %><img src="<%=e.Photo%>" alt="" class="photo"><% } %>
|
||||
<%= Html.Markdown(e.Content,"/bfiles/"+e.Id+"/") %>
|
||||
|
||||
<aside class="hidden">(<%= e.Posted.ToString("yyyy/MM/dd") %>
|
||||
- <%= e.Modified.ToString("yyyy/MM/dd") %> <%= e.Visible? "":", Invisible!" %>)
|
||||
<% if (Membership.GetUser()!=null)
|
||||
if (Membership.GetUser().UserName==e.Author || Roles.IsUserInRole("Admin") )
|
||||
{ %>
|
||||
<%= Html.ActionLink("Editer","Edit", new { id = e.Id }, new { @class="actionlink" }) %>
|
||||
<%= Html.ActionLink("Supprimer","RemovePost", new { id = e.Id }, new { @class="actionlink" } ) %>
|
||||
<% } %>
|
||||
</aside>
|
||||
</div>
|
||||
<% } %>
|
||||
<aside>
|
||||
<form runat="server" id="form1" method="GET">
|
||||
<%
|
||||
rp1.ResultCount = (int) ViewData["RecordCount"];
|
||||
rp1.PageIndex = (int) ViewData["PageIndex"];
|
||||
rp1.PageSize = (int) ViewData["PageSize"];
|
||||
%>
|
||||
<yavsc:ResultPages id="rp1" Action = "?pageIndex={0}" runat="server">
|
||||
<None><i>Pas de contenu</i></None>
|
||||
</yavsc:ResultPages>
|
||||
</form>
|
||||
</aside>
|
||||
|
||||
|
||||
</asp:Content>
|
@ -14,8 +14,7 @@
|
||||
<h1 class="blogtitle">
|
||||
<a href="<%=Url.Content("~/Blog/"+Model.Author)%>">
|
||||
<%=Html.Encode(ViewData["BlogTitle"])%></a>
|
||||
-
|
||||
<a href="<%=Request.Url.Scheme + "://" + Request.Url.Authority%>"><%= YavscHelpers.SiteName %></a>
|
||||
- <a href="<%= Url.Content("~/") %>"><%= YavscHelpers.SiteName %></a>
|
||||
</h1>
|
||||
</asp:Content>
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
<%@ Page Title="Home" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/App.master"%>
|
||||
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
|
||||
<div>
|
||||
<%= Html.ActionLink("Les blogs", "Index", "Blogs",null, new { @class="actionlink" }) %>
|
||||
<%= Html.ActionLink("Les articles", "Index", "Blogs", null, new { @class="actionlink" }) %>
|
||||
<%= Html.ActionLink("Contact", "Contact", "Home", null, new { @class="actionlink" }) %>
|
||||
<%= Html.ActionLink("Credits", "Credits", "Home", null, new { @class="actionlink" }) %>
|
||||
<%= Html.ActionLink("Version des librairies", "AssemblyInfo", "Home", null, new { @class="actionlink" }) %>
|
||||
|
@ -428,6 +428,7 @@
|
||||
<Content Include="images\musician-923526_1.nbb.jpg" />
|
||||
<Content Include="images\musician-923526_1.nbb.xs.jpg" />
|
||||
<Content Include="images\musician-923526_1.nbb.xxs.jpg" />
|
||||
<Content Include="Views\Blogs\Title.aspx" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
||||
|
@ -100,6 +100,11 @@ namespace Yavsc.Model.Blogs
|
||||
Provider.UpdatePost (postid, title, content, visible, cids);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the post photo.
|
||||
/// </summary>
|
||||
/// <param name="postid">Postid.</param>
|
||||
/// <param name="photo">Photo.</param>
|
||||
public static void UpdatePostPhoto (long postid, string photo)
|
||||
{
|
||||
Provider.UpdatePostPhoto (postid, photo);
|
||||
|
59
yavscModel/Blogs/UTBlogEntryCollection.cs
Normal file
59
yavscModel/Blogs/UTBlogEntryCollection.cs
Normal file
@ -0,0 +1,59 @@
|
||||
//
|
||||
// UUTBlogEntryCollection.cs
|
||||
//
|
||||
// Author:
|
||||
// Paul Schneider <paul@pschneider.fr>
|
||||
//
|
||||
// Copyright (c) 2015 GNU GPL
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Yavsc.Model.Blogs
|
||||
{
|
||||
/// <summary>
|
||||
/// Unique User and Title blog entry collection.
|
||||
/// </summary>
|
||||
public class UTBlogEntryCollection : BlogEntryCollection {
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Yavsc.Model.Blogs.UTBlogEntryCollection"/> class.
|
||||
/// </summary>
|
||||
/// <param name="title">Title.</param>
|
||||
public UTBlogEntryCollection(string title) : base() {
|
||||
_title = title;
|
||||
}
|
||||
|
||||
private string _title;
|
||||
/// <summary>
|
||||
/// Gets the title.
|
||||
/// </summary>
|
||||
/// <value>The title.</value>
|
||||
public string Title { get { return _title; } }
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="System.String"/> that represents the current <see cref="Yavsc.Model.Blogs.UUTBlogEntryCollection"/>.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="System.String"/> that represents the current <see cref="Yavsc.Model.Blogs.UUTBlogEntryCollection"/>.</returns>
|
||||
public override string ToString ()
|
||||
{
|
||||
return string.Format ("[UUTBlogEntryCollection: " +
|
||||
"Title={0} Count={2}]", Title, Count);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -32,7 +32,6 @@ namespace Yavsc.Model.Blogs
|
||||
/// </summary>
|
||||
/// <param name="username">Username.</param>
|
||||
/// <param name="title">Title.</param>
|
||||
/// <param name="items">Items.</param>
|
||||
public UUTBlogEntryCollection(string username, string title) : base(username) {
|
||||
_title = title;
|
||||
}
|
||||
|
8
yavscModel/ChangeLog
Normal file
8
yavscModel/ChangeLog
Normal file
@ -0,0 +1,8 @@
|
||||
2015-10-10 Paul Schneider <paul@pschneider.fr>
|
||||
|
||||
* YavscModel.csproj:
|
||||
* BlogManager.cs:
|
||||
* UTBlogEntryCollection.cs:
|
||||
* UUTBlogEntryCollection.cs:
|
||||
* FileSystemManager.cs:
|
||||
|
@ -166,7 +166,7 @@ namespace Yavsc.Model.FileSystem
|
||||
return (di.GetFiles ());
|
||||
}
|
||||
|
||||
public IEnumerable<FileInfo> GetFiles (string username, string subdir)
|
||||
public IEnumerable<FileInfo> GetFiles (string username, string subdir, bool createNonExistent = false)
|
||||
{
|
||||
string path = Prefix;
|
||||
if (subdir != null) {
|
||||
@ -174,6 +174,9 @@ namespace Yavsc.Model.FileSystem
|
||||
path = Path.Combine (Prefix, subdir);
|
||||
}
|
||||
DirectoryInfo di = new DirectoryInfo (path);
|
||||
if (createNonExistent)
|
||||
if (!di.Exists)
|
||||
di.Create ();
|
||||
return (di.GetFiles ());
|
||||
}
|
||||
|
||||
|
@ -171,6 +171,7 @@
|
||||
<Compile Include="RolesAndMembers\UserManager.cs" />
|
||||
<Compile Include="Circles\CircleBase.cs" />
|
||||
<Compile Include="Blogs\MarkdownHelper.cs" />
|
||||
<Compile Include="Blogs\UTBlogEntryCollection.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
Reference in New Issue
Block a user