Exemple #1
0
        public User CreateUser(string name)
        {
            if (!IsValidUsername(name))
            {
                throw new ArgumentException("Usernames can contain unicode symbols, numbers (0-9), dashes (-), underscores (_), apostrophes ('), and periods (.)");
            }

            var dbContext = _dbProvider.CreateContext();

            // TODO: Remove after user item data is migrated.
            var max = dbContext.Users.Any() ? dbContext.Users.Select(u => u.InternalId).Max() : 0;

            var newUser = new User(
                name,
                _defaultAuthenticationProvider.GetType().FullName,
                _defaultPasswordResetProvider.GetType().FullName)
            {
                InternalId = max + 1
            };

            dbContext.Users.Add(newUser);
            dbContext.SaveChanges();

            OnUserCreated?.Invoke(this, new GenericEventArgs <User>(newUser));

            return(newUser);
        }
        internal async Task <User> CreateUserInternalAsync(string name, JellyfinDb dbContext)
        {
            // TODO: Remove after user item data is migrated.
            var max = await dbContext.Users.AnyAsync().ConfigureAwait(false)
                ? await dbContext.Users.Select(u => u.InternalId).MaxAsync().ConfigureAwait(false)
                : 0;

            return(new User(
                       name,
                       _defaultAuthenticationProvider.GetType().FullName,
                       _defaultPasswordResetProvider.GetType().FullName)
            {
                InternalId = max + 1
            });
        }
Exemple #3
0
        internal async Task <User> CreateUserInternalAsync(string name, JellyfinDb dbContext)
        {
            // TODO: Remove after user item data is migrated.
            var max = await dbContext.Users.AsQueryable().AnyAsync().ConfigureAwait(false)
                ? await dbContext.Users.AsQueryable().Select(u => u.InternalId).MaxAsync().ConfigureAwait(false)
                : 0;

            var user = new User(
                name,
                _defaultAuthenticationProvider.GetType().FullName !,
                _defaultPasswordResetProvider.GetType().FullName !)
            {
                InternalId = max + 1
            };

            user.AddDefaultPermissions();
            user.AddDefaultPreferences();

            _users.Add(user.Id, user);

            return(user);
        }