コード例 #1
0
ファイル: SecurityExtensions.cs プロジェクト: pyrostic/Ombi
        /// <summary>
        /// Gets the username this could be the alias! We should always use this method when getting the username
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="session"></param>
        /// <returns>
        ///   <c>null</c> if we cannot find a user
        /// </returns>
        public string GetUsername(string username, ISession session)
        {
            var plexUser = PlexUsers.GetUserByUsername(username);

            if (plexUser != null)
            {
                return(!string.IsNullOrEmpty(plexUser.UserAlias) ? plexUser.UserAlias : plexUser.Username);
            }

            var dbUser = UserRepository.GetUserByUsername(username);

            if (dbUser != null)
            {
                var userProps = ByteConverterHelper.ReturnObject <UserProperties>(dbUser.UserProperties);
                return(!string.IsNullOrEmpty(userProps.UserAlias) ? userProps.UserAlias : dbUser.UserName);
            }

            // could be a local user
            var hasSessionKey = session[SessionKeys.UsernameKey] != null;

            if (hasSessionKey)
            {
                return((string)session[SessionKeys.UsernameKey]);
            }

            return(string.Empty);
        }
コード例 #2
0
ファイル: UserManagementModule.cs プロジェクト: ZinnerC/Ombi
        private UserManagementUsersViewModel MapLocalUser(UsersModel user, DateTime lastLoggedIn)
        {
            var features    = (Features)user.Features;
            var permissions = (Permissions)user.Permissions;

            var userProps = ByteConverterHelper.ReturnObject <UserProperties>(user.UserProperties);

            var m = new UserManagementUsersViewModel
            {
                Id = user.UserGuid,
                PermissionsFormattedString = permissions == 0 ? "None" : permissions.ToString(),
                FeaturesFormattedString    = features.ToString(),
                Username     = user.UserName,
                Type         = UserType.LocalUser,
                EmailAddress = userProps.EmailAddress,
                Alias        = userProps.UserAlias,
                LastLoggedIn = lastLoggedIn,
            };


            m.Permissions.AddRange(GetPermissions(permissions));
            m.Features.AddRange(GetFeatures(features));

            return(m);
        }
コード例 #3
0
        public RequestedModel CheckRequest(string musicId)
        {
            var blobs = Repo.GetAll();
            var blob  = blobs.FirstOrDefault(x => x.MusicId == musicId);

            return(blob != null?ByteConverterHelper.ReturnObject <RequestedModel>(blob.Content) : null);
        }
コード例 #4
0
        public PlexContent GetTvShow(PlexContent[] plexShows, string title, string year, string providerId = null,
                                     int[] seasons = null)
        {
            var advanced = !string.IsNullOrEmpty(providerId);

            foreach (var show in plexShows)
            {
                if (advanced)
                {
                    if (show.ProviderId == providerId && seasons != null)
                    {
                        var showSeasons = ByteConverterHelper.ReturnObject <int[]>(show.Seasons);
                        if (seasons.Any(season => showSeasons.Contains(season)))
                        {
                            return(show);
                        }
                        return(null);
                    }
                    if (!string.IsNullOrEmpty(show.ProviderId) &&
                        show.ProviderId.Equals(providerId, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(show);
                    }
                }
                if (show.Title.Equals(title, StringComparison.CurrentCultureIgnoreCase) &&
                    show.ReleaseYear.Equals(year, StringComparison.CurrentCultureIgnoreCase))
                {
                    return(show);
                }
            }
            return(null);
        }
コード例 #5
0
        public IEnumerable <UserHelperModel> GetUsers()
        {
            var model = new List <UserHelperModel>();

            var localUsers = LocalUserRepository.GetAll();
            var plexUsers  = PlexUserRepository.GetAll();

            foreach (var user in localUsers)
            {
                var props = ByteConverterHelper.ReturnObject <UserProperties>(user.UserProperties);
                model.Add(new UserHelperModel
                {
                    Type         = UserType.LocalUser,
                    Username     = user.UserName,
                    UserAlias    = props.UserAlias,
                    EmailAddress = props.EmailAddress,
                    Permissions  = (Permissions)user.Permissions
                });
            }

            model.AddRange(plexUsers.Select(user => new UserHelperModel
            {
                Type         = UserType.LocalUser,
                Username     = user.Username,
                UserAlias    = user.UserAlias,
                EmailAddress = user.EmailAddress,
                Permissions  = (Permissions)user.Permissions
            }));

            return(model);
        }
コード例 #6
0
        public async Task <RequestedModel> CheckRequestAsync(int providerId)
        {
            var blobs = await Repo.GetAllAsync().ConfigureAwait(false);

            var blob = blobs.FirstOrDefault(x => x.ProviderId == providerId);

            return(blob != null?ByteConverterHelper.ReturnObject <RequestedModel>(blob.Content) : null);
        }
コード例 #7
0
        public RequestedModel CheckRequest(int providerId)
        {
            var blobs = Repo.GetAll();
            var blob  = blobs.FirstOrDefault(x => x.ProviderId == providerId); if (blob == null)
            {
                return(null);
            }
            var model = ByteConverterHelper.ReturnObject <RequestedModel>(blob.Content);

            model.Id = blob.Id;
            return(model);
        }
コード例 #8
0
        /// <summary>
        /// Gets the Issues, if there is no issue in the DB we return a <c>new <see cref="IssuesModel"/></c>.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public async Task <IssuesModel> GetAsync(int id)
        {
            var blob = await Repo.GetAsync(id);

            if (blob == null)
            {
                return(new IssuesModel());
            }
            var model = ByteConverterHelper.ReturnObject <IssuesModel>(blob.Content);

            return(model);
        }
コード例 #9
0
        public UserHelperModel GetUser(string username)
        {
            var localUsers = LocalUserRepository.GetUserByUsername(username);

            if (localUsers != null)
            {
                var props = ByteConverterHelper.ReturnObject <UserProperties>(localUsers.UserProperties);
                return(new UserHelperModel
                {
                    Type = UserType.LocalUser,
                    Username = localUsers.UserName,
                    UserAlias = props.UserAlias,
                    EmailAddress = props.EmailAddress,
                    Permissions = (Permissions)localUsers.Permissions,
                    UserId = localUsers.UserGuid,
                    Features = (Features)localUsers.Features
                });
            }

            var plexUsers = PlexUserRepository.GetUserByUsername(username);

            if (plexUsers != null)
            {
                return(new UserHelperModel
                {
                    Type = UserType.PlexUser,
                    Username = plexUsers.Username,
                    UserAlias = plexUsers.UserAlias,
                    EmailAddress = plexUsers.EmailAddress,
                    Permissions = (Permissions)plexUsers.Permissions,
                    UserId = plexUsers.PlexUserId,

                    Features = (Features)plexUsers.Features
                });
            }

            var embyUsers = EmbyUserRepository.GetUserByUsername(username);

            if (embyUsers != null)
            {
                return(new UserHelperModel
                {
                    Type = UserType.EmbyUser,
                    Username = embyUsers.Username,
                    UserAlias = embyUsers.UserAlias,
                    EmailAddress = embyUsers.EmailAddress,
                    Permissions = (Permissions)embyUsers.Permissions,
                    UserId = embyUsers.EmbyUserId,
                    Features = (Features)embyUsers.Features
                });
            }
            return(null);
        }
コード例 #10
0
        public RequestedModel Get(int id)
        {
            var blob = Repo.Get(id);

            if (blob == null)
            {
                return(new RequestedModel());
            }
            var model = ByteConverterHelper.ReturnObject <RequestedModel>(blob.Content);

            return(model);
        }
コード例 #11
0
        public async Task <RequestedModel> GetAsync(int id)
        {
            var blob = await Repo.GetAsync(id).ConfigureAwait(false);

            if (blob == null)
            {
                return(new RequestedModel());
            }
            var model = ByteConverterHelper.ReturnObject <RequestedModel>(blob.Content);

            return(model);
        }
コード例 #12
0
        private void ProcessMissingInformation(List <RequestQueue> requests)
        {
            if (!requests.Any())
            {
                return;
            }

            var sonarrSettings   = SonarrSettings.GetSettings();
            var sickrageSettings = SickrageSettings.GetSettings();

            var tv = requests.Where(x => x.Type == RequestType.TvShow);

            // TV
            var tvApi = new TvMazeApi();

            foreach (var t in tv)
            {
                var providerId = int.Parse(t.PrimaryIdentifier);
                var showInfo   = tvApi.ShowLookup(providerId);

                if (showInfo.externals?.thetvdb != null)
                {
                    // We now have the info
                    var tvModel = ByteConverterHelper.ReturnObject <RequestedModel>(t.Content);
                    tvModel.ProviderId = showInfo.externals.thetvdb.Value;
                    var result = ProcessTvShow(tvModel, sonarrSettings, sickrageSettings);

                    if (!result)
                    {
                        // we now have the info but couldn't add it, so add it back into the queue but with a different fault
                        t.Content   = ByteConverterHelper.ReturnBytes(tvModel);
                        t.FaultType = FaultType.RequestFault;
                        t.LastRetry = DateTime.UtcNow;
                        Repo.Update(t);
                    }
                    else
                    {
                        // Make sure it's been requested
                        var existingRequests = RequestService.GetAll();
                        var thisItem         = existingRequests.Any(x => x.Title.Equals(tvModel.Title));
                        if (!thisItem)
                        {
                            tvModel.Approved = true;
                            RequestService.AddRequest(tvModel);
                        }

                        // Successful, remove from the fault queue
                        Repo.Delete(t);
                    }
                }
            }
        }
コード例 #13
0
        public RequestedModel Get(int id)
        {
            var blob = Repo.Get(id);

            if (blob == null)
            {
                return(new RequestedModel());
            }
            var model = ByteConverterHelper.ReturnObject <RequestedModel>(blob.Content);

            model.Id = blob.Id; // They should always be the same, but for somereason a user didn't have it in the db https://github.com/tidusjar/Ombi/issues/862#issuecomment-269743847
            return(model);
        }
コード例 #14
0
ファイル: UserHelper.cs プロジェクト: anonaut/Ombi
        public IEnumerable <UserHelperModel> GetUsersWithPermission(Permissions permission)
        {
            var model = new List <UserHelperModel>();

            var localUsers = LocalUserRepository.GetAll().ToList();
            var plexUsers  = PlexUserRepository.GetAll().ToList();
            var embyUsers  = EmbyUserRepository.GetAll().ToList();

            var filteredLocal = localUsers.Where(x => ((Permissions)x.Permissions).HasFlag(permission));
            var filteredPlex  = plexUsers.Where(x => ((Permissions)x.Permissions).HasFlag(permission));
            var filteredEmby  = embyUsers.Where(x => ((Permissions)x.Permissions).HasFlag(permission));


            foreach (var user in filteredLocal)
            {
                var props = ByteConverterHelper.ReturnObject <UserProperties>(user.UserProperties);
                model.Add(new UserHelperModel
                {
                    Type         = UserType.LocalUser,
                    Username     = user.UserName,
                    UserAlias    = props.UserAlias,
                    EmailAddress = props.EmailAddress,
                    Permissions  = (Permissions)user.Permissions,
                    Features     = (Features)user.Features
                });
            }

            model.AddRange(filteredPlex.Select(user => new UserHelperModel
            {
                Type         = UserType.PlexUser,
                Username     = user.Username,
                UserAlias    = user.UserAlias,
                EmailAddress = user.EmailAddress,
                Permissions  = (Permissions)user.Permissions,
                Features     = (Features)user.Features
            }));

            model.AddRange(filteredEmby.Select(user => new UserHelperModel
            {
                Type         = UserType.EmbyUser,
                Username     = user.Username,
                UserAlias    = user.UserAlias,
                EmailAddress = user.EmailAddress,
                Permissions  = (Permissions)user.Permissions,
                Features     = (Features)user.Features
            }));


            return(model);
        }
コード例 #15
0
        public IUserIdentity GetUserFromIdentifier(Guid identifier, NancyContext context)
        {
            var user = Repo.Get(identifier.ToString());

            if (user == null)
            {
                return(null);
            }

            return(new UserIdentity
            {
                UserName = user.UserName,
                Claims = ByteConverterHelper.ReturnObject <string[]>(user.Claims)
            });
        }
コード例 #16
0
        public async Task <RequestedModel> CheckRequestAsync(string musicId)
        {
            var blobs = await Repo.GetAllAsync().ConfigureAwait(false);

            var blob = blobs.FirstOrDefault(x => x.MusicId == musicId);

            if (blob == null)
            {
                return(null);
            }
            var model = ByteConverterHelper.ReturnObject <RequestedModel>(blob.Content);

            model.Id = blob.Id;
            return(model);
        }
コード例 #17
0
        private Response UpdateUser()
        {
            var body = Request.Body.AsString();

            if (string.IsNullOrEmpty(body))
            {
                return(Response.AsJson(new JsonResponseModel {
                    Result = false, Message = "Could not save user, invalid JSON body"
                }));
            }

            var model = JsonConvert.DeserializeObject <UserManagementUpdateModel>(body);

            if (string.IsNullOrWhiteSpace(model.Id))
            {
                return(Response.AsJson(new JsonResponseModel
                {
                    Result = true,
                    Message = "Couldn't find the user"
                }));
            }

            var claims = new List <string>();

            foreach (var c in model.Claims)
            {
                if (c.Selected)
                {
                    claims.Add(c.Name);
                }
            }

            var userFound = UserMapper.GetUser(new Guid(model.Id));

            userFound.Claims = ByteConverterHelper.ReturnBytes(claims.ToArray());
            var currentProps = ByteConverterHelper.ReturnObject <UserProperties>(userFound.UserProperties);

            currentProps.UserAlias    = model.Alias;
            currentProps.EmailAddress = model.EmailAddress;

            userFound.UserProperties = ByteConverterHelper.ReturnBytes(currentProps);

            var user    = UserMapper.EditUser(userFound);
            var dbUser  = UserLoginsRepo.GetAll().FirstOrDefault(x => x.UserId == user.UserGuid);
            var retUser = MapLocalUser(user, dbUser?.LastLoggedIn ?? DateTime.MinValue);

            return(Response.AsJson(retUser));
        }
コード例 #18
0
        private async Task<Response> LoadUsers()
        {
            var localUsers = await UserMapper.GetUsersAsync();
            var model = new List<UserManagementUsersViewModel>();
            foreach (var user in localUsers)
            {
                var claims = ByteConverterHelper.ReturnObject<string[]>(user.Claims);
                var claimsString = string.Join(", ", claims);

                var userProps = ByteConverterHelper.ReturnObject<UserProperties>(user.UserProperties);

                model.Add(new UserManagementUsersViewModel
                {
                    Id = user.UserGuid,
                    Claims = claimsString,
                    Username = user.UserName,
                    Type = UserType.LocalUser,
                    EmailAddress = userProps.EmailAddress,
                    ClaimsArray = claims
                });
            }

            var plexSettings = await PlexSettings.GetSettingsAsync();
            if (!string.IsNullOrEmpty(plexSettings.PlexAuthToken))
            {
                //Get Plex Users
                var plexUsers = PlexApi.GetUsers(plexSettings.PlexAuthToken);

                foreach (var u in plexUsers.User)
                {

                    model.Add(new UserManagementUsersViewModel
                    {
                        Username = u.Username,
                        Type = UserType.PlexUser,
                        Id = u.Id,
                        Claims = "Requestor",
                        EmailAddress = u.Email,
                        PlexInfo = new UserManagementPlexInformation
                        {
                            Thumb = u.Thumb
                        }
                    });
                }
            }
            return Response.AsJson(model);
        }
コード例 #19
0
        private void ProcessTransientErrors(List <RequestQueue> requests)
        {
            var sonarrSettings   = SonarrSettings.GetSettings();
            var sickrageSettings = SickrageSettings.GetSettings();
            var cpSettings       = CpSettings.GetSettings();
            var hpSettings       = HeadphoneSettings.GetSettings();

            if (!requests.Any())
            {
                return;
            }

            foreach (var request in requests)
            {
                var  model = ByteConverterHelper.ReturnObject <RequestedModel>(request.Content);
                bool result;
                switch (request.Type)
                {
                case RequestType.Movie:
                    result = ProcessMovies(model);
                    break;

                case RequestType.TvShow:
                    result = ProcessTvShow(model, sonarrSettings, sickrageSettings);
                    break;

                case RequestType.Album:
                    result = ProcessAlbums(model, hpSettings);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (!result)
                {
                    // we now have the info but couldn't add it, so do nothing now.
                    request.LastRetry = DateTime.UtcNow;
                    Repo.Update(request);
                }
                else
                {
                    // Successful, remove from the fault queue
                    Repo.Delete(request);
                }
            }
        }
コード例 #20
0
ファイル: FaultQueueModule.cs プロジェクト: Zirus1701/Ombi
        private Negotiator Index()
        {
            var requests = RequestQueue.GetAll();

            var model = requests.Select(r => new FaultedRequestsViewModel
            {
                FaultType         = (FaultTypeViewModel)(int)r.FaultType,
                Type              = (RequestTypeViewModel)(int)r.Type,
                Title             = ByteConverterHelper.ReturnObject <RequestedModel>(r.Content).Title,
                Id                = r.Id,
                PrimaryIdentifier = r.PrimaryIdentifier,
                LastRetry         = r.LastRetry,
                Message           = r.Message
            }).ToList();

            return(View["RequestFaultQueue", model]);
        }
コード例 #21
0
        public IEnumerable <RequestedModel> GetAll()
        {
            var blobs  = Repo.GetAll().ToList();
            var retVal = new List <RequestedModel>();

            foreach (var b in blobs)
            {
                if (b == null)
                {
                    continue;
                }
                var model = ByteConverterHelper.ReturnObject <RequestedModel>(b.Content);
                model.Id = b.Id;
                retVal.Add(model);
            }
            return(retVal);
        }
コード例 #22
0
        public async Task <IEnumerable <RequestedModel> > GetAllAsync()
        {
            var blobs = await Repo.GetAllAsync().ConfigureAwait(false);

            var retVal = new List <RequestedModel>();

            foreach (var b in blobs)
            {
                if (b == null)
                {
                    continue;
                }
                var model = ByteConverterHelper.ReturnObject <RequestedModel>(b.Content);
                model.Id = b.Id;
                retVal.Add(model);
            }
            return(retVal);
        }
コード例 #23
0
        private UserManagementUsersViewModel MapLocalUser(UsersModel user, DateTime lastLoggedIn)
        {
            var claims       = ByteConverterHelper.ReturnObject <string[]>(user.Claims);
            var claimsString = string.Join(", ", claims);

            var userProps = ByteConverterHelper.ReturnObject <UserProperties>(user.UserProperties);

            var m = new UserManagementUsersViewModel
            {
                Id           = user.UserGuid,
                Claims       = claimsString,
                Username     = user.UserName,
                Type         = UserType.LocalUser,
                EmailAddress = userProps.EmailAddress,
                Alias        = userProps.UserAlias,
                ClaimsArray  = claims,
                ClaimsItem   = new List <UserManagementUpdateModel.ClaimsModel>(),
                LastLoggedIn = lastLoggedIn
            };

            // Add all of the current claims
            foreach (var c in claims)
            {
                m.ClaimsItem.Add(new UserManagementUpdateModel.ClaimsModel {
                    Name = c, Selected = true
                });
            }

            var allClaims = UserMapper.GetAllClaims();

            // Get me the current claims that the user does not have
            var missingClaims = allClaims.Except(claims);

            // Add them into the view
            foreach (var missingClaim in missingClaims)
            {
                m.ClaimsItem.Add(new UserManagementUpdateModel.ClaimsModel {
                    Name = missingClaim, Selected = false
                });
            }
            return(m);
        }
コード例 #24
0
ファイル: SecurityExtensions.cs プロジェクト: ZinnerC/Ombi
        /// <summary>
        /// Gets the username this could be the alias! We should always use this method when getting the username
        /// </summary>
        /// <param name="username">The username.</param>
        /// <returns><c>null</c> if we cannot find a user</returns>
        public string GetUsername(string username, ISession session)
        {
            var plexUser = PlexUsers.GetUserByUsername(username);

            if (plexUser != null)
            {
                if (!string.IsNullOrEmpty(plexUser.UserAlias))
                {
                    return(plexUser.UserAlias);
                }
                else
                {
                    return(plexUser.Username);
                }
            }

            var dbUser = UserRepository.GetUserByUsername(username);

            if (dbUser != null)
            {
                var userProps = ByteConverterHelper.ReturnObject <UserProperties>(dbUser.UserProperties);
                if (!string.IsNullOrEmpty(userProps.UserAlias))
                {
                    return(userProps.UserAlias);
                }
                else
                {
                    return(dbUser.UserName);
                }
            }

            // could be a local user
            var localName = session[SessionKeys.UsernameKey];

            return(localName as string);
        }
コード例 #25
0
ファイル: UserManagementModule.cs プロジェクト: ZinnerC/Ombi
        private async Task <Response> UpdateUser()
        {
            Analytics.TrackEventAsync(Category.UserManagement, Action.Update, "Updated User", Username, CookieHelper.GetAnalyticClientId(Cookies));
            var body = Request.Body.AsString();

            if (string.IsNullOrEmpty(body))
            {
                return(Response.AsJson(new JsonResponseModel {
                    Result = false, Message = "Could not save user, invalid JSON body"
                }));
            }

            var model = JsonConvert.DeserializeObject <UserManagementUpdateModel>(body);

            if (string.IsNullOrWhiteSpace(model.Id))
            {
                return(Response.AsJson(new JsonResponseModel
                {
                    Result = true,
                    Message = "Couldn't find the user"
                }));
            }

            var permissionsValue = model.Permissions.Where(c => c.Selected).Sum(c => c.Value);
            var featuresValue    = model.Features.Where(c => c.Selected).Sum(c => c.Value);

            Guid outId;

            Guid.TryParse(model.Id, out outId);
            var localUser = UserMapper.GetUser(outId);

            // Update Local User
            if (localUser != null)
            {
                localUser.Permissions = permissionsValue;
                localUser.Features    = featuresValue;

                var currentProps = ByteConverterHelper.ReturnObject <UserProperties>(localUser.UserProperties);

                // Let's check if the alias has changed, if so we need to change all the requests associated with this
                await UpdateRequests(localUser.UserName, currentProps.UserAlias, model.Alias);

                currentProps.UserAlias    = model.Alias;
                currentProps.EmailAddress = model.EmailAddress;

                localUser.UserProperties = ByteConverterHelper.ReturnBytes(currentProps);

                var user    = UserMapper.EditUser(localUser);
                var dbUser  = UserLoginsRepo.GetAll().FirstOrDefault(x => x.UserId == user.UserGuid);
                var retUser = MapLocalUser(user, dbUser?.LastLoggedIn ?? DateTime.MinValue);
                return(Response.AsJson(retUser));
            }

            var plexSettings = await PlexSettings.GetSettingsAsync();

            var plexDbUsers = await PlexUsersRepository.GetAllAsync();

            var plexUsers  = PlexApi.GetUsers(plexSettings.PlexAuthToken);
            var plexDbUser = plexDbUsers.FirstOrDefault(x => x.PlexUserId == model.Id);
            var plexUser   = plexUsers.User.FirstOrDefault(x => x.Id == model.Id);
            var userLogin  = UserLoginsRepo.GetAll().FirstOrDefault(x => x.UserId == model.Id);

            if (plexDbUser != null && plexUser != null)
            {
                // We have a user in the DB for this Plex Account
                plexDbUser.Permissions = permissionsValue;
                plexDbUser.Features    = featuresValue;

                await UpdateRequests(plexDbUser.Username, plexDbUser.UserAlias, model.Alias);

                plexDbUser.UserAlias    = model.Alias;
                plexDbUser.EmailAddress = model.EmailAddress;

                await PlexUsersRepository.UpdateAsync(plexDbUser);

                var retUser = MapPlexUser(plexUser, plexDbUser, userLogin?.LastLoggedIn ?? DateTime.MinValue);
                return(Response.AsJson(retUser));
            }

            // So it could actually be the admin
            var account = PlexApi.GetAccount(plexSettings.PlexAuthToken);

            if (plexDbUser != null && account != null)
            {
                // We have a user in the DB for this Plex Account
                plexDbUser.Permissions = permissionsValue;
                plexDbUser.Features    = featuresValue;

                await UpdateRequests(plexDbUser.Username, plexDbUser.UserAlias, model.Alias);

                plexDbUser.UserAlias = model.Alias;

                await PlexUsersRepository.UpdateAsync(plexDbUser);

                var retUser = MapPlexAdmin(account, plexDbUser, userLogin?.LastLoggedIn ?? DateTime.MinValue);
                return(Response.AsJson(retUser));
            }

            // We have a Plex Account but he's not in the DB
            if (plexUser != null)
            {
                var user = new PlexUsers
                {
                    Permissions  = permissionsValue,
                    Features     = featuresValue,
                    UserAlias    = model.Alias,
                    PlexUserId   = plexUser.Id,
                    EmailAddress = plexUser.Email,
                    Username     = plexUser.Title,
                    LoginId      = Guid.NewGuid().ToString()
                };

                await PlexUsersRepository.InsertAsync(user);

                var retUser = MapPlexUser(plexUser, user, userLogin?.LastLoggedIn ?? DateTime.MinValue);
                return(Response.AsJson(retUser));
            }
            return(null); // We should never end up here.
        }