summaryrefslogtreecommitdiffstats
path: root/samples/OpenIdProviderMvc/Controllers/UserController.cs
blob: 5e0c21fa67a28b4a5c9366d8afe9a2646a92b03e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
namespace OpenIdProviderMvc.Controllers {
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Web;
	using System.Web.Mvc;
	using System.Web.Mvc.Ajax;

	public class UserController : Controller {
		/// <summary>
		/// Identities the specified id.
		/// </summary>
		/// <param name="id">The username or anonymous identifier.</param>
		/// <param name="anon">if set to <c>true</c> then <paramref name="id"/> represents an anonymous identifier rather than a username.</param>
		/// <returns>The view to display.</returns>
		public ActionResult Identity(string id, bool anon) {
			if (!anon) {
				var redirect = this.RedirectIfNotNormalizedRequestUri(id);
				if (redirect != null) {
					return redirect;
				}
			}

			if (Request.AcceptTypes != null && Request.AcceptTypes.Contains("application/xrds+xml")) {
				return View("Xrds");
			}

			if (!anon) {
				this.ViewData["username"] = id;
			}

			return View();
		}

		public ActionResult Xrds(string id) {
			return View();
		}

		private ActionResult RedirectIfNotNormalizedRequestUri(string user) {
			Uri normalized = Models.User.GetClaimedIdentifierForUser(user);
			if (Request.Url != normalized) {
				return Redirect(normalized.AbsoluteUri);
			}

			return null;
		}
	}
}