/Resources/Companion/AdminRole/Controllers/AccountController.cs
C# | 89 lines | 67 code | 14 blank | 8 comment | 8 complexity | 181735a4f33fdd12a928a71494bb75e7 MD5 | raw file
Possible License(s): LGPL-2.0
- 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 Microsoft.WindowsAzure.Companion.Models;
-
- namespace Microsoft.WindowsAzure.Companion.Controllers
- {
-
- [HandleError]
- public class AccountController : BaseController
- {
-
- public IFormsAuthenticationService FormsService { get; set; }
- public IMembershipService MembershipService { get; set; }
-
- public AccountController()
- {
- ViewData["CurrentTab"] = "Account";
- }
-
- protected override void Initialize(RequestContext requestContext)
- {
- if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
- if (MembershipService == null) { MembershipService = new AccountMembershipService(); }
-
- base.Initialize(requestContext);
- }
-
- // **************************************
- // URL: /Account/LogOn
- // **************************************
-
- public ActionResult LogOn()
- {
- // Check for error message
- string errorMessage = ViewData["ErrorMessage"] as string;
- if (!string.IsNullOrEmpty(errorMessage))
- {
- return RedirectToAction("Error", "Home", new { ErrorMessage = errorMessage });
- }
-
- return View();
- }
-
- [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");
- }
- }
- else
- {
- ModelState.AddModelError("", "The user name or password provided is incorrect.");
- }
- }
-
- // If we got this far, something failed, redisplay form
- return View(model);
- }
-
- // **************************************
- // URL: /Account/LogOff
- // **************************************
-
- public ActionResult LogOff()
- {
- FormsService.SignOut();
-
- return RedirectToAction("Index", "Home");
- }
- }
- }