diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-12-30 10:52:59 -0800 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-12-30 10:52:59 -0800 |
commit | 815ca5309b5af651e8ecf9583c31a2f86d02a1a9 (patch) | |
tree | cec977ccaca91ca3afec59108fc959268ef53267 | |
parent | aac052909dcfa275b8582977082b653dad6b654e (diff) | |
download | DotNetOpenAuth-815ca5309b5af651e8ecf9583c31a2f86d02a1a9.zip DotNetOpenAuth-815ca5309b5af651e8ecf9583c31a2f86d02a1a9.tar.gz DotNetOpenAuth-815ca5309b5af651e8ecf9583c31a2f86d02a1a9.tar.bz2 |
Updating account info work.
4 files changed, 56 insertions, 38 deletions
diff --git a/projecttemplates/MvcRelyingParty/Controllers/AccountController.cs b/projecttemplates/MvcRelyingParty/Controllers/AccountController.cs index 9046ece..cd954b9 100644 --- a/projecttemplates/MvcRelyingParty/Controllers/AccountController.cs +++ b/projecttemplates/MvcRelyingParty/Controllers/AccountController.cs @@ -150,13 +150,9 @@ return RedirectToAction("Index", "Home"); } + [Authorize] public ActionResult Edit() { - var model = new AccountInfoModel { - FirstName = Database.LoggedInUser.FirstName, - LastName = Database.LoggedInUser.LastName, - EmailAddress = Database.LoggedInUser.EmailAddress, - }; - return View(model); + return View(GetModel()); } /// <summary> @@ -169,7 +165,7 @@ /// <remarks> /// This action accepts PUT because this operation is idempotent in nature. /// </remarks> - [AcceptVerbs(HttpVerbs.Put), ValidateAntiForgeryToken] + [Authorize, AcceptVerbs(HttpVerbs.Put), ValidateAntiForgeryToken] public ActionResult Update(string firstName, string lastName, string emailAddress) { Database.LoggedInUser.FirstName = firstName; Database.LoggedInUser.LastName = lastName; @@ -179,7 +175,16 @@ Database.LoggedInUser.EmailAddressVerified = false; } - return new EmptyResult(); + return PartialView("EditFields", GetModel()); + } + + private static AccountInfoModel GetModel() { + var model = new AccountInfoModel { + FirstName = Database.LoggedInUser.FirstName, + LastName = Database.LoggedInUser.LastName, + EmailAddress = Database.LoggedInUser.EmailAddress, + }; + return model; } } } diff --git a/projecttemplates/MvcRelyingParty/MvcRelyingParty.csproj b/projecttemplates/MvcRelyingParty/MvcRelyingParty.csproj index c0f7f0b..ad6f475 100644 --- a/projecttemplates/MvcRelyingParty/MvcRelyingParty.csproj +++ b/projecttemplates/MvcRelyingParty/MvcRelyingParty.csproj @@ -89,6 +89,7 @@ <Content Include="GettingStarted.htm" /> <Content Include="Global.asax" /> <Content Include="Setup.aspx" /> + <Content Include="Views\Account\EditFields.ascx" /> <Content Include="Views\Account\Edit.aspx" /> <Content Include="Views\Home\PrivacyPolicy.aspx" /> <Content Include="Web.config" /> diff --git a/projecttemplates/MvcRelyingParty/Views/Account/Edit.aspx b/projecttemplates/MvcRelyingParty/Views/Account/Edit.aspx index ea741f4..38d621d 100644 --- a/projecttemplates/MvcRelyingParty/Views/Account/Edit.aspx +++ b/projecttemplates/MvcRelyingParty/Views/Account/Edit.aspx @@ -6,44 +6,22 @@ Edit </asp:Content> <asp:Content ContentPlaceHolderID="ScriptsArea" runat="server"> + <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script> + <script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script> + </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2> Edit Account Information </h2> - <% using (Ajax.BeginForm("Update", new AjaxOptions { HttpMethod = "PUT", UpdateTargetId = "postResult" })) { %> + <% using (Ajax.BeginForm("Update", new AjaxOptions { HttpMethod = "PUT", UpdateTargetId = "editPartial", LoadingElementId = "updatingMessage" })) { %> <%= Html.AntiForgeryToken()%> - <table> - <tr> - <td> - First name - </td> - <td> - <input name="firstName" value="<%= Html.Encode(Model.FirstName) %>" /> - </td> - </tr> - <tr> - <td> - Last name - </td> - <td> - <input name="lastName" value="<%= Html.Encode(Model.LastName) %>" /> - </td> - </tr> - <tr> - <td> - Email - </td> - <td> - <input name="emailAddress" value="<%= Html.Encode(Model.EmailAddress) %>" /> - </td> - </tr> - </table> - <div> - <input type="submit" value="Save" /> - <div id="postResult" /> + <div id="editPartial"> + <% Html.RenderPartial("EditFields"); %> </div> + <input type="submit" value="Save" /> + <span id="updatingMessage" style="display: none">Saving...</span> <% } %> </asp:Content> diff --git a/projecttemplates/MvcRelyingParty/Views/Account/EditFields.ascx b/projecttemplates/MvcRelyingParty/Views/Account/EditFields.ascx new file mode 100644 index 0000000..39b4358 --- /dev/null +++ b/projecttemplates/MvcRelyingParty/Views/Account/EditFields.ascx @@ -0,0 +1,34 @@ +<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MvcRelyingParty.Models.AccountInfoModel>" %> +<%= Html.ValidationSummary("Edit was unsuccessful. Please correct the errors and try again.") %> +<fieldset> + <legend>Account Details</legend> + <table> + <tr> + <td> + <label for="FirstName">First Name:</label> + </td> + <td> + <%= Html.TextBox("FirstName", Model.FirstName) %> + <%= Html.ValidationMessage("FirstName", "*") %> + </td> + </tr> + <tr> + <td> + <label for="LastName">Last Name:</label> + </td> + <td> + <%= Html.TextBox("LastName", Model.LastName) %> + <%= Html.ValidationMessage("LastName", "*") %> + </td> + </tr> + <tr> + <td> + <label for="EmailAddress">Email Address:</label> + </td> + <td> + <%= Html.TextBox("EmailAddress", Model.EmailAddress) %> + <%= Html.ValidationMessage("EmailAddress", "*") %> + </td> + </tr> + </table> +</fieldset> |