예제 #1
0
        public async Task AddOrUpdate(string id, UserDto user)
        {
            var item = await GetItemInternal(x => x.Id == id);
            if (item == null)
            {
                _items.Add(user);
            }
            else
            {
                user.CopyItem(item);
            }

            await SaveItems();
        }
예제 #2
0
 public ProfileBox()
 {
     this.DefaultStyleKey = typeof (ProfileBox);
     this.Tap += ProfileBox_Tap;
     //this.LostFocus += OnLostFocus;
     if(DesignerProperties.IsInDesignTool)
     {
         Profile = new UserDto
         {
             Name = "Scott Lovegrove",
             LastLoginDate = DateTime.Now.AddHours(-1)
         };
     }
 }
예제 #3
0
        public SideMenuUsersViewModel(ISessionManager sessionManager, IImageManager imageManager, IApiClient apiClient)
        {
            _sessionManager = sessionManager;
            _imageManager = imageManager;
            _apiClient = apiClient;

            sessionManager.UserLoggedOut += (s, e) => Image = null;
            sessionManager.UserLoggedIn += (s, e) => {
                _user = sessionManager.CurrentUser;
                DownloadImage();
            };

            _user = sessionManager.CurrentUser;
            DownloadImage();
            
            AdditionalUsers = new ObservableCollection<AdditionalUserViewModel>();
        }
예제 #4
0
        public UserLoginViewModel(UserDto user, IApiClient apiClient, IImageManager imageManager, ISessionManager sessionManager, ILogManager logManager)
        {
            _user = user;
            _apiClient = apiClient;
            _imageManager = imageManager;

            ILogger logger = logManager.GetLogger("Login");

            LoginCommand = new RelayCommand(async arg => {
                try {
                    IsInvalidLoginDetails = false;
                    await sessionManager.Login(Username, Password, RememberLogin);
                } catch (UnauthorizedAccessException) {
                    IsInvalidLoginDetails = true;
                } catch (Exception e) {
                    logger.ErrorException("Error while attempting to login", e);
                }
            });
        }
        public async Task Logout()
        {
             _playback.StopAllPlayback();

            _apiClient.CurrentUserId = null;

            var previous = CurrentUser;

            CurrentUser = null;

            if (previous != null)
            {
                EventHelper.FireEventIfNotNull(UserLoggedOut, this, EventArgs.Empty, _logger);
            }

            await _navService.NavigateToLoginPage();

            _navService.ClearHistory();
        }
예제 #6
0
        public async Task Logout()
        {
//            _playback.StopAllPlayback();

            _apiClient.CurrentUserId = null;

            UserDto previous = CurrentUser;

            CurrentUser = null;

            if (previous != null) {
                EventHelper.FireEventIfNotNull(UserLoggedOut, this, EventArgs.Empty, _logger);
            }

            //Clear auto login info
            _config.Configuration.AutoLoginConfiguration = new AutoLoginConfiguration();
            _config.SaveConfiguration();

            await _navService.Navigate(Go.To.Login());
            _navService.ClearNavigationHistory();
        }
        public async Task Login(string username, string password)
        {
            using (var provider = SHA1.Create())
            {
                var hash = provider.ComputeHash(Encoding.UTF8.GetBytes(password ?? string.Empty));

                var result = await _apiClient.AuthenticateUserAsync(username, hash);

                CurrentUser = result.User;
                _apiClient.CurrentUserId = CurrentUser.Id;
            }

            EventHelper.FireEventIfNotNull(UserLoggedIn, this, EventArgs.Empty, _logger);

            var userConfig = await _config.GetUserTheaterConfiguration(CurrentUser.Id);

            var theme = _themeManager.Themes.FirstOrDefault(i => string.Equals(i.Name, userConfig.Theme)) ?? _themeManager.DefaultTheme;

            await _themeManager.LoadTheme(theme);

            await _navService.NavigateToHomePage();

            _navService.ClearHistory();
        }
예제 #8
0
        /// <summary>
        /// Converts a User to a DTOUser
        /// </summary>
        /// <param name="user">The user.</param>
        /// <returns>DtoUser.</returns>
        /// <exception cref="System.ArgumentNullException">user</exception>
        public async Task<UserDto> GetUserDto(User user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            var dto = new UserDto
            {
                Id = user.Id.ToString("N"),
                Name = user.Name,
                HasPassword = !String.IsNullOrEmpty(user.Password),
                LastActivityDate = user.LastActivityDate,
                LastLoginDate = user.LastLoginDate,
                Configuration = user.Configuration
            };

            var image = user.PrimaryImagePath;

            if (!string.IsNullOrEmpty(image))
            {
                dto.PrimaryImageTag = Kernel.Instance.ImageManager.GetImageCacheTag(user, ImageType.Primary, image);

                try
                {
                    await DtoBuilder.AttachPrimaryImageAspectRatio(dto, user, _logger).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    // Have to use a catch-all unfortunately because some .net image methods throw plain Exceptions
                    _logger.ErrorException("Error generating PrimaryImageAspectRatio for {0}", ex, user.Name);
                }
            }

            return dto;
        }
예제 #9
0
        private async Task UpdateUserImage(UserDto user, IApiClient apiClient, CancellationToken cancellationToken)
        {
            if (user.HasPrimaryImage)
            {
                var isImageCached = await _localAssetManager.HasImage(user).ConfigureAwait(false);

                if (!isImageCached)
                {
                    var imageUrl = apiClient.GetUserImageUrl(user, new ImageOptions
                    {
                        ImageType = ImageType.Primary
                    });

                    using (var stream = await apiClient.GetImageStreamAsync(imageUrl, cancellationToken).ConfigureAwait(false))
                    {
                        await _localAssetManager.SaveImage(user, stream).ConfigureAwait(false);
                    }
                }
            }
            else
            {
                await _localAssetManager.DeleteImage(user).ConfigureAwait(false);
            }
        }
예제 #10
0
        private async Task<List<BaseItemDto>> GetTvSeries(UserDto user, BaseItemDto parentItem)
        {
            var shows = await _itemRepository.GetTvSeries(user.ServerId, user.Id).ConfigureAwait(false);

            return shows
                .OrderBy(i => i.Name)
                .Select(i =>
                {
                    var item = new BaseItemDto
                    {
                        Name = i.Name,
                        Id = i.Id,
                        Type = "Series",
                        ServerId = i.ServerId,
                        ImageTags = new Dictionary<ImageType, string>()
                    };

                    if (!string.IsNullOrWhiteSpace(i.PrimaryImageTag))
                    {
                        item.ImageTags[ImageType.Primary] = i.PrimaryImageTag;
                    }

                    return item;
                })
                .ToList();
        }
예제 #11
0
        private async Task<List<BaseItemDto>> GetPhotos(UserDto user, BaseItemDto parentItem)
        {
            var items = await _itemRepository.GetItems(new LocalItemQuery
            {
                AlbumId = parentItem.Id,
                ServerId = user.ServerId,
                MediaType = "Photo"
            });

            return FilterByUserAccess(items, user)
                .Select(i => i.Item)
                .OrderBy(i => i.SortName)
                .ToList();
        }
예제 #12
0
        private async Task<List<BaseItemDto>> GetMusicAlbums(UserDto user, BaseItemDto parentItem)
        {
            var items = await _itemRepository.GetItems(new LocalItemQuery
            {
                AlbumArtistId = parentItem.Id,
                ServerId = user.ServerId,
                Type = "Audio"
            });

            var dict = new Dictionary<string, List<BaseItemDto>>();

            foreach (var item in FilterByUserAccess(items, user))
            {
                if (!string.IsNullOrWhiteSpace(item.Item.AlbumId))
                {
                    List<BaseItemDto> subItems;
                    if (!dict.TryGetValue(item.Item.AlbumId, out subItems))
                    {
                        subItems = new List<BaseItemDto>();
                        dict[item.Item.AlbumId] = subItems;
                    }
                    subItems.Add(item.Item);
                }
            }

            return dict
                .OrderBy(i => i.Value[0].Album)
                .Select(i => new BaseItemDto
                {
                    Name = i.Value[0].Album,
                    Id = i.Key,
                    Type = "MusicAlbum",
                    ServerId = user.ServerId,
                    SongCount = i.Value.Count,
                    ChildCount = i.Value.Count,
                    AlbumPrimaryImageTag = i.Value[0].AlbumPrimaryImageTag,
                    Genres = i.Value.SelectMany(m => m.Genres).Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(m => m).ToList(),
                    Artists = i.Value.SelectMany(m => m.Artists).Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(m => m).ToList()
                })
                .ToList();
        }
예제 #13
0
        public Task<List<BaseItemDto>> GetItems(UserDto user, BaseItemDto parentItem)
        {
            if (string.Equals(parentItem.Type, "MusicView"))
            {
                return GetMusicArtists(user, parentItem);
            }
            if (string.Equals(parentItem.Type, "MusicArtist"))
            {
                return GetMusicAlbums(user, parentItem);
            }
            if (string.Equals(parentItem.Type, "MusicAlbum"))
            {
                return GetAlbumSongs(user, parentItem);
            }
            if (string.Equals(parentItem.Type, "PhotosView"))
            {
                return GetPhotoAlbums(user, parentItem);
            }
            if (string.Equals(parentItem.Type, "PhotoAlbum"))
            {
                return GetPhotos(user, parentItem);
            }
            if (string.Equals(parentItem.Type, "VideosView"))
            {
                return GetVideos(user, parentItem);
            }
            if (string.Equals(parentItem.Type, "TVView"))
            {
                return GetTvSeries(user, parentItem);
            }
            if (string.Equals(parentItem.Type, "Series"))
            {
                return GetTvEpisodes(user, parentItem);
            }

            return Task.FromResult(new List<BaseItemDto>());
        }
예제 #14
0
 public Task<bool> HasImage(UserDto user)
 {
     return _imageRepository.HasImage(GetImageRepositoryId(user.ServerId, user.Id), user.PrimaryImageTag);
 }
예제 #15
0
 public Task DeleteImage(UserDto user)
 {
     return _imageRepository.DeleteImages(GetImageRepositoryId(user.ServerId, user.Id));
 }
예제 #16
0
 public Task<Stream> GetImage(UserDto user)
 {
     return Task.FromResult<Stream>(null);
 }
 public IEnumerable<IApp> GetApps(UserDto user)
 {
     return AppFactories
         .SelectMany(i => i.GetApps());
 }
예제 #18
0
 public Task DeleteImage(UserDto user)
 {
     return Task.FromResult(true);
 }
예제 #19
0
        private async Task<List<BaseItemDto>> GetVideos(UserDto user, BaseItemDto parentItem)
        {
            var items = await _itemRepository.GetItems(new LocalItemQuery
            {
                ServerId = user.ServerId,
                MediaType = "Video",
                ExcludeTypes = new[] { "Episode" }
            });

            return FilterByUserAccess(items, user)
                .Select(i => i.Item)
                .OrderBy(i => i.SortName)
                .ToList();
        }
예제 #20
0
 public Task<bool> HasImage(UserDto user)
 {
     return Task.FromResult(false);
 }
예제 #21
0
 public Task SaveOfflineUser(UserDto user)
 {
     return Task.FromResult(true);
 }
예제 #22
0
 public Task<List<BaseItemDto>> GetItems(UserDto user, BaseItemDto parentItem)
 {
     return Task.FromResult(new List<BaseItemDto>());
 }
예제 #23
0
        private IEnumerable<LocalItem> FilterByUserAccess(IEnumerable<LocalItem> items, UserDto user)
        {
            return items.Where(i =>
            {
                var result = i.UserIdsWithAccess.Contains(user.Id, StringComparer.OrdinalIgnoreCase);

                if (!result)
                {
                    _logger.Debug("Offline item {0} is blocked from user {1}", i.Item.Name, user.Name);
                }

                return result;
            });
        }
        public void SetUser(UserDto user)
        {
            LoggedInUser = user;

            _settingsService.Set(Constants.Settings.SelectedUserSetting, LoggedInUser);
        }
예제 #25
0
        public UserDto GetUserDto(User user, string remoteEndPoint = null)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            var passwordHash = GetPasswordHash(user);

            var hasConfiguredPassword = !IsPasswordEmpty(passwordHash);
            var hasConfiguredEasyPassword = !IsPasswordEmpty(GetLocalPasswordHash(user));

            var hasPassword = user.Configuration.EnableLocalPassword && !string.IsNullOrEmpty(remoteEndPoint) && _networkManager.IsInLocalNetwork(remoteEndPoint) ?
                hasConfiguredEasyPassword :
                hasConfiguredPassword;

            var dto = new UserDto
            {
                Id = user.Id.ToString("N"),
                Name = user.Name,
                HasPassword = hasPassword,
                HasConfiguredPassword = hasConfiguredPassword,
                HasConfiguredEasyPassword = hasConfiguredEasyPassword,
                LastActivityDate = user.LastActivityDate,
                LastLoginDate = user.LastLoginDate,
                Configuration = user.Configuration,
                ConnectLinkType = user.ConnectLinkType,
                ConnectUserId = user.ConnectUserId,
                ConnectUserName = user.ConnectUserName,
                ServerId = _appHost.SystemId,
                Policy = user.Policy
            };

            var image = user.GetImageInfo(ImageType.Primary, 0);

            if (image != null)
            {
                dto.PrimaryImageTag = GetImageCacheTag(user, image);

                try
                {
                    _dtoServiceFactory().AttachPrimaryImageAspectRatio(dto, user, new List<ItemFields>
                    {
                        ItemFields.PrimaryImageAspectRatio
                    });
                }
                catch (Exception ex)
                {
                    // Have to use a catch-all unfortunately because some .net image methods throw plain Exceptions
                    _logger.ErrorException("Error generating PrimaryImageAspectRatio for {0}", ex, user.Name);
                }
            }

            return dto;
        }
예제 #26
0
 public Task SaveOfflineUser(UserDto user)
 {
     return _userRepository.AddOrUpdate(user.Id, user);
 }
예제 #27
0
 public bool IsVisible(UserDto user)
 {
     return user != null;
 }
예제 #28
0
        public async Task SaveImage(UserDto user, Stream stream)
        {
            await DeleteImage(user).ConfigureAwait(false);

            await _imageRepository.SaveImage(GetImageRepositoryId(user.ServerId, user.Id), user.PrimaryImageTag, stream).ConfigureAwait(false);
        }
 public bool IsVisible(UserDto user)
 {
     return user != null && user.Configuration.IsAdministrator;
 }
예제 #30
0
 public Task<Stream> GetImage(UserDto user)
 {
     return _imageRepository.GetImage(user.Id, user.PrimaryImageTag);
 }