コード例 #1
0
        private Response RequestAuthToken()
        {
            var user = this.Bind <PlexAuth>();

            if (string.IsNullOrEmpty(user.username) || string.IsNullOrEmpty(user.password))
            {
                return(Response.AsJson(new { Result = false, Message = "Please provide a valid username and password" }));
            }

            var model = PlexApi.SignIn(user.username, user.password);

            if (model?.user == null)
            {
                return(Response.AsJson(new { Result = false, Message = "Incorrect username or password!" }));
            }

            var oldSettings = PlexService.GetSettings();

            if (oldSettings != null)
            {
                oldSettings.PlexAuthToken = model.user.authentication_token;
                PlexService.SaveSettings(oldSettings);
            }
            else
            {
                var newModel = new PlexSettings
                {
                    PlexAuthToken = model.user.authentication_token
                };
                PlexService.SaveSettings(newModel);
            }

            return(Response.AsJson(new { Result = true, AuthToken = model.user.authentication_token }));
        }
コード例 #2
0
        private Response GetUsers()
        {
            var settings = PlexService.GetSettings();

            var token = settings?.PlexAuthToken;

            if (token == null)
            {
                return(Response.AsJson(new { Result = true, Users = string.Empty }));
            }

            try
            {
                var users = PlexApi.GetUsers(token);
                if (users == null)
                {
                    return(Response.AsJson(string.Empty));
                }
                if (users.User == null || users.User?.Length == 0)
                {
                    return(Response.AsJson(string.Empty));
                }

                var usernames = users.User.Select(x => x.Title);
                return(Response.AsJson(new { Result = true, Users = usernames }));
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                if (ex is WebException || ex is ApiRequestException)
                {
                    return(Response.AsJson(new { Result = false, Message = "Could not load the user list! We have connectivity problems connecting to Plex, Please ensure we can access Plex.Tv, The error has been logged." }));
                }

                return(Response.AsJson(new { Result = false, Message = ex.Message }));
            }
        }
コード例 #3
0
        private Negotiator Plex()
        {
            var settings = PlexService.GetSettings();

            return(View["Plex", settings]);
        }
コード例 #4
0
        // GET: Layout
        public ActionResult ApplicationMenu()
        {
            var model = new List <LayoutModel>();

            foreach (var app in Enum.GetValues(typeof(Applications)))
            {
                switch ((Applications)app)
                {
                case Applications.SabNZBD:
                    var sabService = SabService.GetSettings();
                    if (sabService.Enabled)
                    {
                        model.Add(
                            new LayoutModel {
                            Name = "SabNzbd", Url = "/SabNzbd"
                        });
                    }
                    break;

                case Applications.Sickbeard: break;

                case Applications.CouchPotato:
                    var cpService = CpService.GetSettings();
                    if (cpService.Enabled)
                    {
                        model.Add(
                            new LayoutModel {
                            Name = "CouchPotato", Url = "/CouchPotato"
                        });
                    }
                    break;

                case Applications.Kodi: break;

                case Applications.Sonarr:
                    var sonarrService = SonarrService.GetSettings();
                    if (sonarrService.Enabled)
                    {
                        model.Add(
                            new LayoutModel {
                            Name = "Sonarr", Url = "/Sonarr"
                        });
                    }
                    break;

                case Applications.Plex:
                    var plexService = PlexService.GetSettings();
                    if (plexService.Enabled)
                    {
                        model.Add(
                            new LayoutModel {
                            Name = "Plex", Url = "/Plex"
                        });
                    }
                    break;

                case Applications.NzbGet:
                    var nzbgetService = NzbService.GetSettings();
                    if (nzbgetService.Enabled)
                    {
                        model.Add(
                            new LayoutModel {
                            Name = "NzbGet", Url = "/NzbGet"
                        });
                    }
                    break;

                case Applications.Headphones: break;

                default:
                    throw new ArgumentOutOfRangeException("application");
                }
            }

            return(PartialView("NavBarItems", model));
        }