Esempio n. 1
0
        /// <summary>
        /// Creates a new user.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="lname">The lname.</param>
        /// <param name="passw">The passw.</param>
        /// <param name="email">The email.</param>
        public static User MakeNew(string name, string lname, string passw, string email)
        {
            var user = new Umbraco.Core.Models.Membership.User(name, email, lname, passw);

            ApplicationContext.Current.Services.UserService.Save(user);

            var u = new User(user);

            u.OnNew(EventArgs.Empty);

            return(u);
        }
Esempio n. 2
0
        internal static User CreateUser(IUserType userType = null, string suffix = "", params string[] allowedSections)
        {
            if (userType == null)
            {
                userType = MockedUserType.CreateUserType();
            }

            var user = new User(userType)
                {
                    Language = "en",
                    IsApproved = true,
                    Name = "TestUser" + suffix,
                    Password = "******",
                    NoConsole = false,
                    DefaultPermissions = "ABC",
                    StartContentId = -1,
                    StartMediaId = -1,
                    DefaultToLiveEditing = false,
                    Email = "test" + suffix + "@test.com",
                    Username = "******" + suffix
                };

            if (allowedSections.Any())
            {
                foreach (var s in allowedSections)
                {
                    user.AddAllowedSection(s);
                }
            }
            else
            {
                user.AddAllowedSection("content");
                user.AddAllowedSection("media");    
            }

            return user;
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a new user for logging into the umbraco backoffice
        /// </summary>
        /// <param name="name"></param>
        /// <param name="login"></param>
        /// <param name="password"></param>
        /// <param name="userType"></param>
        /// <param name="email"></param>
        /// <returns></returns>
        public IMembershipUser CreateMembershipUser(string name, string login, string password, IUserType userType, string email = "")
        {
            var uow = _uowProvider.GetUnitOfWork();
            using (var repository = _repositoryFactory.CreateUserRepository(uow))
            {
                var loginExists = uow.Database.ExecuteScalar<int>("SELECT COUNT(id) FROM umbracoUser WHERE userLogin = @Login", new { Login = login }) != 0;
                if (loginExists)
                    throw new ArgumentException("Login already exists");

                var user = new User(userType)
                {
                    DefaultToLiveEditing = false,
                    Email = email,
                    Language = Umbraco.Core.Configuration.GlobalSettings.DefaultUILanguage,
                    Name = name,
                    Password = password,
                    DefaultPermissions = userType.Permissions,
                    Username = login,
                    StartContentId = -1,
                    StartMediaId = -1,
                    NoConsole = false,
                    IsApproved = true
                };

                repository.AddOrUpdate(user);
                uow.Commit();

                return user;
            }
        }
        public void Can_Save_New_Content_With_Explicit_User()
        {
            var user = new User(ServiceContext.UserService.GetUserTypeByAlias("admin"))
                {
                    Name = "Test",
                    Email = "*****@*****.**",
                    Username = "******",
                    Password = "******"
                };
            ServiceContext.UserService.SaveUser(user);
            var content = new Content("Test", -1, ServiceContext.ContentTypeService.GetContentType("umbTextpage"));

            // Act
            ServiceContext.ContentService.Save(content, (int)user.Id);

            // Assert
            Assert.That(content.CreatorId, Is.EqualTo(user.Id));
            Assert.That(content.WriterId, Is.EqualTo(user.Id));
        }