Ejemplo n.º 1
0
        // Register

        public async Task <RegisterResult> RegisterAsync(string newCustomerName, string username, string email, string password)
        {
            var customer     = new CustomerDTO(null, newCustomerName);
            var user         = new UserDTO(null, null, username, username, email);
            var passwordHash = BCrypt.Net.BCrypt.HashPassword(password);
            var authMethod   = new UserAuthenticationDTO(null, null, CredentialType.PasswordHash, passwordHash, "Password", DateTime.UtcNow);

            try
            {
                await _persistence.RequireTransactionAsync(async() =>
                {
                    customer          = await _persistence.Customers.CreateAsync(customer);
                    user.CustomerId   = customer.Id;
                    user              = await _persistence.Users.CreateAsync(user);
                    authMethod.UserId = user.Id;
                    authMethod        = await _persistence.UserAuthentications.CreateAsync(authMethod);
                });
            }
            catch (Exception exc)
            {
                //TODO reduce breadth of exception statement
                return(RegisterResult.GetFailed("Username is already in use"));
            }

            // add in option of an email activation step and use options to provide redirect url

            await SignInAsync(user);

            return(RegisterResult.GetSuccess());
        }