using System.Web.Mvc; using System.Web.UI; using Pilotfish.Afx.Security; using System; using System.Configuration; using System.Web.Profile; using System.Linq; using Neo.Legitimate.Common; using System.Web.Security; using Pilotfish.Afx.Services.Audits; namespace Pilotfish.Afx.Test.WebConsole.Controllers.Auth { // Don't inherit from Controller // as it has the Authorize attribute public partial class AuthController : Controller { [AllowAnonymous] [OutputCache(Location = OutputCacheLocation.None)] public ActionResult Login() { return RedirectToAction("SignIn"); } [AllowAnonymous] [OutputCache(Location = OutputCacheLocation.None)] public ActionResult SignIn() { ViewBag.Controller = "Authentication"; ViewBag.FingerprintAuthenticationEnabled = ConfigurationManager.AppSettings["FingerprintAuthenticationEnabled"].ToString().ToLower() == "true"; return View(); } [OutputCache(Location = OutputCacheLocation.None)] public ActionResult SignOut() { DomainAuthenticationProvider.Signout(); return RedirectToAction("Default", "Home"); } #region JSON endpoints #region SignInUser // POST: /Home/SignInUser [HttpPost] [AllowAnonymous] public JsonResult SignInUser(string userName, string password, string fingerprint) { bool success = false; var returnUrl = DomainAuthenticationProvider.DefaultUrl; if (!Profile.IsAnonymous) { return Json(new { success, returnUrl = returnUrl, passwordExpired = false, alreadyLoggedIn = true }); } if (ConfigurationManager.AppSettings["FingerprintAuthenticationEnabled"].ToString().ToLower() == "true") { if (!string.IsNullOrEmpty(fingerprint)) { success = DomainAuthenticationProvider.ValidateUser(fingerprint, false, ref userName); } } else { success = DomainAuthenticationProvider.ValidateUser(userName, password, false); } if (success) { Session["DateLoggedIn"] = DateTime.Now; var profile = new UserProfile(); profile = (UserProfile)ProfileBase.Create(userName, success); if (profile != null) { var auditDb = new AuditsDatabase(); auditDb.WriteEntry(profile.UserID, "Application", "User logged in", null, false, false, 1 /*user*/, profile.UserID); returnUrl = (HttpContext.Request.Cookies["LastPage"] != null) ? ConfigurationManager.AppSettings["BaseUrl"] + HttpContext.Request.Cookies["LastPage"].Value : ConfigurationManager.AppSettings["BaseUrl"]; } } return Json(new { success, returnUrl = returnUrl, passwordExpired = false, alreadyLoggedIn = false }); } #endregion #endregion } }