Exemplo n.º 1
0
        public IActionResult Login(LoginInputDto input)
        {
            if (!CheckPwd(input))
            {
                return(Json(new ResultDto()
                {
                    Message = "invalid username or password"
                }));
            }
            var token = JwtHelper.GenerateJwtToken(options.Secret, new Dictionary <string, string>
            {
                { "username", input.UserName },
                { "logintime", DateTime.Now.ToString() }
            });

            ResponseCookie.Add(new HttpCookie
            {
                Name  = "authorization",
                Value = token
            });
            return(Json(new ResultDto()
            {
                Success = true
            }));
        }
Exemplo n.º 2
0
        public void SetTempData(PipelineContext context, IDictionary <string, object> tempData)
        {
            if (tempData.Keys.Count <= 0)
            {
                return;
            }

            var serializeObject = JsonConvert.SerializeObject(tempData);

            // Temporary logging to see if we're outputting commas in cookies, we shouldnt be as it can b0rk things.
            if (serializeObject != null && serializeObject.Contains(","))
            {
                log.Warning("Temp data contains a comma `{0}`", serializeObject);
            }

            var cookie = new ResponseCookie(
                "temp",
                value: serializeObject,
                secure: true,
                httpOnly: false,
                domain: GetCookieDomain(context.Request)
                );

            context.Response.Cookies.Set(cookie);
        }
Exemplo n.º 3
0
        private void WriteResponseCookies(IRequest originalRequest, IResponse originalResponse, HttpWebResponse response)
        {
            if (response.Cookies != null && response.Cookies.Count > 0)
            {
                foreach (Cookie cookie in response.Cookies)
                {
                    string path = cookie.Path;
                    if (0 == string.Compare(path, originalRequest.Uri.AbsolutePath, true))
                    {
                        path = "/";
                    }

                    ResponseCookie constructedCookie = new ResponseCookie(cookie.Name, cookie.Value, cookie.Expires);
                    constructedCookie.Value = cookie.Value;
                    constructedCookie.Path  = path;

                    /*constructedCookie.Domain = GetRemoteHost(originalRequest);
                     * constructedCookie.HttpOnly = cookie.HttpOnly;
                     * constructedCookie.Secure = cookie.Secure;*/
                    constructedCookie.Expires = cookie.Expires;

                    originalResponse.Cookies.Add(constructedCookie);
                }
            }
        }
Exemplo n.º 4
0
        static public Cookie adaptFromResponseCookie(ResponseCookie aCookie)
        {
            var cookie = new Cookie(aCookie.Name, aCookie.Value, aCookie.Path, null);

            cookie.Expires = aCookie.Expires;

            return(cookie);
        }
Exemplo n.º 5
0
 public void Test()
 {
     DateTime expires = DateTime.Now;
     ResponseCookie cookie = new ResponseCookie("jonas", "mycontent", expires);
     Assert.Equal(expires, cookie.Expires);
     Assert.Equal("jonas", cookie.Name);
     Assert.Equal("mycontent", cookie.Value);
 }
Exemplo n.º 6
0
        public void Test()
        {
            DateTime       expires = DateTime.Now;
            ResponseCookie cookie  = new ResponseCookie("jonas", "mycontent", expires);

            Assert.Equal(expires, cookie.Expires);
            Assert.Equal("jonas", cookie.Name);
            Assert.Equal("mycontent", cookie.Value);
        }
        private void TryAddCookies(CookieCollection cookies, IHttpResponse aResponse)
        {
            for (int i = 0; i < cookies.Count; i++)
            {
                string   cookieValue  = cookies[i].Value;
                string   cookieKey    = cookies[i].Name;
                DateTime cookieExpire = cookies[i].Expires;

                ResponseCookie newCookie = new ResponseCookie(cookieKey, cookieValue, cookieExpire);
                aResponse.Cookies.Add(newCookie);
            }
        }
        public void Set(ResponseCookie cookie)
        {
            this.cookies.Add(cookie.Name, cookie);

            this.responseCookies.Append(cookie.Name, cookie.Value, new CookieOptions
            {
                Domain   = cookie.Domain,
                Expires  = cookie.Expires,
                HttpOnly = cookie.HttpOnly,
                Path     = cookie.Path,
                Secure   = cookie.Secure
            });
        }
Exemplo n.º 9
0
 internal void CompleteResponseHeader()
 {
     if (ResponseCookie.Count > 0)
     {
         SetHeader(HeaderFields.SetCookie, ResponseCookie.ToString());
     }
     if (ContentCharset.Length > 0)
     {
         SetHeader(HeaderFields.ContenType, $"{ContentType}; charset={ContentCharset}");
     }
     else
     {
         SetHeader(HeaderFields.ContenType, ContentType);
     }
     SetHeader(HeaderFields.Date, DateTime.Now.ToString("R"));
 }
Exemplo n.º 10
0
        public void Set(ResponseCookie cookie)
        {
            this.cookies.Add(cookie.Name, cookie);

            var httpCookie = new HttpCookie(cookie.Name, cookie.Value)
            {
                Domain   = cookie.Domain,
                Path     = cookie.Path,
                HttpOnly = cookie.HttpOnly,
                Secure   = cookie.Secure
            };

            if (cookie.Expires.HasValue)
            {
                httpCookie.Expires = cookie.Expires.Value;
            }
        }
        public HttpResponse Nikol(HttpRequest request)
        {
            var body       = $"<h1>Nikol</h1>";
            var bodyAsByte = Encoding.UTF8.GetBytes(body);

            var response       = new HttpResponse(bodyAsByte);
            var responseCookie = new ResponseCookie("sid=testtest123")
            {
                IsHttpOnly = true,
                MaxAge     = 60
            };
            var responseCookie2 = new ResponseCookie("sid2=aaaaaaaa")
            {
                MaxAge = 60 * 60
            };

            return(CookieValidation.CookieSender(request, response, responseCookie, responseCookie2));
        }
        public void Set(ResponseCookie cookie)
        {
            this.cookies.Add(cookie.Name, cookie);

            var httpCookie = new HttpCookie(cookie.Name, cookie.Value)
            {
                Domain   = cookie.Domain,
                Path     = cookie.Path,
                HttpOnly = cookie.HttpOnly,
                Secure   = cookie.Secure,
                SameSite = GetSameSiteMode(cookie.SameSiteMode),
            };

            if (cookie.Expires.HasValue)
            {
                httpCookie.Expires = cookie.Expires.Value;
            }

            this.aspNetCookies.Add(httpCookie);
        }
Exemplo n.º 13
0
        public void GET()
        {
            //request 请求
            HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(url);

            webReq.CookieContainer = RequestCookie;//存储网页返回的cookie值
            webReq.Method          = Method;
            //response 返回
            HttpWebResponse webResp = (HttpWebResponse)webReq.GetResponse();

            ResponseCookie.Add(webResp.Cookies);
            //获取返回的response流
            using (Stream stream = webResp.GetResponseStream())
            {
                using (StreamReader read = new StreamReader(stream, Encoder))
                {
                    html = read.ReadToEnd();
                }
            }
        }
Exemplo n.º 14
0
 public void Set(ResponseCookie cookie)
 {
     this.cookies.Add(cookie.Name, cookie);
 }
Exemplo n.º 15
0
        private void WriteResponseCookies(IRequest originalRequest, IResponse originalResponse, HttpWebResponse response)
        {
            if(response.Cookies != null && response.Cookies.Count > 0)
            {
                foreach(Cookie cookie in response.Cookies)
                {
                    string path = cookie.Path;
                    if(0 == string.Compare(path, originalRequest.Uri.AbsolutePath, true))
                        path = "/";

                    ResponseCookie constructedCookie = new ResponseCookie(cookie.Name, cookie.Value, cookie.Expires);
                    constructedCookie.Value = cookie.Value;
                    constructedCookie.Path = path;
                    /*constructedCookie.Domain = GetRemoteHost(originalRequest);
                    constructedCookie.HttpOnly = cookie.HttpOnly;
                    constructedCookie.Secure = cookie.Secure;*/
                    constructedCookie.Expires = cookie.Expires;

                    originalResponse.Cookies.Add(constructedCookie);
                }
            }
        }