From 57a473aff87b5f028a00805a87ac32091d453803 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Tue, 6 Jan 2015 10:15:24 +0100 Subject: [PATCH] Many changes : * JsonReaderError.aspx: display a nice json conversion error * CalendarEntryList.cs: new Google data for the calendar entries * JsonReaderError.cs: Json error model * README.md: Documentation url * NpgsqlBlogProvider.cs: Update the blog post title * BlogsController.cs: - Updating the blog post title - bug fix rendering the avatar * FrontOfficeController.cs: - the client cannot modify its estimation * GoogleController.cs: - implementing the calendar entries retrieval * HomeController.cs: - the home start page from configuration parameter named "StartPage" * Global.asax.cs: - back to a clean global.asax * style.css: showing the main area with a background transparent color * Post.aspx: Bug fix: the message was displayed two times (we keep the one from app.master) * UserPost.aspx: the blog title comes from the poster profile found in ViewData * DateQuery.aspx: implementing the date query * Web.config: the start page now comes from Web.config * Web.csproj: the Sql db creation script should not be deployed, neither as package.config * BlogManager.cs: updating the blog post title * BlogProvider.cs: yavscModel/Blogs/BlogManager.cs * YavscModel.csproj: new cs files to compile * App.master: returning from the Google login --- NpgsqlBlogProvider/NpgsqlBlogProvider.cs | 10 ++++-- README.md | 3 ++ web/Controllers/BlogsController.cs | 13 +++---- web/Controllers/FrontOfficeController.cs | 1 - web/Controllers/GoogleController.cs | 44 ++++++++++++++++-------- web/Controllers/HomeController.cs | 4 ++- web/Global.asax.cs | 14 ++------ web/Models/App.master | 2 +- web/Theme/style.css | 14 +++++--- web/Views/Blogs/Post.aspx | 6 ++-- web/Views/Blogs/UserPost.aspx | 9 ++++- web/Views/Google/DateQuery.aspx | 9 ++++- web/Views/Google/JsonReaderError.aspx | 12 +++++++ web/Web.config | 5 ++- web/Web.csproj | 5 +-- yavscModel/Blogs/BlogManager.cs | 4 +-- yavscModel/Blogs/BlogProvider.cs | 2 +- yavscModel/Google/CalendarEntryList.cs | 30 ++++++++++++++++ yavscModel/Google/JsonReaderError.cs | 31 +++++++++++++++++ yavscModel/YavscModel.csproj | 2 ++ 20 files changed, 163 insertions(+), 57 deletions(-) create mode 100644 web/Views/Google/JsonReaderError.aspx create mode 100644 yavscModel/Google/CalendarEntryList.cs create mode 100644 yavscModel/Google/JsonReaderError.cs diff --git a/NpgsqlBlogProvider/NpgsqlBlogProvider.cs b/NpgsqlBlogProvider/NpgsqlBlogProvider.cs index c9cbbdc5..e37b63c6 100644 --- a/NpgsqlBlogProvider/NpgsqlBlogProvider.cs +++ b/NpgsqlBlogProvider/NpgsqlBlogProvider.cs @@ -68,15 +68,19 @@ namespace Npgsql.Web.Blog } return cmts.ToArray(); } - public override void UpdatePost (long postid, string content, bool visible) + public override void UpdatePost (long postid, string title, string content, bool visible) { using (NpgsqlConnection cnx = new NpgsqlConnection(connectionString)) using (NpgsqlCommand cmd = cnx.CreateCommand()) { DateTime now = DateTime.Now; cmd.CommandText = - "update blog set modified=@now, bcontent=@content, " + - "visible = @visible where _id = @id"; + "update blog set modified=@now," + + " title = @title," + + " bcontent=@content, " + + " visible = @visible " + + "where _id = @id"; cmd.Parameters.Add ("@now", now); + cmd.Parameters.Add ("@title", title); cmd.Parameters.Add ("@content", content); cmd.Parameters.Add ("@visible", visible); cmd.Parameters.Add ("@id", postid); diff --git a/README.md b/README.md index fa8aef1e..8c10a396 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,6 @@ yavsc Yet Another Very Small Company For the moment, overall a little home made blogging system. + +See for more information + diff --git a/web/Controllers/BlogsController.cs b/web/Controllers/BlogsController.cs index 46ab5ab6..5fb79f75 100644 --- a/web/Controllers/BlogsController.cs +++ b/web/Controllers/BlogsController.cs @@ -122,6 +122,7 @@ namespace Yavsc.Controllers return View ("TitleNotFound"); ViewData ["BlogUserProfile"] = pr; ViewData ["BlogTitle"] = pr.BlogTitle; + ViewData ["HasAvatar"] = pr.avatar != null; MembershipUser u = Membership.GetUser (); if (u != null) ViewData ["UserName"] = u.UserName; @@ -159,8 +160,6 @@ namespace Yavsc.Controllers string un = Membership.GetUser ().UserName; if (String.IsNullOrEmpty (user)) user = un; - if (un != user) - ViewData ["Message"] = string.Format ("Vous n'êtes pas {0}!", user); ViewData ["UserName"] = un; return View (new BlogEditEntryModel { Title = title }); } @@ -187,7 +186,7 @@ namespace Yavsc.Controllers ViewData ["BlogUser"] = Membership.GetUser ().UserName; if (ModelState.IsValid) { if (!model.Preview) { - BlogManager.UpdatePost (model.Id, model.Content, model.Visible); + BlogManager.UpdatePost (model.Id, model.Title, model.Content, model.Visible); return UserPost (model); } } @@ -247,11 +246,9 @@ namespace Yavsc.Controllers return File (fia.OpenRead (), defaultAvatarMimetype); } WebRequest wr = WebRequest.Create(avpath); - using (WebResponse resp = wr.GetResponse ()) { - using (Stream str = resp.GetResponseStream ()) { - return File (str, resp.ContentType); - } - } + WebResponse resp = wr.GetResponse (); + Stream str = resp.GetResponseStream (); + return File (str, resp.ContentType); } /// diff --git a/web/Controllers/FrontOfficeController.cs b/web/Controllers/FrontOfficeController.cs index 7a7e5e84..f96a8ae5 100644 --- a/web/Controllers/FrontOfficeController.cs +++ b/web/Controllers/FrontOfficeController.cs @@ -71,7 +71,6 @@ namespace Yavsc.Controllers } if (ModelState.IsValid) { if (username != model.Responsible - && username != model.Client && !Roles.IsUserInRole ("FrontOffice")) throw new UnauthorizedAccessException ("You're not allowed to modify this estimate"); diff --git a/web/Controllers/GoogleController.cs b/web/Controllers/GoogleController.cs index 01548060..d1080c14 100644 --- a/web/Controllers/GoogleController.cs +++ b/web/Controllers/GoogleController.cs @@ -26,22 +26,22 @@ namespace Yavsc.Controllers // 2015-01-01T10:00:00-07:00 // private string API_KEY="AIzaSyBV_LQHb22nGgjNvFzZwnQHjao3Q7IewRw"; - private string getPeopleUri = "https://www.googleapis.com/plus/v1/people"; - private string getCalListUri = "https://www.googleapis.com/calendar/v3/users/me/calendarList"; - private string getCalEntriesUri = "https://developers.google.com/google-apps/calendar/v3/reference/events/list"; + private static string getPeopleUri = "https://www.googleapis.com/plus/v1/people"; + private static string getCalListUri = "https://www.googleapis.com/calendar/v3/users/me/calendarList"; + private static string getCalEntriesUri = "https://www.googleapis.com/calendar/v3/calendars/{0}/events"; - private string CLIENT_ID = "325408689282-6bekh7p3guj4k0f3301a6frf025cnrk1.apps.googleusercontent.com"; - private string CLIENT_SECRET = "MaxYcvJJCs2gDGvaELZbzwfL"; + private static string CLIENT_ID = "325408689282-6bekh7p3guj4k0f3301a6frf025cnrk1.apps.googleusercontent.com"; + private static string CLIENT_SECRET = "MaxYcvJJCs2gDGvaELZbzwfL"; - string[] SCOPES = { + private static string[] SCOPES = { "openid", "profile", "email" }; - string tokenUri = "https://accounts.google.com/o/oauth2/token"; - string authUri = "https://accounts.google.com/o/oauth2/auth"; - + private static string tokenUri = "https://accounts.google.com/o/oauth2/token"; + private static string authUri = "https://accounts.google.com/o/oauth2/auth"; + private static string dateFormat = "yyyy-MM-dd'T'HH:mm:ss.fffK"; private string SetSessionSate () { Random rand = new Random (); @@ -363,14 +363,24 @@ namespace Yavsc.Controllers ModelState.AddModelError ("MinTime", "This first date must be lower than the second one."); return View (model); } - ProfileBase upr = ProfileBase.Create (model.UserName); - if (upr == null) { + var muc = Membership.FindUsersByName (model.UserName); + if (muc.Count==0) { ModelState.AddModelError ("UserName", "Non existent user"); return View (model); } + ProfileBase upr = ProfileBase.Create (model.UserName); - - HttpWebRequest webreq = WebRequest.CreateHttp (getCalEntriesUri); + string calid = (string) upr.GetPropertyValue ("gcalid"); + if (string.IsNullOrWhiteSpace(calid)) { + ModelState.AddModelError ("UserName", "L'utilisateur n'a pas de calendrier Google associé."); + return View (model); + } + HttpWebRequest webreq = WebRequest.CreateHttp ( + string.Format( + getCalEntriesUri, calid)+ + string.Format("?singleEvents=true&orderBy=startTime&timeMin={0}&timeMax={1}", + model.MinDate.ToString(dateFormat),model.MaxDate.ToString(dateFormat)) + ); webreq.Headers.Add (HttpRequestHeader.Authorization, GetFreshGoogleCredential(upr)); webreq.Method = "GET"; webreq.ContentType = "application/http"; @@ -378,12 +388,18 @@ namespace Yavsc.Controllers using (Stream respstream = resp.GetResponseStream ()) { using (StreamReader readresp = new StreamReader (respstream, Encoding.UTF8)) { string responseStr = readresp.ReadToEnd (); - CalendarList res = JsonConvert.DeserializeObject (responseStr); + try { + CalendarEntryList res = JsonConvert.DeserializeObject (responseStr); ViewData ["json"] = responseStr; return View (res); + } + catch (JsonReaderException ex) { + return View ("JsonReaderError", new JsonReaderError() {Text= responseStr, Excepx = ex}); + } } } } + } return View (model); } diff --git a/web/Controllers/HomeController.cs b/web/Controllers/HomeController.cs index 4855377c..fce3c827 100644 --- a/web/Controllers/HomeController.cs +++ b/web/Controllers/HomeController.cs @@ -69,7 +69,9 @@ namespace Yavsc.Controllers public ActionResult Index () { - string cn = CultureInfo.CurrentCulture.Name; + string startPage = WebConfigurationManager.AppSettings ["StartPage"]; + if (startPage != null) + Redirect (startPage); ViewData ["Message"] = LocalizedText.Welcome; return View (); } diff --git a/web/Global.asax.cs b/web/Global.asax.cs index 32f7e0d4..b1fa79bb 100644 --- a/web/Global.asax.cs +++ b/web/Global.asax.cs @@ -25,17 +25,7 @@ namespace Yavsc "Blog", "Blog/{user}/{title}", new { controller = "Blogs", action = "Index", user=UrlParameter.Optional, title = UrlParameter.Optional } - ); /* - routes.MapRoute ( - "Blogs", - "Blogs/{action}/{user}/{title}", - new { controller = "Blogs", action = "Index", user=UrlParameter.Optional, title = UrlParameter.Optional} - );*/ /* - routes.MapRoute ( - "Home", - "Home/Index", - new { controller = "Blogs", action = "Index", user="paul", title = "Documentation" } - );*/ + ); /*routes.MapRoute ( "Default", @@ -45,7 +35,7 @@ namespace Yavsc routes.MapRoute ( "Default", "{controller}/{action}/{user}/{title}", - new { controller = "Blogs", action = "Index", user="paul", title = "Documentation"} + new { controller = "Blogs", action = "Index", user=UrlParameter.Optional, title = UrlParameter.Optional } ); } diff --git a/web/Models/App.master b/web/Models/App.master index e766a075..4d2721f0 100644 --- a/web/Models/App.master +++ b/web/Models/App.master @@ -50,7 +50,7 @@ Page d'accueil <%= Html.ActionLink("Login", "Login", "Account", new { returnUrl=Request.Url.PathAndQuery }, new { @class="actionlink" } ) %> Pour pouvoir poster ou commenter - ?returnUrl=<%=ViewData["returnUrl"]%>" class="actionlink"> + ?returnUrl=<%=Request.Url.PathAndQuery%>" class="actionlink"> Google sign in S'authentifier avec son compte Google+ diff --git a/web/Theme/style.css b/web/Theme/style.css index 72a203b4..059e37b4 100644 --- a/web/Theme/style.css +++ b/web/Theme/style.css @@ -9,7 +9,7 @@ body { } main { - background-color: rgba(0,0,0,0.8); + background-color: rgba(17,0,23,0.65); float:left; margin:.5em; } @@ -24,9 +24,13 @@ video,img { max-width:100%; max-height:75%; position:relative; - top:4px; } -.panel { max-width: 17em; + +.panel { + background-color: rgba(16,32,32,0.8); + padding: 1em; margin: 0.5em; + border-radius:25px; border: solid 1px #000060; + max-width: 17em; max-height:30em; border:solid green 1px;} footer { @@ -39,8 +43,8 @@ footer { justify-content: space-around; z-index:-1; } - - footer img { max-height: 2em; } +.actionlink img { top:4px; } +footer img { max-height: 2em; } a { text-decoration: none; diff --git a/web/Views/Blogs/Post.aspx b/web/Views/Blogs/Post.aspx index 260d9eab..0001df6d 100644 --- a/web/Views/Blogs/Post.aspx +++ b/web/Views/Blogs/Post.aspx @@ -14,9 +14,7 @@ Nouveau billet - -
- <%= Html.Encode(ViewData["Message"]) %> -
+ <% if (Model != null ) if (Model.Content != null ) { %>
<%= BBCodeHelper.Parser.ToHtml(Model.Content) %> @@ -54,7 +52,7 @@ Nouveau billet - <%= Html.ValidationMessage("Preview", "*") %>
<%= Html.Hidden("Id") %> - + "/>