From 0e6da273097171168d752ad6033223702ee4c1c2 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Tue, 27 Oct 2015 21:25:43 +0100 Subject: [PATCH] WIP: A Blogger role --- web/Controllers/BlogsController.cs | 12 +++++----- web/Controllers/GoogleController.cs | 34 +++++++++++++++-------------- web/Scripts/parallax.js | 28 ++++++++++++------------ 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/web/Controllers/BlogsController.cs b/web/Controllers/BlogsController.cs index acb8e344..2306ce3c 100644 --- a/web/Controllers/BlogsController.cs +++ b/web/Controllers/BlogsController.cs @@ -145,7 +145,7 @@ namespace Yavsc.Controllers /// /// The comment. /// Cmtid. - [Authorize] + [Authorize(Roles="Blogger")] public ActionResult RemoveComment (long cmtid) { long postid = BlogManager.RemoveComment (cmtid); @@ -257,7 +257,7 @@ namespace Yavsc.Controllers /// Post the specified title. /// /// Title. - [Authorize] + [Authorize(Roles="Blogger")] public ActionResult Post (string title) { string un = Membership.GetUser ().UserName; @@ -279,7 +279,7 @@ namespace Yavsc.Controllers /// /// The edit. /// Model. - [Authorize] + [Authorize(Roles="Blogger")] public ActionResult ValidateEdit (BlogEntry model) { ViewData ["SiteName"] = sitename; @@ -311,7 +311,7 @@ namespace Yavsc.Controllers /// Edit the specified bill /// /// Identifier. - [Authorize] + [Authorize(Roles="Blogger")] public ActionResult Edit (long postid) { @@ -361,7 +361,7 @@ namespace Yavsc.Controllers /// User. /// Return URL. /// If set to true confirm. - [Authorize] + [Authorize(Roles="Blogger")] public ActionResult RemoveTitle (string user, string title, string returnUrl, bool confirm = false) { if (returnUrl == null) @@ -389,7 +389,7 @@ namespace Yavsc.Controllers /// Identifier. /// Return URL. /// If set to true confirm. - [Authorize] + [Authorize(Roles="Blogger")] public ActionResult RemovePost (long postid, string returnUrl, bool confirm = false) { // ensures the access control diff --git a/web/Controllers/GoogleController.cs b/web/Controllers/GoogleController.cs index 1e4a1bac..b29043e6 100644 --- a/web/Controllers/GoogleController.cs +++ b/web/Controllers/GoogleController.cs @@ -26,6 +26,9 @@ namespace Yavsc.Controllers /// public class GoogleController : Controller { + /// + /// Index this instance. + /// public ActionResult Index() { return View (); @@ -295,9 +298,9 @@ namespace Yavsc.Controllers /// The query. [Authorize] [HttpGet] - public ActionResult DateQuery () + public ActionResult Book () { - return View (new BookEdit ()); + return View (new BookQuery ()); } /// @@ -307,42 +310,41 @@ namespace Yavsc.Controllers /// Model. [Authorize] [HttpPost] - public ActionResult DateQuery (BookEdit model) + public ActionResult Book (BookQuery model) { if (ModelState.IsValid) { - DateTime mindate = DateTime.Now; if (model.PreferedDate < mindate) model.PreferedDate = mindate; if (model.MaxDate < mindate) model.MaxDate = mindate.AddYears (1).Date; - var muc = Membership.FindUsersByName (model.UserName); + var muc = Membership.FindUsersByName (model.Person); if (muc.Count == 0) { - ModelState.AddModelError ("UserName", "Non existent user"); + ModelState.AddModelError ("Person", LocalizedText.Non_existent_user); + return View (model); + } + if (!Roles.IsUserInRole (model.Role)) { + ModelState.AddModelError ("Role", LocalizedText.UserNotInThisRole); return View (model); } - ProfileBase upr = ProfileBase.Create (model.UserName); + + ProfileBase upr = ProfileBase.Create (model.Person); string calid = (string)upr.GetPropertyValue ("gcalid"); if (string.IsNullOrWhiteSpace (calid)) { - ModelState.AddModelError ("UserName", "L'utilisateur n'a pas de calendrier Google associƩ."); + ModelState.AddModelError ("Person", LocalizedText.No_calendar_for_this_user); return View (model); } - DateTime maxdate = model.MaxDate; - CalendarApi c = new CalendarApi (); CalendarEventList res; try { - res = c.GetCalendar (calid, mindate, maxdate, upr); + var events = c.GetCalendar (calid, mindate, maxdate, upr); + } catch (OtherWebException ex) { - ViewData ["Title"] = ex.Title; - ViewData ["Content"] = ex.Content; - return View ("GoogleErrorMessage", ex); + return View ("OtherWebException", ex); } - - return View ("ChooseADate",res); } return View (model); } diff --git a/web/Scripts/parallax.js b/web/Scripts/parallax.js index 380cce2f..ba363144 100644 --- a/web/Scripts/parallax.js +++ b/web/Scripts/parallax.js @@ -22,13 +22,15 @@ $(document).ready(function(){ var $window = $(window); - var onPos = function (bgobj,dx,dy) { - x=$window.scrollLeft()+dx; - y=$window.scrollTop()+dy; + var $stwidth = $(window).width(); + var $stheight = $(window).width(); + var onPos = function (bgobj,ax,ay) { var speed = bgobj.data('speed'); - var xPos = bgobj.attr('orgbgpx') - Math.round( x / speed); - var yPos = bgobj.attr('orgbgpy') - Math.round( y / speed); + var dx=($window.scrollLeft()+ax-$stwidth/2)/speed; + var dy=($window.scrollTop()+ay-$stheight/2)/speed; + var xPos = bgobj.attr('orgbgpx') - Math.round( dx ); + var yPos = bgobj.attr('orgbgpy') - Math.round( dy ); // Put together our final background position var coords = '' + xPos + bgobj.attr('orgbgpxu') + yPos + bgobj.attr('orgbgpyu'); // Move the background @@ -80,18 +82,16 @@ $(document).ready(function(){ }); var nbevo=0; if (window.DeviceOrientationEvent) { + if ($stwidth>320 && $stheight>320) { window.addEventListener('deviceorientation', function(event) { - if (nbevo++>6) { - tiltLR = event.gamma; - titleFB = event.beta; + tiltLR = $stwidth*Math.sin(event.gamma*Math.PI/180); + titleFB = $stheight*Math.sin(event.beta*Math.PI/180); onPos($bgobj,tiltLR,titleFB); - nbevo=0; - } - },false); + },false); } $(window).mousemove(function(e) { - tiltLR = e.pageX; - titleFB = e.pageY; - onPos($bgobj,tiltLR,titleFB); + tiltLR = e.pageX; + titleFB = e.pageY; + onPos($bgobj,e.pageX,e.pageY); }); } });