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 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));
        }
Exemple #3
0
        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));
        }
Exemple #4
0
        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
        }