public void SignOut() { ICookieFactory cookieFactory = new CookieFactory(); ICookieClient cookieClient = cookieFactory.Create(); cookieClient.Remove(AuthConfigProvider.AuthConfig.CookieName); }
public TBody GetBody() { // 获取 密钥 string secret = SecretBuilder.Build(); if (string.IsNullOrWhiteSpace(secret)) { throw new Exception("应用程序密钥(AppSecret)为空或null"); } ICookieFactory cookieFactory = new CookieFactory(); ICookieClient cookieClient = cookieFactory.Create(); if (!cookieClient.Contains(AuthConfigProvider.AuthConfig.CookieName)) { return(null); } // 获取cookie, 并解密 数据 string token = cookieClient.GetCookie(AuthConfigProvider.AuthConfig.CookieName); IAlgorithmFactory algorithmFactory = new HMACSHAAlgorithmFactory(); IJsonSerializer serializer = new JsonNetSerializer(); IDateTimeProvider provider = new UtcDateTimeProvider(); IJwtValidator validator = new JwtValidator(serializer, provider); IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder(); IJwtDecoder decoder = new JwtDecoder(serializer, validator, urlEncoder, algorithmFactory); TBody authUser = decoder.DecodeToObject <TBody>(token, secret, true); SignIn(authUser); return(authUser); }
void Start() { blockFactory = new BlockFactory(this, gameWeights, levelContainer); obstacleFactory = new ObstacleFactory(this, gameWeights); cookieFactory = new CookieFactory(this, gameWeights); CreateInitWalls(); }
private void OrderCookie() { var cookie = CookieFactory.BakeCookie(); CookieCounter.Add(cookie); CookiesRemaining--; Console.WriteLine("Bakery made cookie #" + cookie.Id); }
public Bakery() { CookieCounter = new List <Cookie>(); CookieFactory = new CookieFactory(); CookiesRemaining = SetDailyCookies(); new Thread(Run).Start(); }
public void Create_NullParameters_DoesNotThrow() { // Arrange // Act TestDelegate action = () => CookieFactory.Create(null, null); // Assert Assert.DoesNotThrow(action); }
public void BakeCookieTest() { CookieFactory cookieFactory = new CookieFactory(); Cookie cookie = cookieFactory.BakeCookie(); Assert.IsNotNull(cookie); Assert.IsTrue(cookie.CookieType.GetType() == typeof(CookieFlyWeight.ChocolateCookie) || cookie.CookieType.GetType() == typeof(CookieFlyWeight.BlueberryCookie) || cookie.CookieType.GetType() == typeof(CookieFlyWeight.HotDogCookie)); }
// AJAX: /ShoppingCart/AddItemToShoppingCart/ public JsonResult AddItemToShoppingCart(ShoppingCartItemViewModel itemModel) { // Check if there's a cart for this session ShoppingCart shoppingCart = _shoppingCartService.GetShoppingCart(CookieFactory.GetShoppingCartCookie(Request, Response)); ShoppingCartItem item = Mapper.Map <ShoppingCartItemViewModel, ShoppingCartItem>(itemModel); ShoppingCartItem retItem = _shoppingCartItemService.AddOrUpdateShoppingCartItem(item, shoppingCart.Guid); _shoppingCartItemService.SaveShoppingCartItem(); ShoppingCartItemViewModel newModel = Mapper.Map <ShoppingCartItem, ShoppingCartItemViewModel>(retItem); decimal total = _offerService.GetTotal(shoppingCart, _itemService.GetItems()); return(Json(new { newModel, total = total }, JsonRequestBehavior.AllowGet)); }
public void GetActivitiesIdCookies(HttpResponseBase resp, DateTime dt) { IActivityService activityService = ServiceBuilder.BuildActivityService(); ResponseStatus respStatus = activityService.GetActivityIds(ref activitiesId); if (respStatus == ResponseStatus.SUCCESS) { if (activitiesId.Count > 0) { for (int i = 0; i < activitiesId.Count; ++i) { CookieFactory cf = CookieFactory.Instance(); cf.CreateCookie("ACY" + i, activitiesId[i] + "", dt, resp); } } } }
// AJAX: /ShoppingCart/RemoveFromShoppingCart/ public JsonResult RemoveFromShoppingCart(string name) { // Check if there's a cart for this session ShoppingCart shoppingCart = _shoppingCartService.GetShoppingCart(CookieFactory.GetShoppingCartCookie(Request, Response)); if (shoppingCart != null) { bool success = _shoppingCartItemService.DeleteShoppingCartItemByName(name); _shoppingCartService.SaveShoppingCart(); decimal total = _offerService.GetTotal(shoppingCart, _itemService.GetItems()); return(Json(new { success = success, total = total }, JsonRequestBehavior.AllowGet)); } return(Json(null, JsonRequestBehavior.AllowGet)); }
public void SignIn(TBody body) { // 获取 密钥 string secret = SecretBuilder.Build(); if (string.IsNullOrWhiteSpace(secret)) { throw new Exception("应用程序密钥(AppSecret)为空或null"); } ICookieFactory cookieFactory = new CookieFactory(); ICookieClient cookieClient = cookieFactory.Create(); cookieClient.SetCookie(AuthConfigProvider.AuthConfig.CookieName, body.SerializeObject(), AuthConfigProvider.AuthConfig.Expires, value => { ICryptor cryptor = new DesCryptor(SecretBuilder.AppKey, secret); return(cryptor.Encrypt(value)); }); }
public ActionResult Index() { IEnumerable <Item> items = _itemService.GetItems().ToList(); IEnumerable <ItemViewModel> modelItems = Mapper.Map <IEnumerable <Item>, IEnumerable <ItemViewModel> >(items); // Check if there's a cart for this session ShoppingCart shoppingCart = _shoppingCartService.GetShoppingCart(CookieFactory.GetShoppingCartCookie(Request, Response)); _shoppingCartService.SaveShoppingCart(); ShoppingCartViewModel cartModel = Mapper.Map <ShoppingCart, ShoppingCartViewModel>(shoppingCart); return(View(new ItemsAndCartViewModel { Items = modelItems, ShoppingCart = cartModel, Total = _offerService.GetTotal(shoppingCart, items) })); }
public void SignIn(TBody body) { // 获取 密钥 string secret = SecretBuilder.Build(); if (string.IsNullOrWhiteSpace(secret)) { throw new Exception("应用程序密钥(AppSecret)为空或null"); } // 生成加密token; IAlgorithmFactory algorithmFactory = new HMACSHAAlgorithmFactory(); IJwtAlgorithm algorithm = algorithmFactory.Create(AuthConfigProvider.AuthConfig.JwtAlgorithmType); IJsonSerializer serializer = new JsonNetSerializer(); IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder(); IJwtEncoder encoder = new JwtEncoder(algorithm, serializer, urlEncoder); string token = encoder.Encode(body, secret); // 写入Cookie ICookieFactory cookieFactory = new CookieFactory(); ICookieClient cookieClient = cookieFactory.Create(); cookieClient.SetCookie(AuthConfigProvider.AuthConfig.CookieName, token, AuthConfigProvider.AuthConfig.Expires); }
public TBody GetBody() { // 获取 密钥 string secret = SecretBuilder.Build(); if (string.IsNullOrWhiteSpace(secret)) { throw new Exception("应用程序密钥(AppSecret)为空或null"); } ICookieFactory cookieFactory = new CookieFactory(); ICookieClient cookieClient = cookieFactory.Create(); if (!cookieClient.Contains(AuthConfigProvider.AuthConfig.CookieName)) { return(null); } string token = cookieClient.GetCookie(AuthConfigProvider.AuthConfig.CookieName, value => { ICryptor cryptor = new DesCryptor(SecretBuilder.AppKey, secret); return(cryptor.Decrypt(value)); }); TBody authUser = token.DeserializeObject <TBody>(); DateTime expires = authUser.exp.AsDateTime(); if (expires < DateTime.Now) { return(null); // 已失效 } SignIn(authUser); return(authUser); }
public FluentSessionRecorder SetCookie(string name, string value, string domain = null, string path = null, DateTime?expiry = null) { var cookie = CookieFactory.Create(name, value, domain, path, expiry); return(SetCookie(cookie)); }
public ActionResult Index(long?industryId = null, long?placeId = null, string theme = null, string feature = "", bool?showForm = null) { //in this context the APIToken is the widget key bool valid = APIContext.Current.ApiToken != null && APIContext.Current.ApiToken.IsValid && !APIContext.Current.ApiToken.IsExpired; Log(); if (!valid) { throw new HttpException(403, "Api token not valid"); } if (Request.Cookies["sessionId"] == null) { return(View("~/areas/widget/views/Authorize/Authorize.cshtml")); } HttpCookie cc = CookieFactory.Create("enabled"); cc.Expires = DateTime.Now.AddDays(-1); Response.Cookies.Add(cc); Feature?startFeature = null; if (feature.ToLower() == "dashboard") { startFeature = Feature.Dashboard; } else if (feature.ToLower() == "competition") { startFeature = Feature.Competition; } else if (feature.ToLower() == "community") { startFeature = Feature.Community; } else if (feature.ToLower() == "advertising") { startFeature = Feature.Advertising; } else if (feature.ToLower() == "featureselect") { startFeature = Feature.FeatureSelect; } else if (feature.ToLower() == "select") { startFeature = Feature.Select; } WebContext.Current.StartFeature = startFeature; if (!string.IsNullOrWhiteSpace(theme)) { HttpCookie c = SizeUp.Core.Web.CookieFactory.Create("theme", theme); Response.Cookies.Add(c); } else { HttpCookie c = SizeUp.Core.Web.CookieFactory.Create("theme"); c.Expires = DateTime.Now.AddDays(-1d); Response.Cookies.Add(c); } using (var context = ContextFactory.SizeUpContext) { if (placeId != null) { WebContext.Current.CurrentPlace = Core.DataLayer.Place.Get(context, placeId); } if (industryId != null) { WebContext.Current.CurrentIndustry = Core.DataLayer.Industry.Get(context, industryId); } string urlToken = HttpUtility.UrlEncode(APIContext.Current.ApiToken.GetToken()); string urlBase = "/{0}/{1}/{2}/{3}"; string url = string.Format("/{0}?wt={1}", "widget/select", urlToken); if (WebContext.Current.CurrentPlace.Id != null && WebContext.Current.CurrentIndustry != null) { var place = WebContext.Current.CurrentPlace; var industry = WebContext.Current.CurrentIndustry; urlBase = string.Format(urlBase, place.State.SEOKey, place.County.SEOKey, place.City.SEOKey, industry.SEOKey); if (WebContext.Current.StartFeature == Feature.Advertising) { url = string.Format("/{0}{1}?wt={2}", "widget/advertising", urlBase, urlToken); } else if (WebContext.Current.StartFeature == Feature.Competition) { url = string.Format("/{0}{1}?wt={2}", "widget/competition", urlBase, urlToken); } else if (WebContext.Current.StartFeature == Feature.Dashboard) { url = string.Format("/{0}{1}?wt={2}", "widget/dashboard", urlBase, urlToken); } else if (WebContext.Current.StartFeature == Feature.Community) { url = string.Format("/{0}{1}?wt={2}", "widget/community", urlBase, urlToken); } else if (WebContext.Current.StartFeature == Feature.FeatureSelect) { url = string.Format("/{0}?wt={1}#featureSelect=true", "widget/select", urlToken); } } //wells fargo if (showForm != null) { url = string.Format("/{0}?wt={1}", "widget/select", urlToken); } return(Redirect(url)); } }
public void TestMethod() { //Arrange const string mirabeauUrl = "https://github.com/wbtstr/wbtstr"; const string mirabeauTitle = "GitHub - wbtstr/wbtstr: The uncomplicated test automation framework."; // Act I.Open("https://github.com/") .Open(UriParser.ParseWebUrl("https://github.com/")) .Type("username??") .ResizeWindow(1600, 1050) .CapturePage(out var snapshot1) .SetCookie(CookieFactory.Create(snapshot1.Cookies.Keys.First(), "Hello World!")) .SetCookie(snapshot1.Cookies.Keys.First(), "Hello World!") .WaitUntil(() => I.Find(".header-search-input").Displayed) .Focus(".header-search-input") .Find(".header-search-input", out var input) .Focus(input) .Wait(seconds: 1) .DeleteCookie(snapshot1.Cookies.Keys.First()) .Enter("wbtstr.net").In(".header-search-input") .Append("!!!").In(".header-search-input") .DoubleClick(".header-search-input") .DoubleClick(input) .Wait(seconds: 1) .MaximizeWindow() .Find(".header-search-input", out var header) .Enter("wbtstr").In(header) .Append(Keys.Enter).In(header) .Wait(seconds: 1) .Hover(".repo-list a:first-child") .Find(".repo-list a:first-child", out var firstChild) .Hover(firstChild) .Wait(seconds: 1) .Click(".repo-list a:first-child") .TakeScreenshot() .RightClick("body") .Find("body", out var body) .RightClick(body); IElement md = I.Find(".markdown-body"); string mdTagName = md.TagName; string mdSelector = md.Selector; string mdGetAttribute = md.GetAttribute("outerHTML"); string mdGetCssValue = md.GetCssValue("height"); int mdHeight = md.Height; int mdWidth = md.Width; int mdUpperLeftCornerX = md.UpperLeftCornerX; int mdUpperLeftCornerY = md.UpperLeftCornerY; string HTML = md.HTML; var h1 = I.FindMultiple("h1"); Assert.True(h1.Count >= 0); IElement b = I.ExecuteJs <IElement>("return window.document.body"); string bTagName = I.ExecuteJs <string>("return window.document.body.tagName"); long bChildElementCount = I.ExecuteJs <long>("return window.document.body.childElementCount"); bool bHasAttributes = I.ExecuteJs <bool>("return window.document.body.hasAttributes()"); var page = I.CapturePage(); var cookie = page.Cookies[page.Cookies.Keys.First()]; var value = cookie.Value; var domain = cookie.Domain; var path = cookie.Path; var secure = cookie.Secure; var isHttpOnly = cookie.IsHttpOnly; var expiry = cookie.Expiry; // Assert Assert.AreEqual(mirabeauTitle, page.Title); Assert.AreEqual(mirabeauUrl, page.Url); Assert.AreEqual(b.TagName.ToUpper(), bTagName.ToUpper()); Assert.NotZero(bChildElementCount); Assert.IsTrue(bHasAttributes); }