public void AddIdentity(IDomainIdentityService ids, PasswordGenerator pwds, string display, string identity) { var user = new UserId(ids.GetId()); var token = pwds.CreateToken(); Apply(new SecurityIdentityAdded(_state.Id, user, display, identity, 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 }
public void AddIdentity(IDomainIdentityService ids, PasswordGenerator pwds, string display, string identity) { if (_state.ContainsIdentity(identity)) return; var user = new UserId(ids.GetId()); var token = pwds.CreateToken(); Apply(new SecurityIdentityAdded(_state.Id, user, display, identity, token)); }
public void AddPassword(IDomainIdentityService ids, PasswordGenerator pwds, string display, string login, string password) { if (_state.ContainsLogin(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 When(IDomainIdentityService ids, PasswordGenerator pwds, CreateSecurityFromRegistration c) { Apply(new SecurityAggregateCreated(c.Id)); var user = new UserId(ids.GetId()); var salt = pwds.CreateSalt(); var token = pwds.CreateToken(); var hash = pwds.HashPassword(c.Pwd, salt); Apply(new SecurityPasswordAdded(c.Id, user, c.DisplayName, c.Login, hash, salt, token)); if (!string.IsNullOrEmpty(c.OptionalIdentity)) { AddIdentity(ids, pwds, c.DisplayName, c.OptionalIdentity); } Apply(new SecurityRegistrationProcessCompleted(c.Id, c.DisplayName, user, token, c.RegistrationId)); }
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 }