public async Task <PartialViewResult> UpdateBenchmarkBasket(long urn, CookieActions withAction) { switch (withAction) { case CookieActions.SetDefault: await _schoolBenchmarkListService.SetSchoolAsDefaultAsync(urn); break; case CookieActions.Add: await _schoolBenchmarkListService.AddSchoolToBenchmarkListAsync(urn); break; case CookieActions.Remove: await _schoolBenchmarkListService.RemoveSchoolFromBenchmarkListAsync(urn); break; case CookieActions.RemoveAll: _schoolBenchmarkListService.ClearSchoolBenchmarkList(); break; case CookieActions.UnsetDefault: _schoolBenchmarkListService.UnsetDefaultSchool(); break; } return(PartialView("Partials/BenchmarkListBanner", new SchoolViewModel(_schoolBenchmarkListService.GetSchoolBenchmarkList()))); }
public async Task <JsonResult> UpdateManualBasket(long?urn, CookieActions withAction) { if (urn.HasValue) { switch (withAction) { case CookieActions.SetDefault: await _manualBenchmarkListService.SetSchoolAsDefaultInManualBenchmarkList(urn.GetValueOrDefault()); break; case CookieActions.Add: await _manualBenchmarkListService.AddSchoolToManualBenchmarkListAsync(urn.GetValueOrDefault()); break; case CookieActions.Remove: await _manualBenchmarkListService.RemoveSchoolFromManualBenchmarkListAsync(urn.GetValueOrDefault()); break; case CookieActions.UnsetDefault: _manualBenchmarkListService.UnsetDefaultSchoolInManualBenchmarkList(); break; } } else { _manualBenchmarkListService.ClearManualBenchmarkList(); } return(Json(_manualBenchmarkListService.GetManualBenchmarkList().BenchmarkSchools.Count, JsonRequestBehavior.AllowGet)); }
public async Task <IActionResult> LoginUser([FromBody] User user) { if (await IsUserLogged()) { return(BadRequest("You are already logged in")); } var loginUser = await tokenRepository.LogIn(user); if (loginUser == null) { return(BadRequest("Invalid username or password, please try again")); } string token = TokenActions.GenerateToken(loginUser, configuration); Console.WriteLine(token); loginUser.Token = token; await tokenRepository.SaveToken(loginUser.IdUser, token); // SET COOKIES USER ID AND USER TOKEN Cookie cookieToken = CookieActions.SetCookie("session-id", token, 1); Response.Cookies.Append(cookieToken.Key, cookieToken.Value, cookieToken.Option); Cookie cookieUserId = CookieActions.SetCookie("user-id", loginUser.IdUser.ToString(), 1); Response.Cookies.Append(cookieUserId.Key, cookieUserId.Value, cookieUserId.Option); var userLogin = mapper.Map <UserDto>(loginUser); return(Ok(userLogin)); }
private static string GetCurrentSession() { var cookie = HttpContext.Current.Request.Cookies.Get(CookieActions.GetSessionCookieName()); if (cookie != null) { return(cookie.Value); } return(""); }
public async Task <PartialViewResult> UpdateBenchmarkBasket(long?urn, CookieActions withAction) { if (urn.HasValue) { switch (withAction) { case CookieActions.SetDefault: await _benchmarkBasketService.SetSchoolAsDefaultAsync(urn.GetValueOrDefault()); break; case CookieActions.Add: await _benchmarkBasketService.AddSchoolToBenchmarkListAsync(urn.GetValueOrDefault()); break; case CookieActions.Remove: await _benchmarkBasketService.RemoveSchoolFromBenchmarkListAsync(urn.GetValueOrDefault()); break; case CookieActions.RemoveAll: _benchmarkBasketService.ClearSchoolBenchmarkList(); break; case CookieActions.UnsetDefault: _benchmarkBasketService.UnsetDefaultSchool(); break; default: break; } } else { _benchmarkBasketService.ClearSchoolBenchmarkList(); } return(PartialView("Partials/BenchmarkBasketControls", _benchmarkBasketService.GetSchoolBenchmarkList())); }
public IEnumerable <WeatherForecast> Get() { Response.Headers.Add("testsf", "valeurtest123"); CookieActions cookie = new CookieActions { response = Response, request = Request }; cookie.SetCookie("testcookie", "testvaluecookie", 60); var rng = new Random(); return(Enumerable.Range(1, 5).Select(index => new WeatherForecast { Date = DateTime.Now.AddDays(index), TemperatureC = rng.Next(-20, 55), Summary = Summaries[rng.Next(Summaries.Length)], Town = Towns[rng.Next(Towns.Length)] }) .ToArray()); }
public void UpdateManualComparisonListCookie(CookieActions withAction, BenchmarkSchoolModel benchmarkSchool = null) { HttpCookie cookie = null; switch (withAction) { case CookieActions.Add: cookie = AddSchoolToCookie(benchmarkSchool, CookieNames.COMPARISON_LIST_MANUAL); break; case CookieActions.Remove: cookie = RemoveSchoolFromCookie(benchmarkSchool, CookieNames.COMPARISON_LIST_MANUAL); break; case CookieActions.SetDefault: cookie = SetDefaultSchoolInCookie(benchmarkSchool, CookieNames.COMPARISON_LIST_MANUAL); break; case CookieActions.UnsetDefault: cookie = UnsetDefaultSchoolInCookie(CookieNames.COMPARISON_LIST_MANUAL); break; case CookieActions.RemoveAll: cookie = RemoveAllSchoolsFromCookie(CookieNames.COMPARISON_LIST_MANUAL); break; case CookieActions.AddDefaultToList: cookie = AddDefaultSchoolToListInCookie(CookieNames.COMPARISON_LIST_MANUAL); break; } if (cookie != null) { cookie.HttpOnly = false; cookie.Secure = HttpContext.Current.Request.IsSecureConnection; HttpContext.Current.Response.Cookies.Add(cookie); } }
public void UpdateSchoolComparisonListCookie(CookieActions withAction, BenchmarkSchoolModel benchmarkSchool = null) { HttpCookie cookie = null; switch (withAction) { case CookieActions.Add: cookie = AddSchoolToCookie(benchmarkSchool, CookieNames.COMPARISON_LIST); break; case CookieActions.Remove: cookie = RemoveSchoolFromCookie(benchmarkSchool, CookieNames.COMPARISON_LIST); break; case CookieActions.SetDefault: cookie = SetDefaultSchoolInCookie(benchmarkSchool, CookieNames.COMPARISON_LIST); break; case CookieActions.UnsetDefault: cookie = UnsetDefaultSchoolInCookie(CookieNames.COMPARISON_LIST); break; case CookieActions.RemoveAll: cookie = RemoveAllSchoolsFromCookie(CookieNames.COMPARISON_LIST); break; case CookieActions.AddDefaultToList: cookie = AddDefaultSchoolToListInCookie(CookieNames.COMPARISON_LIST); break; } if (cookie != null) { cookie.Expires = DateTime.MaxValue; HttpContext.Current.Response.Cookies.Add(cookie); } }
protected void Application_AcquireRequestState(Object sender, EventArgs e) { Context.Items["osCurrentPTAName"] = RequestPtaName; Context.Items["osCurrentPTAUserName"] = RequestPtaUserName; Context.Items["osIsLoadingScreen"] = false; RunningInfo.InitializeRunningInfo(); RunningInfo.ESpaceHash = ConfigurationManager.AppSettings["OutSystems.HubEdition.EspaceCompilationHash"]; RunningInfo.ESpaceVersionToken = ConfigurationManager.AppSettings["OutSystems.HubEdition.EspaceVersionToken"]; RunningInfo.ESpaceVersionId = int.Parse(ConfigurationManager.AppSettings["OutSystems.HubEdition.EspaceVersionID"]); RunningInfo.DebugMode = false; // Skips internal pages if (Request.FilePath.ToLowerInvariant().EndsWith("/_ping.aspx") || Request.FilePath.ToLowerInvariant().EndsWith("/_queriescoverage.aspx") || Request.FilePath.ToLower().EndsWith("/_debugger.asmx") || Request.FilePath.ToLower().EndsWith("/_debuggerevents.ashx")) { return; } if (App == null) { // Try again Application_Start(sender, e); if (Application["ApplicationStartError"] != null) { ApplicationStartErrorRedirect(); } } if (App.Tenant.PhoneConfigException != null) { Application["ApplicationStartError"] = App.Tenant.PhoneConfigException; ApplicationStartErrorRedirect(); } // Session Start HeContext heContext = Global.App.OsContext; heContext.InitSession(); var sessionCookieKey = Response.Cookies.AllKeys.FirstIfSingleOrDefault(c => c == CookieActions.GetSessionCookieName()); if (sessionCookieKey != null) { var sessionCookie = Response.Cookies.Get(sessionCookieKey); if (sessionCookie != null && Settings.GetBool(Settings.Configs.EnforceSessionCookiesSecure)) { sessionCookie.Secure = true; } } if (Context.Session == null || heContext.Session.NeedsSessionStart(App.eSpaceName)) { if (Request.Path.ToLowerInvariant().EndsWith("_SmsHandler.aspx")) { Global.App.OsContext.Session["TerminalType"] = "SMS"; Global.App.OsContext.Session["MSISDN"] = Global.App.OsContext.MOMsg.MSISDN; } else if (Request.Path.ToLowerInvariant().EndsWith("smshandler.asmx")) { Global.App.OsContext.Session["TerminalType"] = "SMS"; Global.App.OsContext.Session["MSISDN"] = Request.Headers["MSISDN"]; } else { Global.App.OsContext.Session["TerminalType"] = "WEB"; Global.App.OsContext.Session["MSISDN"] = ""; } if (Application["ApplicationStartError"] != null) { // Try again Application_Start(sender, e); } if (Application["ApplicationStartError"] != null) { ApplicationStartErrorRedirect(); } if (Context.Session != null) { ExtendedActions.AutoLogin(App, App.OsContext.Session); RunOnSessionStart(); } } /* * else { * * } */ // Process visit cookies if (RuntimePlatformUtils.ShouldCreateCookieForRequest()) { if (Request.CurrentExecutionFilePath.ToLowerInvariant().EndsWith(".aspx")) { var osVisitorCookie = Request.Cookies["osVisitor"]; var osVisitCookie = Request.Cookies["osVisit"]; if (osVisitorCookie == null || !GuidUtils.IsGuid(osVisitorCookie.Value)) { osVisitorCookie = new HttpCookie("osVisitor", Guid.NewGuid().ToString()); osVisitorCookie.Expires = DateTime.Now.AddYears(100); // forever SecureCookieUtils.setSecureCookie(osVisitorCookie, heContext.Context.Response); } if (osVisitCookie == null || !GuidUtils.IsGuid(osVisitCookie.Value)) { osVisitCookie = new HttpCookie("osVisit", Guid.NewGuid().ToString()); heContext.Session["osIsNewVisit"] = true; } osVisitCookie.Expires = DateTime.Now.AddMinutes(30); SecureCookieUtils.setSecureCookie(osVisitCookie, heContext.Context.Response); Context.Items["osVisitor"] = osVisitorCookie.Value; Context.Items["osVisit"] = osVisitCookie.Value; } } App.OsContext.Session[GenericExtendedActions.ReqAuditCountSessionName] = 0; // Default Multilingual state if (!App.MultilingualEnabled) { GenericExtendedActions.SetCurrentLocale(heContext, ""); } else { string localeHeader = heContext.OsISAPIFilter.GetLocale(Request); if (localeHeader != null) { try { GenericExtendedActions.SetCurrentLocale(heContext, localeHeader); } catch {} } } }
public TrustComparisonListModel UpdateTrustComparisonListCookie(CookieActions withAction, int?companyNo = null, string matName = null) { TrustComparisonListModel comparisonList = null; HttpCookie cookie = HttpContext.Current.Request.Cookies[CookieNames.COMPARISON_LIST_MAT]; switch (withAction) { case CookieActions.SetDefault: if (cookie is null) { cookie = new HttpCookie(CookieNames.COMPARISON_LIST_MAT); comparisonList = new TrustComparisonListModel(companyNo.GetValueOrDefault(), matName) { Trusts = new List <BenchmarkTrustModel> { new BenchmarkTrustModel(companyNo.GetValueOrDefault(), matName) } }; } else { comparisonList = JsonConvert.DeserializeObject <TrustComparisonListModel>(cookie.Value, new JsonSerializerSettings() { StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true) }); comparisonList.DefaultTrustCompanyNo = companyNo.GetValueOrDefault(); comparisonList.DefaultTrustName = matName; if (comparisonList.Trusts.All(s => s.CompanyNo != companyNo)) { comparisonList.Trusts.Add(new BenchmarkTrustModel(companyNo.GetValueOrDefault(), matName)); } } break; case CookieActions.Add: if (cookie == null) { cookie = new HttpCookie(CookieNames.COMPARISON_LIST_MAT); comparisonList = new TrustComparisonListModel(companyNo.GetValueOrDefault(), matName) { Trusts = new List <BenchmarkTrustModel> { new BenchmarkTrustModel(companyNo.GetValueOrDefault(), matName) } }; } else { comparisonList = JsonConvert.DeserializeObject <TrustComparisonListModel>(cookie.Value, new JsonSerializerSettings() { StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true) }); if (comparisonList.Trusts.Any(s => s.CompanyNo == companyNo)) { throw new ApplicationException(ErrorMessages.DuplicateTrust); } else { comparisonList.Trusts.Add(new BenchmarkTrustModel(companyNo.GetValueOrDefault(), matName)); } } break; case CookieActions.Remove: comparisonList = JsonConvert.DeserializeObject <TrustComparisonListModel>(cookie.Value, new JsonSerializerSettings() { StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true) }); comparisonList.Trusts.Remove(new BenchmarkTrustModel(companyNo.GetValueOrDefault())); break; case CookieActions.RemoveAll: if (cookie != null) { comparisonList = JsonConvert.DeserializeObject <TrustComparisonListModel>(cookie.Value, new JsonSerializerSettings() { StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true) }); comparisonList.Trusts.Clear(); } break; case CookieActions.AddDefaultToList: comparisonList = JsonConvert.DeserializeObject <TrustComparisonListModel>(cookie.Value, new JsonSerializerSettings() { StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true) }); if (comparisonList.Trusts.All(s => comparisonList.DefaultTrustCompanyNo != companyNo)) { comparisonList.Trusts.Add(new BenchmarkTrustModel(comparisonList.DefaultTrustCompanyNo, comparisonList.DefaultTrustName)); } break; } if (cookie != null) { cookie.Value = JsonConvert.SerializeObject(comparisonList, new JsonSerializerSettings() { StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true) }); cookie.Expires = DateTime.MaxValue; cookie.HttpOnly = false; cookie.Secure = HttpContext.Current.Request.IsSecureConnection; HttpContext.Current.Response.Cookies.Add(cookie); return(comparisonList); } return(null); }