Esempio n. 1
0
        public async Task <RegisterResult> RegisterAsync(string userName, string email, string password)
        {
            var passwordHash = BCrypt.Net.BCrypt.HashPassword(password);

            var userRequest = new CreateUserCommand(
                username: userName,
                email: email,
                pwdHash: passwordHash
                );

            var user = new User();

            try
            {
                var handler = new CreateUserCommandHandler(_userRepository);
                userRequest = await handler.HandleAsync(userRequest);

                user = handler.getUser();
            }
            catch (EntityAlreadyExistsException exc)
            {
                //TODO reduce breadth of exception statement
                return(RegisterResult.GetFailed("Username is already in use"));
            }

            await SignInAsync(user);

            return(RegisterResult.GetSuccess());
        }
Esempio n. 2
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());
        }
        public async Task <RegisterResult> RegisterAsync(string userName, string email, string password)
        {
            var passwordHash = BCrypt.Net.BCrypt.HashPassword(password);
            var user         = new LoginUser()
            {
                Username     = userName,
                Email        = email,
                PasswordHash = passwordHash,
                CreationTime = DateTime.UtcNow
            };

            try
            {
                user = await _persistence.Users.CreateUserAsync(user);
            }
            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());
        }
        public async Task <RegisterResult> RegisterExternalAsync(string username, string email, string scheme, string identity, string identityName)
        {
            var user = new LoginUser()
            {
                Username     = username,
                Email        = email,
                CreationTime = DateTime.UtcNow
            };
            var userAuth = new LoginUserAuthentication()
            {
                Scheme       = StringToScheme(scheme),
                Identity     = identity,
                Name         = identityName,
                CreationTime = DateTime.UtcNow
            };

            try
            {
                user = await _persistence.Users.CreateUserAsync(user);
            }
            catch (Exception)
            {
                //TODO reduce breadth of exception statement
                return(RegisterResult.GetFailed("Username is already in use"));
            }

            try
            {
                userAuth.UserId = user.Id;
                userAuth        = await _persistence.Users.CreateUserAuthenticationAsync(userAuth);
            }
            catch (Exception)
            {
                // cleanup
                await _persistence.Users.DeleteUserAsync(user);

                throw;
            }


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

            await SignInAsync(user);

            return(RegisterResult.GetSuccess());
        }