protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { CookieHelper cookieHelper = new CookieHelper("52cos"); cookieHelper.DeleteCookie("user_id"); cookieHelper.DeleteCookie("pwd"); Session["UserInfo"] = null; } }
public JsonResult Login(string username, string password, bool rememberMe) { var data = db.EdsaLogins.Where(x => x.username == username && x.password == password).FirstOrDefault(); if (data != null) { if (rememberMe) { string encryptedPass = ManagePassword.EncryptedPassword(password); CookieHelper.CreateUserCookie(username, encryptedPass); } else { CookieHelper.DeleteCookie(); } // Primary Key Session["Id"] = data.id; Session["Username"] = data.username; Session["Password"] = data.password; // User Id Session["UserId"] = data.UserId; Session["userType"] = data.userType; return(Json(new { success = true, responseText = "Login Success!" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, responseText = "Invalid Username or Password" }, JsonRequestBehavior.AllowGet)); } }
public PartialViewResult RemoveIngredient(Guid id) { HttpCookie cookie; ICollection <IngredientCreateViewModel> ingredients; if (CookieHelper.CookieExists(currentRecipeCookie, out cookie)) { ingredients = CookieHelper.ReadCookie <ICollection <IngredientCreateViewModel> >(cookie, createdRecipeIngredients); if (ingredients == null) { CookieHelper.DeleteCookie(currentRecipeCookie); } else { IngredientCreateViewModel ingredient = ingredients.First(i => i.ProductId == id); if (ingredient != null) { ingredients.Remove(ingredient); CookieHelper.UpdateCookie <ICollection <IngredientCreateViewModel> >(cookie, createdRecipeIngredients, ingredients); } } } else { ingredients = new List <IngredientCreateViewModel>(); } return(PartialView("_CreatedRecipeIngredients", ingredients)); }
public Response ClearToken() { Response res = new Response(); CookieHelper cookie = new CookieHelper(_accessor.HttpContext); cookie.DeleteCookie("userToken"); return(res); }
public ActionResult Login(string returnUrl) { //if(ViewHelp.GetUserId()!=0) // return RedirectToLocal(returnUrl); CookieHelper.DeleteCookie(StaticKey.CookieAccountKey); ViewBag.ReturnUrl = returnUrl; return(View()); }
public Response setToken(string token) { Response res = new Response(); CookieHelper cookie = new CookieHelper(_accessor.HttpContext); cookie.DeleteCookie("userToken"); cookie.AddCookie("userToken", token, DateTime.Now.AddDays(30)); return(res); }
private void Events_AfterUserCreate(UserAfterCreateEventArgs e) { var afterCreatedCookie = CookieHelper.GetCookie(SamlCookieName); if (afterCreatedCookie == null) { return; } var samlTokenData = SamlTokenData.GetTokenDataFromDatabase(afterCreatedCookie.Value); if (samlTokenData == null) { return; } //destroy secure cookie for new user if cookie is still present CookieHelper.DeleteCookie(afterCreatedCookie.Value); //also cleanup our afterCreatedCookie CookieHelper.DeleteCookie(afterCreatedCookie.Name); //update the samlTokenData now that we know the user ID and cleanup the cookie used by the login samlTokenData.UserId = e.Id.Value; //Update the cookie SAMLToken Data to have the UserId now that its an existing user to fire the after authenticated events (which also removes the cookie) var tokenKey = samlTokenData.SaveTokenDataToDatabase(); var afterAuthenticatedCookie = new HttpCookie(clientType, tokenKey) { Expires = DateTime.Now.AddHours(8), HttpOnly = true }; CookieHelper.AddCookie(afterAuthenticatedCookie); if (PersistClaims) { SqlData.SaveSamlToken(samlTokenData); } var apiUser = _usersApi.Get(new UsersGetOptions() { Id = e.Id.Value }); //raise new SamlUserCreated Event try { SamlEvents.Instance.OnAfterUserCreate(apiUser, samlTokenData); } catch (Exception ex) { _eventLogApi.Write("SamlOAuthClient Error OnAfterUserCreate: " + ex.Message + " : " + ex.StackTrace, new EventLogEntryWriteOptions() { Category = "SAML", EventId = 1, EventType = "Error" }); } }
public ActionResult RSVP() { // Clear cookie CookieHelper.DeleteCookie("gid"); AuthenticationViewModel viewModel = new AuthenticationViewModel(); return(View(viewModel)); }
public ActionResult DeleteCookie() { CookieHelper.DeleteCookie("username"); CookieHelper.DeleteCookie("userid"); //if (Request.Cookies["username"] != null) //{ // Response.Cookies["username"].Expires = DateTime.Now.AddDays(-1); //} return(Redirect("~/Admin/Login/Index")); }
public JsonResult Logout() { Session.Abandon(); CookieHelper.DeleteCookie("app_key"); CookieHelper.DeleteCookie("app_secret"); CookieHelper.DeleteCookie("app_session"); CookieHelper.DeleteCookie("unit_id"); CookieHelper.DeleteCookie("unit_name"); CookieHelper.DeleteCookie("token"); CookieHelper.DeleteCookie("role"); return(Json(new { result = "sucess" })); }
public PartialViewResult AddIngredient(Guid id) { HttpCookie cookie; var product = ProductManager.FindById(id); IngredientCreateViewModel ingredient = new IngredientCreateViewModel { ProductId = id, Quantity = 0, ProductName = product.Name, BaseProtein = product.Protein, BaseCarbohydrate = product.Carbohydrate, BaseFat = product.Fat }; ICollection <IngredientCreateViewModel> ingredients; if (CookieHelper.CookieExists(currentRecipeCookie, out cookie)) { ingredients = CookieHelper.ReadCookie <ICollection <IngredientCreateViewModel> >(cookie, createdRecipeIngredients); if (ingredients == null) { CookieHelper.DeleteCookie(currentRecipeCookie); ingredients = new List <IngredientCreateViewModel> { ingredient }; CookieHelper.CreateCookie <ICollection <IngredientCreateViewModel> >( currentRecipeCookie, createdRecipeIngredients, ingredients, new TimeSpan(0, 30, 0)); } else { if (!ingredients.Any(i => i.ProductId == id)) { ingredients.Add(ingredient); CookieHelper.UpdateCookie <ICollection <IngredientCreateViewModel> >(cookie, createdRecipeIngredients, ingredients); } } } else { ingredients = new List <IngredientCreateViewModel> { ingredient }; CookieHelper.CreateCookie <ICollection <IngredientCreateViewModel> >( currentRecipeCookie, createdRecipeIngredients, ingredients, new TimeSpan(0, 30, 0)); } return(PartialView("_CreatedRecipeIngredients", ingredients)); }
public ActionResult CreateRecipe(AddRecipeViewModel model) { var errors = ModelState.Values.SelectMany(v => v.Errors); if (ModelState.IsValid) { var recipe = new Entities.Recipe { Name = model.Name, Description = model.Description, Vegetarian = model.Vegetarian, PreparationTime = model.PreparationTime, Added = DateTime.Now, Author = null }; List <Ingredient> ingredients = new List <Ingredient>(); ICollection <IngredientCreateViewModel> ingredientsInfo; if (CookieHelper.TryReadCookie <ICollection <IngredientCreateViewModel> >( currentRecipeCookie, createdRecipeIngredients, out ingredientsInfo)) { foreach (var ingr in ingredientsInfo) { ingredients.Add(new Ingredient { Name = ingr.Alias, ProductId = ingr.ProductId, Product = ProductManager.FindById(ingr.ProductId), Quantity = ingr.Quantity, Recipe = recipe }); } } recipe.Ingredients = ingredients; RecipeManager.AddToCategory(recipe, RecipeManager.FindCategoryById(model.CategoryId)); RecipeManager.Save(); CookieHelper.DeleteCookie(currentRecipeCookie); return(RedirectToAction("CreateResult")); } ViewBag.Categories = RecipeManager.RecipeCategories.ToSelectList <Entities.RecipeCategory, RecipeCategoryInfo>(); ViewBag.OrderedCategories = ProductManager.ProductCategories.ToOrderedSelectList(); return(View("Create")); }
public JsonResult InternalUserLogin(string username, string password, string userType, bool rememberMe) { List <EdsaUser> lstEdsaUser = db.EdsaUsers.ToList(); List <EdsaRole> lstRoles = db.EdsaRoles.ToList(); List <EdsaUserRole> lstUserRoles = db.EdsaUserRoles.ToList(); var data = (from u in lstEdsaUser join ur in lstUserRoles on u.Id equals ur.UserId join r in lstRoles on ur.RoleId equals r.Id where u.Username == username && u.Password == password && r.Name == userType select new ViewModel { edsaUsers = u, edsaRoles = r, edsaUserRoles = ur }).ToList(); if (data.Count != 0) { if (rememberMe) { string encryptedPass = ManagePassword.EncryptedPassword(password); CookieHelper.CreateUserCookie(username, encryptedPass); } else { CookieHelper.DeleteCookie(); } Session["Id"] = data.Select(x => x.edsaUsers.Id).FirstOrDefault(); Session["Username"] = data.Select(x => x.edsaUsers.Username).FirstOrDefault(); Session["Password"] = data.Select(x => x.edsaUsers.Password).FirstOrDefault(); Session["userType"] = data.Select(x => x.edsaRoles.Name).FirstOrDefault(); return(Json(new { success = true, responseText = "Login Success!" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, responseText = "Invalid Username or Password" }, JsonRequestBehavior.AllowGet)); } }
private bool TryUpdateCreatedQuantity(Guid productId, int quantity, out ICollection <IngredientCreateViewModel> ingredients) { HttpCookie recipeCookie; if (CookieHelper.CookieExists(currentRecipeCookie, out recipeCookie)) { ingredients = CookieHelper.ReadCookie <ICollection <IngredientCreateViewModel> >( recipeCookie, createdRecipeIngredients); if (ingredients == null) { // Ciasteczko jest uszkodzone. CookieHelper.DeleteCookie(currentRecipeCookie); return(false); } IngredientCreateViewModel ing = ingredients.First(i => i.ProductId == productId); if (ing != null) { ing.Quantity = quantity; } else { var product = ProductManager.FindById(productId); if (product != null) { ingredients.Add(new IngredientCreateViewModel { ProductId = productId, ProductName = product.Name, Quantity = quantity }); } else { return(false); } } CookieHelper.UpdateCookie <ICollection <IngredientCreateViewModel> >(recipeCookie, createdRecipeIngredients, ingredients); return(true); } ingredients = null; return(false); }
private void TokenLogout(string accessHeadAndPayload, TokenManager tokenManager, HttpContextBase context) { if (!String.IsNullOrWhiteSpace(accessHeadAndPayload)) { var authCookie = CookieHelper.GetCookie(context.Request, AccessSignatureCookieName); if (authCookie == null) { throw new UnauthorizedAccessException("Missing access cookie."); } var accessSignature = authCookie.Value; var principal = tokenManager.ValidateToken(accessHeadAndPayload + "." + accessSignature, false); if (principal == null) { throw new UnauthorizedAccessException("Invalid access token."); } CookieHelper.DeleteCookie(context.Response, AccessSignatureCookieName); CookieHelper.DeleteCookie(context.Response, AccessHeadAndPayloadCookieName); CookieHelper.DeleteCookie(context.Response, RefreshSignatureCookieName); context.Response.StatusCode = HttpResponseStatusCode.Ok; } }
public override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); HttpCookie cookie = filterContext.HttpContext.Request.Cookies[ActionStatusCookieInvalidatorActionFilter.MessageCookieName]; if (cookie != null && !String.IsNullOrWhiteSpace(cookie.Value)) { String readValue = cookie.Value; String message = readValue.Substring(1); bool isSuccess = (cookie.Value[0] == '1'); Result result; if (isSuccess) { result = Result.SuccessResult(message); } else { result = Result.ErrorResult(message); } filterContext.Controller.ViewData.Add(new KeyValuePair <string, object>(ActionStatusCookieInvalidatorActionFilter.ViewDataKey, result)); CookieHelper.DeleteCookie(ActionStatusCookieInvalidatorActionFilter.MessageCookieName); } }
private void TokenLogout(string accessHeadAndPayload, TokenManager tokenManager, HttpContextBase context) { if (!String.IsNullOrWhiteSpace(accessHeadAndPayload)) { var authCookie = CookieHelper.GetCookie(context.Request, AccessSignatureCookieName); if (authCookie == null) { throw new UnauthorizedAccessException("Missing access cookie."); } var accessSignature = authCookie.Value; var principal = tokenManager.ValidateToken(accessHeadAndPayload + "." + accessSignature, false); if (principal == null) { throw new UnauthorizedAccessException("Invalid access token."); } bool.TryParse(AuthenticationHelper.GetRequestParameterValue(context, "ultimateLogout"), out var ultimateLogout); // ultimately log out only if the user has not been logged out already, if he has, just a local logout executes if (ultimateLogout || Configuration.Security.DefaultUltimateLogout) { ultimateLogout = !UserHasLoggedOut(tokenManager, principal.Identity.Name, accessHeadAndPayload, out var portalPrincipal); using (AuthenticationHelper.GetSystemAccount()) { context.User = portalPrincipal; } } _logoutExecutor?.Logout(ultimateLogout); CookieHelper.DeleteCookie(context.Response, AccessSignatureCookieName); CookieHelper.DeleteCookie(context.Response, AccessHeadAndPayloadCookieName); CookieHelper.DeleteCookie(context.Response, RefreshSignatureCookieName); context.Response.StatusCode = HttpResponseStatusCode.Ok; } }
// // POST: /Account/LogOff public ActionResult LogOff() { userAccountRepo.LogOff(ViewHelp.GetUserId()); CookieHelper.DeleteCookie(StaticKey.CookieAccountKey); return(RedirectToAction("Login")); }
void Events_AfterIdentify(UserAfterIdentifyEventArgs e) { var context = HttpContext.Current; if (context == null) { return; } if (context.Request == null) { return; } if (!context.Request.IsAuthenticated) { return; } //filter some requests basic non UI requests if (context.Request.RawUrl.ToLower().StartsWith("/socket.ashx")) { return; } if (context.Request.RawUrl.ToLower().StartsWith("/webresource.axd")) { return; } if (context.Request.RawUrl.ToLower().StartsWith("/api.ashx")) { return; } if (context.Request.RawUrl.ToLower().StartsWith("/utility/")) { return; } if (context.Request.RawUrl.ToLower().StartsWith("/cfs-filesystemfile/")) { return; } if (context.Request.RawUrl.ToLower().StartsWith("/dynamic-style")) { return; } if (context.Request.RawUrl.ToLower().StartsWith("/favicon.ico")) { return; } if (context.Request.RawUrl.ToLower().EndsWith(".css")) { return; } //check to see if our Oauth ProcessLogin() cookie exists try { var afterAuthenticatedCookie = CookieHelper.GetCookie(clientType); if (afterAuthenticatedCookie == null) { return; } var samlTokenData = SamlTokenData.GetTokenDataFromDatabase(afterAuthenticatedCookie.Value); if (samlTokenData == null) { return; } if (!samlTokenData.IsExistingUser()) { return; } if (samlTokenData.UserId != e.Id.Value) { return; //check to see that the logged in user and ProcessLogin() user have the same ID; } if (Guid.TryParse(afterAuthenticatedCookie.Value, out var tokenKey)) { SamlTokenData.DeleteTokenDataFromDatabase(afterAuthenticatedCookie.Value); } CookieHelper.DeleteCookie(afterAuthenticatedCookie.Value); CookieHelper.DeleteCookie(afterAuthenticatedCookie.Name); //Get the API user and the last SAML token to keep things API friendly var apiUser = _usersApi.Get(new UsersGetOptions() { Id = e.Id.Value }); SamlEvents.Instance.OnAfterAuthenticate(apiUser, samlTokenData); } catch (Exception ex) { _eventLogApi.Write("SamlOAuthClient Error OnAfterAuthenticate: " + ex.Message + " : " + ex.StackTrace, new EventLogEntryWriteOptions() { Category = "SAML", EventId = 1, EventType = "Error" }); } }
/// <summary> ///普通用户登出 /// </summary> public static void Exit() { CookieHelper.DeleteCookie("usertoken"); }
public static void AdminExit() { CookieHelper.DeleteCookie("dtoken"); }