예제 #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;
        }
예제 #4
0
 private bool ValidatePassword(User user, string password)
 {
     var encoded = Md5Encrypt.Md5EncryptPassword(password);
     return user.PasswordHash.Equals(encoded);
 }
예제 #5
0
파일: UserTest.cs 프로젝트: kostyrin/FNHMVC
        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");
            }
        }