PageRenderTime 64ms CodeModel.GetById 37ms RepoModel.GetById 1ms app.codeStats 0ms

/Resources/Companion/AdminRole/Controllers/AccountController.cs

https://bitbucket.org/zgramana/azure-accelerators-project
C# | 89 lines | 67 code | 14 blank | 8 comment | 8 complexity | 181735a4f33fdd12a928a71494bb75e7 MD5 | raw file
Possible License(s): LGPL-2.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics.CodeAnalysis;
  4. using System.Linq;
  5. using System.Security.Principal;
  6. using System.Web;
  7. using System.Web.Mvc;
  8. using System.Web.Routing;
  9. using System.Web.Security;
  10. using Microsoft.WindowsAzure.Companion.Models;
  11. namespace Microsoft.WindowsAzure.Companion.Controllers
  12. {
  13. [HandleError]
  14. public class AccountController : BaseController
  15. {
  16. public IFormsAuthenticationService FormsService { get; set; }
  17. public IMembershipService MembershipService { get; set; }
  18. public AccountController()
  19. {
  20. ViewData["CurrentTab"] = "Account";
  21. }
  22. protected override void Initialize(RequestContext requestContext)
  23. {
  24. if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
  25. if (MembershipService == null) { MembershipService = new AccountMembershipService(); }
  26. base.Initialize(requestContext);
  27. }
  28. // **************************************
  29. // URL: /Account/LogOn
  30. // **************************************
  31. public ActionResult LogOn()
  32. {
  33. // Check for error message
  34. string errorMessage = ViewData["ErrorMessage"] as string;
  35. if (!string.IsNullOrEmpty(errorMessage))
  36. {
  37. return RedirectToAction("Error", "Home", new { ErrorMessage = errorMessage });
  38. }
  39. return View();
  40. }
  41. [HttpPost]
  42. public ActionResult LogOn(LogOnModel model, string returnUrl)
  43. {
  44. if (ModelState.IsValid)
  45. {
  46. if (MembershipService.ValidateUser(model.UserName, model.Password))
  47. {
  48. FormsService.SignIn(model.UserName, model.RememberMe);
  49. if (!String.IsNullOrEmpty(returnUrl))
  50. {
  51. return Redirect(returnUrl);
  52. }
  53. else
  54. {
  55. return RedirectToAction("Index", "Home");
  56. }
  57. }
  58. else
  59. {
  60. ModelState.AddModelError("", "The user name or password provided is incorrect.");
  61. }
  62. }
  63. // If we got this far, something failed, redisplay form
  64. return View(model);
  65. }
  66. // **************************************
  67. // URL: /Account/LogOff
  68. // **************************************
  69. public ActionResult LogOff()
  70. {
  71. FormsService.SignOut();
  72. return RedirectToAction("Index", "Home");
  73. }
  74. }
  75. }