Ejemplo n.º 1
0
 public UserRegisterCommand(User user, string password)
 {
     this.FirstName = user.FirstName;
     this.LastName = user.LastName;
     this.Email = user.Email;
     this.Password = password;
     this.RoleId = user.RoleId;
     this.Activated = user.Activated;
 }
        private static UserInfo CreateUserContextFromUser(User user)
        {
            var userContext = new UserInfo
            {
                UserId = user.UserId,
                DisplayName = user.DisplayName,
                UserIdentifier = user.Email,
                RoleName=Enum.GetName(typeof(UserRoles),user.RoleId)
            };

            return userContext;
        }
        public static FormsAuthenticationTicket CreateAuthenticationTicket(User user)
        {
            UserInfo userInfo = CreateUserContextFromUser(user);

            var ticket = new FormsAuthenticationTicket(
                1,
                user.FirstName,
                DateTime.Now,
                DateTime.Now.Add(FormsAuthentication.Timeout),
                false,
                userInfo.ToString());

            return ticket;
        }
Ejemplo n.º 4
0
 private bool ValidatePassword(User user, string password)
 {
     var encoded = Md5Encrypt.Md5EncryptPassword(password);
     return user.PasswordHash.Equals(encoded);
 }
Ejemplo n.º 5
0
        public void UserCreateTest()
        {
            using (var lifetime = container.BeginLifetimeScope())
            {
                DefaultCommandBus commandBus = lifetime.Resolve<DefaultCommandBus>();
                IMappingEngine mapper = lifetime.Resolve<IMappingEngine>();

                User user = new User()
                {
                    FirstName = "Test",
                    LastName = "User",
                    Email = "*****@*****.**",
                    DateCreated = DateTime.Now,
                    RoleId = 1,
                    Activated = true
                };

                UserRegisterCommand command = mapper.Map<UserRegisterCommand>(user);
                command.Password = "******";

                IValidationHandler<UserRegisterCommand> validationHandler = lifetime.Resolve<IValidationHandler<UserRegisterCommand>>();
                IEnumerable<ValidationResult> validations = commandBus.Validate(command, validationHandler);
                foreach (var val in validations)
                {
                    Assert.IsNull(val, "Error: User creation did not validate " + val.Message);
                }
                ICommandHandler<UserRegisterCommand> commnadHandler = lifetime.Resolve<ICommandHandler<UserRegisterCommand>>();
                ICommandResult result = commandBus.Submit(command, commnadHandler);
                Assert.IsNotNull(result, "Error: User was not created by CommandBus");
                Assert.IsTrue(result.Success, "Error: User was not created by CommandBus");
            }
        }