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 SecurityApplicationService( IEventStore eventStore, IDomainIdentityService ids, PasswordGenerator pwds, IUserIndexService index) { _eventStore = eventStore; _ids = ids; _pwds = pwds; _index = index; }
public void AddPassword(IDomainIdentityService ids, IUserIndexService index, PasswordGenerator pwds, string display, string login, string password) { if (index.IsLoginRegistered(login)) throw DomainError.Named("duplicate-login", "Login {0} is already taken", login); var user = new UserId(ids.GetId()); var salt = pwds.CreateSalt(); var token = pwds.CreateToken(); var hash = pwds.HashPassword(password, salt); Apply(new SecurityPasswordAdded(_state.Id, user, display, login, hash, salt, token)); }
public void AddPassword(IDomainIdentityService ids, IUserIndexService index, PasswordGenerator pwds, string display, string login, string password) { if (index.IsLoginRegistered(login)) { throw DomainError.Named("duplicate-login", "Login {0} is already taken", login); } var user = new UserId(ids.GetId()); var salt = pwds.CreateSalt(); var token = pwds.CreateToken(); var hash = pwds.HashPassword(password, salt); Apply(new SecurityPasswordAdded(_state.Id, user, display, login, hash, salt, token)); }
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 }