Esempio n. 1
0
        public IHttpActionResult Launch([FromUri, Required] LaunchRequest request)
        {
            using (var _db = new DatabaseContext())
            {
                IAuthorizationManager authorizationManager = new AuthorizationManager();
                Session session = authorizationManager.ValidateAndUpdateSession(_db, request.token);
                if (session == null)
                {
                    return(Unauthorized());
                }

                ILaunchManager launchManager  = new LaunchManager();
                LaunchResponse launchResponse = launchManager.SignLaunch(_db, session, request.appId);

                return(Ok(launchResponse));
            }
        }
Esempio n. 2
0
        public IHttpActionResult Launch([FromUri, Required] LaunchRequest request)
        {
            if (!ModelState.IsValid || request == null)
            {
                // Request does not match model
                return(Content(System.Net.HttpStatusCode.PreconditionFailed, ModelState));
            }

            using (var _db = new DatabaseContext())
            {
                // Validate session
                IAuthorizationManager authorizationManager = new AuthorizationManager(_db);
                Session session = authorizationManager.ValidateAndUpdateSession(request.Token);
                if (session == null)
                {
                    return(Content(System.Net.HttpStatusCode.Unauthorized, "Invalid session"));
                }

                // Create launch payload for client to submit
                ILaunchManager launchManager = new LaunchManager(_db);
                LaunchData     launchResponse;
                try
                {
                    launchResponse = launchManager.SignLaunch(session, request.AppId);
                }
                catch (ArgumentException)
                {
                    return(Content(System.Net.HttpStatusCode.NotFound, "Application not found"));
                }

                // Save updated (extended) session
                try
                {
                    _db.SaveChanges();
                }
                catch (DbEntityValidationException)
                {
                    _db.Entry(session).State = System.Data.Entity.EntityState.Detached;
                    return(InternalServerError());
                }

                return(Ok(launchResponse));
            }
        }