summaryrefslogtreecommitdiffstats
path: root/samples/OAuthAuthorizationServer/Controllers/AccountController.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2010-08-01 06:51:33 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2010-08-01 08:58:42 -0700
commite7743dd039bab3788e682833368ca5a376b22354 (patch)
treea4eb3af6cc4c263823d3612ee39c6fa4a550aac5 /samples/OAuthAuthorizationServer/Controllers/AccountController.cs
parentc94c7f8197eda673947a9d1e0c0b3f3c4efca94f (diff)
downloadDotNetOpenAuth-e7743dd039bab3788e682833368ca5a376b22354.zip
DotNetOpenAuth-e7743dd039bab3788e682833368ca5a376b22354.tar.gz
DotNetOpenAuth-e7743dd039bab3788e682833368ca5a376b22354.tar.bz2
The OAuthClient, OAuthResourceServer and OAuthAuthorizationServer samples now work!
Diffstat (limited to 'samples/OAuthAuthorizationServer/Controllers/AccountController.cs')
-rw-r--r--samples/OAuthAuthorizationServer/Controllers/AccountController.cs129
1 files changed, 38 insertions, 91 deletions
diff --git a/samples/OAuthAuthorizationServer/Controllers/AccountController.cs b/samples/OAuthAuthorizationServer/Controllers/AccountController.cs
index a62258b..1361376 100644
--- a/samples/OAuthAuthorizationServer/Controllers/AccountController.cs
+++ b/samples/OAuthAuthorizationServer/Controllers/AccountController.cs
@@ -1,28 +1,23 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics.CodeAnalysis;
-using System.Linq;
-using System.Security.Principal;
-using System.Web;
-using System.Web.Mvc;
-using System.Web.Routing;
-using System.Web.Security;
-using OAuthAuthorizationServer.Models;
+namespace OAuthAuthorizationServer.Controllers {
+ using System;
+ using System.Collections.Generic;
+ using System.Diagnostics.CodeAnalysis;
+ using System.Linq;
+ using System.Security.Principal;
+ using System.Web;
+ using System.Web.Mvc;
+ using System.Web.Routing;
+ using System.Web.Security;
-namespace OAuthAuthorizationServer.Controllers {
+ using DotNetOpenAuth.OpenId;
+ using DotNetOpenAuth.OpenId.RelyingParty;
- [HandleError]
- public class AccountController : Controller {
-
- public IFormsAuthenticationService FormsService { get; set; }
- public IMembershipService MembershipService { get; set; }
+ using OAuthAuthorizationServer.Models;
- protected override void Initialize(RequestContext requestContext) {
- if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
- if (MembershipService == null) { MembershipService = new AccountMembershipService(); }
+ using DotNetOpenAuth.Messaging;
- base.Initialize(requestContext);
- }
+ [HandleError]
+ public class AccountController : Controller {
// **************************************
// URL: /Account/LogOn
@@ -35,15 +30,13 @@ namespace OAuthAuthorizationServer.Controllers {
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl) {
if (ModelState.IsValid) {
- if (MembershipService.ValidateUser(model.UserName, model.Password)) {
- FormsService.SignIn(model.UserName, model.RememberMe);
- if (!String.IsNullOrEmpty(returnUrl)) {
- return Redirect(returnUrl);
- } else {
- return RedirectToAction("Index", "Home");
- }
+ var rp = new OpenIdRelyingParty();
+ var request = rp.CreateRequest(model.UserSuppliedIdentifier, Realm.AutoDetect, new Uri(Request.Url, Url.Action("Authenticate")));
+ if (request != null) {
+ request.AddCallbackArguments("returnUrl", returnUrl);
+ return request.RedirectingResponse.AsActionResult();
} else {
- ModelState.AddModelError("", "The user name or password provided is incorrect.");
+ ModelState.AddModelError("", "The identifier you supplied is not recognized as a valid OpenID Identifier.");
}
}
@@ -51,77 +44,31 @@ namespace OAuthAuthorizationServer.Controllers {
return View(model);
}
- // **************************************
- // URL: /Account/LogOff
- // **************************************
-
- public ActionResult LogOff() {
- FormsService.SignOut();
-
- return RedirectToAction("Index", "Home");
- }
-
- // **************************************
- // URL: /Account/Register
- // **************************************
-
- public ActionResult Register() {
- ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
- return View();
- }
-
- [HttpPost]
- public ActionResult Register(RegisterModel model) {
- if (ModelState.IsValid) {
- // Attempt to register the user
- MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);
-
- if (createStatus == MembershipCreateStatus.Success) {
- FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
- return RedirectToAction("Index", "Home");
- } else {
- ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
+ public ActionResult Authenticate(string returnUrl) {
+ var rp = new OpenIdRelyingParty();
+ var response = rp.GetResponse();
+ if (response != null) {
+ switch (response.Status) {
+ case AuthenticationStatus.Authenticated:
+ FormsAuthentication.SetAuthCookie(response.ClaimedIdentifier, false);
+ return this.Redirect(returnUrl);
+ default:
+ ModelState.AddModelError("", "An error occurred during login.");
+ break;
}
}
- // If we got this far, something failed, redisplay form
- ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
- return View(model);
+ return this.View("LogOn");
}
// **************************************
- // URL: /Account/ChangePassword
+ // URL: /Account/LogOff
// **************************************
- [Authorize]
- public ActionResult ChangePassword() {
- ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
- return View();
- }
-
- [Authorize]
- [HttpPost]
- public ActionResult ChangePassword(ChangePasswordModel model) {
- if (ModelState.IsValid) {
- if (MembershipService.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword)) {
- return RedirectToAction("ChangePasswordSuccess");
- } else {
- ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
- }
- }
-
- // If we got this far, something failed, redisplay form
- ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
- return View(model);
- }
-
- // **************************************
- // URL: /Account/ChangePasswordSuccess
- // **************************************
+ public ActionResult LogOff() {
+ FormsAuthentication.SignOut();
- public ActionResult ChangePasswordSuccess() {
- return View();
+ return RedirectToAction("Index", "Home");
}
-
}
}