public HttpResponseMessage Create(CredentialDto credential)
        {
            string token = sessionServices.Create(
                new Credential(credential.Username, credential.Password));

            if (token == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden));
            }

            HttpResponseMessage response = Request.CreateResponse(
                HttpStatusCode.Created, new { Token = token });

            #region Please add necessary information on response headers

            // A created result should contains the resource URI. Since the user
            // has logged into the system, it should contains the correct cookie
            // setter.

            response.Headers.Location = new Uri(Url.Link("get session", new { token }), UriKind.RelativeOrAbsolute);
            response.Headers.AddCookies(new []
            {
                new CookieHeaderValue(SessionCookieKey, token)
            });

            #endregion

            return(response);
        }
Пример #2
0
        public HttpResponseMessage Create(CredentialDto credential)
        {
            string token = sessionServices.Create(
                new Credential(credential.Username, credential.Password));

            if (token == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden));
            }

            HttpResponseMessage response = Request.CreateResponse(
                HttpStatusCode.Created, new { Token = token });

            #region Please add necessary information on response headers

            // A created result should contains the resource URI. Since the user
            // has logged into the system, it should contains the correct cookie
            // setter.

            throw new NotImplementedException();

            #endregion

            return(response);
        }
        public HttpResponseMessage Create(CredentialDto credential)
        {
            string token = sessionServices.Create(
                new Credential(credential.Username, credential.Password));

            if (token == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden));
            }

            HttpResponseMessage response = Request.CreateResponse(
                HttpStatusCode.Created, new { Token = token });

            response.Headers.Location = new Uri(Url.Link("get session", new { token }), UriKind.RelativeOrAbsolute);
            response.Headers.AddCookies(
                new[]
            {
                new CookieHeaderValue(SessionCookieKey, token)
            });

            return(response);
        }