예제 #1
0
        public async Task <IHttpActionResult> PostSession(int uid, string userName, int licenseLevel, bool isSso = false)
        {
            try
            {
                var session = await _repo.BeginSession(uid, userName, licenseLevel, isSso, id => _sessions.Remove(id));

                if (session == null)
                {
                    throw new KeyNotFoundException();
                }

                var token = Session.Convert(session.SessionId);
                _sessionsCache.Add(token, session, DateTimeOffset.UtcNow.Add(SessionsCacheSettings.SessionCacheExpiration));
                InsertSession(session);
                var response = Request.CreateResponse(HttpStatusCode.OK);
                response.Headers.Add("Session-Token", token);

                return(ResponseMessage(response));
            }
            catch (KeyNotFoundException)
            {
                return(NotFound());
            }
            catch (Exception ex)
            {
                await _log.LogError(WebApiConfig.LogSourceSessions, ex);

                return(InternalServerError());
            }
        }