Exemple #1
0
 public HttpResponseMessage Auth([FromBody] UserRegistrationInfo userRegisterInfo)
 {
     if (!ModelState.IsValid)
     {
         return(new HttpResponseMessage(HttpStatusCode.BadRequest));
     }
     try
     {
         var session = authenticator.Authenticate(userRegisterInfo.Login, userRegisterInfo.Password);
         var cookie  = new CookieHeaderValue("SessionId", session.SessionId.ToString());
         cookie.Expires = DateTimeOffset.Now.AddMonths(1);
         cookie.Domain  = Request.RequestUri.Host;
         cookie.Path    = "/";
         var response = Request.CreateResponse <SessionState>(HttpStatusCode.OK, session);
         response.Headers.AddCookies(new CookieHeaderValue[] { cookie });
         return(response);
     }
     catch (UserNotFoundException)
     {
         return(new HttpResponseMessage(HttpStatusCode.NotFound));
     }
     catch (Exception)
     {
         return(new HttpResponseMessage(HttpStatusCode.Conflict));
     }
 }
Exemple #2
0
 public IHttpActionResult Auth([FromBody] UserRegistrationInfo userRegisterInfo)
 {
     if (!ModelState.IsValid)
     {
         return(this.BadRequest());
     }
     try
     {
         var session = authenticator.Authenticate(userRegisterInfo.Login, userRegisterInfo.Password);
         return(this.Ok(session));
     }
     catch (UserNotFoundException)
     {
         return(this.NotFound());
     }
     catch (Exception)
     {
         return(this.Conflict());
     }
 }
 public IHttpActionResult Auth([FromBody] UserAuthorizationInfo userAuthorizationInfo)
 {
     if (!ModelState.IsValid)
     {
         return(this.BadRequest(ModelState));
     }
     if (userAuthorizationInfo == null)
     {
         return(this.BadRequest("Body must be not null"));
     }
     try
     {
         var session = authenticator.Authenticate(userAuthorizationInfo.Login, userAuthorizationInfo.Password);
         return(this.Ok(session));
     }
     catch (UserNotFoundException)
     {
         return(this.NotFound());
     }
     catch (Exception)
     {
         return(this.Conflict());
     }
 }