public ActionResult Index(Models.Login.Login login) { if (login.IsValid()) { FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, // ticket version login.Username, // authenticated username DateTime.Now, // issueDate DateTime.Now.AddMinutes(30), // expiryDate true, // true to persist across browser sessions "", // can be used to store additional user data FormsAuthentication.FormsCookiePath); // the path for the cookie // Encrypt the ticket using the machine key string encryptedTicket = FormsAuthentication.Encrypt(ticket); // Add the cookie to the request to save it HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); cookie.HttpOnly = true; Response.Cookies.Add(cookie); return(RedirectToAction("StatsForStagePlan")); } return(View()); }
/// <summary> /// Process request on deletion of user based on HTTP context, returns message upon success /// </summary> public void ProcessRequest(HttpContext context) { HttpRequest request = context.Request; HttpResponse response = context.Response; String jsonString = String.Empty; JavaScriptSerializer serializer = new JavaScriptSerializer(); Models.Login.Login login = new Models.Login.Login(new User { UserName = request.Form["userName"] }); try { login.DeleteUser(); jsonString = serializer.Serialize(new { result = "success" }); } catch (Exception ex) { jsonString = serializer.Serialize(new { result = ex.Message }); } finally { response.Write(jsonString); response.ContentType = "application/json"; } }
/// <summary> /// Process request on deletion of user based on HTTP context, returns message upon success /// </summary> public void ProcessRequest(HttpContext context) { HttpRequest request = context.Request; HttpResponse response = context.Response; String jsonString = String.Empty; JavaScriptSerializer serializer = new JavaScriptSerializer(); Models.Login.Login login = new Models.Login.Login(new User { UserName = request.Form["userName"] }); try { login.DeleteUser(); jsonString = serializer.Serialize(new { result = "success" }); } catch (Exception ex) { jsonString = serializer.Serialize(new { result = ex.Message }); } finally { response.Write(jsonString); response.ContentType = "application/json"; } }
// INDEX; INDEX/ENVIRONMENT_NAME public ActionResult Index(String environmentName) { Models.Login.Login loginModel = null; System.Diagnostics.Trace.WriteLineIf(MercuryApplication.TraceSwitchSecurity.TraceVerbose, "\r\n[Mercury.Web.Default] Current Credentials"); System.Diagnostics.Trace.WriteLineIf(MercuryApplication.TraceSwitchSecurity.TraceVerbose, "Web Thread Principal: " + System.Threading.Thread.CurrentPrincipal.Identity.Name); System.Diagnostics.Trace.WriteLineIf(MercuryApplication.TraceSwitchSecurity.TraceVerbose, "Web System Principal: " + System.Security.Principal.WindowsIdentity.GetCurrent().Name); System.Diagnostics.Trace.WriteLineIf(MercuryApplication.TraceSwitchSecurity.TraceVerbose, "Web Thread Authentication Type: " + System.Threading.Thread.CurrentPrincipal.Identity.AuthenticationType); if (((System.Threading.Thread.CurrentPrincipal.Identity.AuthenticationType == "NTLM") || (System.Threading.Thread.CurrentPrincipal.Identity.AuthenticationType == "Kerberos") || (System.Threading.Thread.CurrentPrincipal.Identity.AuthenticationType == "Negotiate")) && (System.Threading.Thread.CurrentPrincipal.Identity.IsAuthenticated) && (!String.IsNullOrWhiteSpace(System.Threading.Thread.CurrentPrincipal.Identity.Name))) { MercuryApplication.Authenticate(environmentName); // AUTHENTICATION REQUEST if ((MercuryApplication.AuthenticationResponse.AuthenticationError == Mercury.Server.Enterprise.AuthenticationError.NoError) && (!String.IsNullOrWhiteSpace(MercuryApplication.AuthenticationResponse.Token))) { // VALID, SUCCESSFUL LOGIN return(RedirectToRoute(new { controller = "Workspace" })); // USE STANDARD REDIRECTION WHEN AUTHENTICATED, MERCURY APPLICATION IS CACHED FOR WORKSPACE TO USE // THE BELOW WAS REMOVED, IT COULD BE USED TO SUPPORT STATELESS PASSING OF THE TOKEN BETWEEN THE LOGIN PAGE AND THE WORKSPACE PAGE //String encryptedToken = MercuryApplication.AuthenticationResponse.Token; //#if DEBUG //System.Diagnostics.Debug.WriteLine ("Authentication Token: " + MercuryApplication.AuthenticationResponse.Token); //System.Diagnostics.Debug.WriteLine ("Authentication Token Encrypted: " + encryptedToken); //#endif // // loginModel = new Models.Login.Login (MercuryApplication.AuthenticationResponse, environmentName); } else { // NOT A SUCCESSFUL LOGIN, CREATE MODEL AND PASS VIEW loginModel = new Models.Login.Login(MercuryApplication.AuthenticationResponse, environmentName); } } else { // NOT USING WINDOWS AUTHENTICATION, REDIRECT TO PERMISSION DENIED // TODO: REDIRECT } return(View(loginModel)); }
//validPwrd = "Unic0rn5"; //validUsr = "******"; // GET: Unicorn public ActionResult Index() { var login = new Models.Login.Login(); return(View(login)); }