summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--projecttemplates/MvcRelyingParty/Controllers/AccountController.cs33
-rw-r--r--projecttemplates/MvcRelyingParty/Models/AccountInfoModel.cs14
-rw-r--r--projecttemplates/MvcRelyingParty/MvcRelyingParty.csproj3
-rw-r--r--projecttemplates/MvcRelyingParty/Views/Account/Edit.aspx49
-rw-r--r--projecttemplates/MvcRelyingParty/Views/Shared/Site.Master68
5 files changed, 135 insertions, 32 deletions
diff --git a/projecttemplates/MvcRelyingParty/Controllers/AccountController.cs b/projecttemplates/MvcRelyingParty/Controllers/AccountController.cs
index 05bffe4..03eb505 100644
--- a/projecttemplates/MvcRelyingParty/Controllers/AccountController.cs
+++ b/projecttemplates/MvcRelyingParty/Controllers/AccountController.cs
@@ -12,6 +12,7 @@
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;
using DotNetOpenAuth.OpenId.RelyingParty;
+ using MvcRelyingParty.Models;
using RelyingPartyLogic;
[HandleError]
@@ -148,5 +149,37 @@
this.FormsAuth.SignOut();
return RedirectToAction("Index", "Home");
}
+
+ public ActionResult Edit() {
+ var model = new AccountInfoModel {
+ FirstName = Database.LoggedInUser.FirstName,
+ LastName = Database.LoggedInUser.LastName,
+ EmailAddress = Database.LoggedInUser.EmailAddress,
+ };
+ return View(model);
+ }
+
+ /// <summary>
+ /// Updates the user's account information.
+ /// </summary>
+ /// <param name="firstName">The first name.</param>
+ /// <param name="lastName">The last name.</param>
+ /// <param name="emailAddress">The email address.</param>
+ /// <returns>An updated view showing the new profile.</returns>
+ /// <remarks>
+ /// This action accepts PUT because this operation is idempotent in nature.
+ /// </remarks>
+ [AcceptVerbs(HttpVerbs.Put), ValidateAntiForgeryToken]
+ public ActionResult Update(string firstName, string lastName, string emailAddress) {
+ Database.LoggedInUser.FirstName = firstName;
+ Database.LoggedInUser.LastName = lastName;
+
+ if (Database.LoggedInUser.EmailAddress != emailAddress) {
+ Database.LoggedInUser.EmailAddress = emailAddress;
+ Database.LoggedInUser.EmailAddressVerified = false;
+ }
+
+ return new EmptyResult();
+ }
}
}
diff --git a/projecttemplates/MvcRelyingParty/Models/AccountInfoModel.cs b/projecttemplates/MvcRelyingParty/Models/AccountInfoModel.cs
new file mode 100644
index 0000000..04fda47
--- /dev/null
+++ b/projecttemplates/MvcRelyingParty/Models/AccountInfoModel.cs
@@ -0,0 +1,14 @@
+namespace MvcRelyingParty.Models {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Web;
+
+ public class AccountInfoModel {
+ public string FirstName { get; set; }
+
+ public string LastName { get; set; }
+
+ public string EmailAddress { get; set; }
+ }
+}
diff --git a/projecttemplates/MvcRelyingParty/MvcRelyingParty.csproj b/projecttemplates/MvcRelyingParty/MvcRelyingParty.csproj
index 116b836..c0f7f0b 100644
--- a/projecttemplates/MvcRelyingParty/MvcRelyingParty.csproj
+++ b/projecttemplates/MvcRelyingParty/MvcRelyingParty.csproj
@@ -74,6 +74,7 @@
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
+ <Compile Include="Models\AccountInfoModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Setup.aspx.cs">
<DependentUpon>Setup.aspx</DependentUpon>
@@ -88,6 +89,7 @@
<Content Include="GettingStarted.htm" />
<Content Include="Global.asax" />
<Content Include="Setup.aspx" />
+ <Content Include="Views\Account\Edit.aspx" />
<Content Include="Views\Home\PrivacyPolicy.aspx" />
<Content Include="Web.config" />
<Content Include="Content\Site.css" />
@@ -119,7 +121,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
- <Folder Include="Models\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />
diff --git a/projecttemplates/MvcRelyingParty/Views/Account/Edit.aspx b/projecttemplates/MvcRelyingParty/Views/Account/Edit.aspx
new file mode 100644
index 0000000..ea741f4
--- /dev/null
+++ b/projecttemplates/MvcRelyingParty/Views/Account/Edit.aspx
@@ -0,0 +1,49 @@
+<%@ Page Title="Edit Account Information" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
+ Inherits="System.Web.Mvc.ViewPage<AccountInfoModel>" %>
+
+<%@ Import Namespace="MvcRelyingParty.Models" %>
+<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
+ 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" })) { %>
+ <%= 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>
+ <% } %>
+</asp:Content>
diff --git a/projecttemplates/MvcRelyingParty/Views/Shared/Site.Master b/projecttemplates/MvcRelyingParty/Views/Shared/Site.Master
index c02a50c..f49b072 100644
--- a/projecttemplates/MvcRelyingParty/Views/Shared/Site.Master
+++ b/projecttemplates/MvcRelyingParty/Views/Shared/Site.Master
@@ -3,38 +3,44 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
- <title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
- <link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
+ <title>
+ <asp:ContentPlaceHolder ID="TitleContent" runat="server" />
+ </title>
+ <link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
</head>
-
<body>
- <div class="page">
-
- <div id="header">
- <div id="title">
- <h1>My MVC Application</h1>
- </div>
-
- <div id="logindisplay">
- <% Html.RenderPartial("LogOnUserControl"); %>
- </div>
-
- <div id="menucontainer">
-
- <ul id="menu">
- <li><%= Html.ActionLink("Home", "Index", "Home")%></li>
- <li><%= Html.ActionLink("About", "About", "Home")%></li>
- </ul>
-
- </div>
- </div>
-
- <div id="main">
- <asp:ContentPlaceHolder ID="MainContent" runat="server" />
-
- <div id="footer">
- </div>
- </div>
- </div>
+ <div class="page">
+ <div id="header">
+ <div id="title">
+ <h1>
+ My MVC Application
+ </h1>
+ </div>
+ <div id="logindisplay">
+ <% Html.RenderPartial("LogOnUserControl"); %>
+ </div>
+ <div id="menucontainer">
+ <ul id="menu">
+ <li>
+ <%= Html.ActionLink("Home", "Index", "Home")%>
+ </li>
+ <li>
+ <%= Html.ActionLink("About", "About", "Home")%>
+ </li>
+ <% if (Page.User.Identity.IsAuthenticated) { %>
+ <li>
+ <%= Html.ActionLink("Account", "Edit", "Account")%>
+ </li>
+ <% } %>
+ </ul>
+ </div>
+ </div>
+ <div id="main">
+ <asp:ContentPlaceHolder ID="MainContent" runat="server" />
+ <div id="footer">
+ </div>
+ </div>
+ </div>
+ <asp:ContentPlaceHolder runat="server" ID="ScriptsArea" />
</body>
</html>