From 5d19dc2dcffaaf5aef076c91a248f9d000f675d8 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sat, 31 Jan 2015 00:18:11 +0100 Subject: [PATCH] * GoogleController.cs: Restores the calendar choosing * OAuth2.cs: code formatting * Profile.aspx: useless Uri display * ChooseCalendar.aspx: returnUrl in the calendar choosing process --- web/Controllers/GoogleController.cs | 25 +++++++++++++++++++------ web/Helpers/Google/OAuth2.cs | 3 +-- web/Views/Account/Profile.aspx | 2 +- web/Views/Google/ChooseCalendar.aspx | 1 + 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/web/Controllers/GoogleController.cs b/web/Controllers/GoogleController.cs index 101f953a..d3fe1ac8 100644 --- a/web/Controllers/GoogleController.cs +++ b/web/Controllers/GoogleController.cs @@ -60,6 +60,18 @@ namespace Yavsc.Controllers oa.Login (Response, SetSessionSate ()); } + /// + /// Gets the cal auth. + /// + /// Return URL. + public void GetCalAuth (string returnUrl) + { + if (string.IsNullOrWhiteSpace (returnUrl)) + returnUrl = "/"; + Session ["returnUrl"] = returnUrl; + OAuth2 oa = new OAuth2 (CalendarGRU); + oa.GetCalAuth (Response, SetSessionSate ()); + } /// /// Called after the Google authorizations screen, @@ -68,7 +80,6 @@ namespace Yavsc.Controllers /// The auth. [HttpGet] [Authorize] - public ActionResult CalAuth () { string msg; @@ -221,17 +232,21 @@ namespace Yavsc.Controllers [HttpGet] public ActionResult ChooseCalendar (string returnUrl) { - Session ["ChooseCalReturnUrl"] = returnUrl; + bool hasCalAuth = (bool)HttpContext.Profile.GetPropertyValue ("gcalapi"); if (!hasCalAuth) { Session ["returnUrl"] = Request.Url.Scheme + "://" + Request.Url.Authority + "/Google/ChooseCalendar"; - return RedirectToAction ("GetCalAuth"); + return RedirectToAction ("GetCalAuth", + new { + returnUrl = "ChooseCalendar?returnUrl="+HttpUtility.UrlEncode(returnUrl) + }); } string cred = OAuth2.GetFreshGoogleCredential (HttpContext.Profile); string json; CalendarApi c = new CalendarApi (); CalendarList cl = c.GetCalendars (cred, out json); ViewData ["json"] = json; + ViewData ["returnUrl"] = returnUrl; return View (cl); } @@ -242,14 +257,12 @@ namespace Yavsc.Controllers /// Calchoice. [HttpPost] [Authorize] - public ActionResult SetCalendar (string calchoice) + public ActionResult SetCalendar (string calchoice,string returnUrl) { HttpContext.Profile.SetPropertyValue ("gcalid", calchoice); HttpContext.Profile.Save (); - string returnUrl = (string)Session ["ChooseCalReturnUrl"]; if (returnUrl != null) { - Session ["ChooseCalReturnUrl"] = null; return Redirect (returnUrl); } return Redirect ("/"); diff --git a/web/Helpers/Google/OAuth2.cs b/web/Helpers/Google/OAuth2.cs index 76e79948..5bd260c5 100644 --- a/web/Helpers/Google/OAuth2.cs +++ b/web/Helpers/Google/OAuth2.cs @@ -128,8 +128,7 @@ namespace Yavsc.Helpers.Google string cont = null; WebRequest wr = WebRequest.Create (authUri + "?" + prms); wr.Method = "GET"; - using ( - WebResponse response = wr.GetResponse ()) { + using (WebResponse response = wr.GetResponse ()) { string resQuery = response.ResponseUri.Query; cont = HttpUtility.ParseQueryString (resQuery) ["continue"]; response.Close (); diff --git a/web/Views/Account/Profile.aspx b/web/Views/Account/Profile.aspx index ef6f31be..fa9ea1cc 100644 --- a/web/Views/Account/Profile.aspx +++ b/web/Views/Account/Profile.aspx @@ -57,7 +57,7 @@ table.layout TR TD { max-width:40%; } <%= Html.TextBox("BlogTitle") %> <%= Html.ValidationMessage("BlogTitle", "*") %> -Avatar : "<%=Model.avatar%>" +Avatar <%= Html.ValidationMessage("AvatarFile", "*") %> diff --git a/web/Views/Google/ChooseCalendar.aspx b/web/Views/Google/ChooseCalendar.aspx index addaef08..876897ee 100644 --- a/web/Views/Google/ChooseCalendar.aspx +++ b/web/Views/Google/ChooseCalendar.aspx @@ -8,6 +8,7 @@ <%=Html.Encode(e.summary)%>
<%=Html.Encode(e.description)%>
<% } %> +"> <% } %>