public RegistrationApplicationService( IEventStore eventStore,IDomainIdentityService ids, IUserIndexService uniqueness, PasswordGenerator generator) { _eventStore = eventStore; _ids = ids; _uniqueness = uniqueness; _generator = generator; }
public void CreateRegistration( RegistrationId i, RegistrationInfo info, IDomainIdentityService ids, IUserIndexService uniqueness, PasswordGenerator generator) { var problems = new List<string>(); // we do all the checks at registration phase if (uniqueness.IsLoginRegistered(info.ContactEmail)) { problems.Add(string.Format("Email '{0}' is already taken.", info.ContactEmail)); } if (!string.IsNullOrEmpty(info.OptionalUserIdentity)) { if (uniqueness.IsIdentityRegistered(info.OptionalUserIdentity)) { problems.Add(string.Format("Identity '{0}' is already taken.", info.OptionalUserIdentity)); } } var userDisplay = info.OptionalUserDisplay; if (string.IsNullOrEmpty(userDisplay)) { userDisplay = string.Format("{0}", info.CustomerName); } var password = info.OptionalUserPassword; if (string.IsNullOrEmpty(password)) { password = generator.CreatePassword(6); } // TODO: we are checking contact uniqueness, but can use user name var login = info.ContactEmail; if (string.IsNullOrEmpty(login)) { login = info.ContactEmail; } if (problems.Any()) { Apply(new RegistrationFailed(i, info, problems.ToArray())); return; } var id = ids.GetId(); var host = info.Headers.FirstOrDefault(h => h.Key == "UserHostAddress"); var security = new SecurityInfo(new SecurityId(id), login, password, userDisplay, info.OptionalUserIdentity); var customer = new CustomerInfo(new CustomerId(id), info.CustomerName, userDisplay, info.ContactEmail, info.OptionalCompanyPhone, info.OptionalCompanyUrl); Apply(new RegistrationCreated(i, info.CreatedUtc, customer, security)); // if no problems }
public static IEnumerable<object> ApplicationServices(IDocumentStore docs, IEventStore store) { var storage = new NuclearStorage(docs); var id = new DomainIdentityGenerator(storage); var unique = new UserIndexService(storage); var passwords = new PasswordGenerator(); yield return new UserApplicationService(store); yield return new SecurityApplicationService(store, id, passwords, unique); yield return new RegistrationApplicationService(store, id, unique, passwords); yield return id; }