public ActionResult Register(FormCollection collection)
        {
            User user;

            string password = collection[FormDataKeys.Password.ToString()];
            string email = collection[FormDataKeys.Email.ToString()];
            string firstName = collection[FormDataKeys.FirstName.ToString()];
            string secondName = collection[FormDataKeys.SecondName.ToString()];

            try
            {
                user = _authenticationService.RegisterUser(email, password);
            }
            catch (InvalidOperationException ex)
            {
                AccountView accountView = InitializeAccountViewWithIssue(
                                                             true,
                                                                         ex.Message);

                return View(accountView);
            }

            if (user.IsAuthenticated)
            {
                try
                {
                    CreateCustomerRequest createCustomerRequest =
                                            new CreateCustomerRequest();
                    createCustomerRequest.CustomerIdentityToken =
                                            user.AuthenticationToken;
                    createCustomerRequest.Email = email;
                    createCustomerRequest.FirstName = firstName;
                    createCustomerRequest.SecondName = secondName;

                    _formsAuthentication.SetAuthenticationToken(
                                                          user.AuthenticationToken);
                    _customerService.CreateCustomer(createCustomerRequest);

                    return RedirectToAction("Detail", "Customer");
                }
                catch (CustomerInvalidException ex)
                {
                    AccountView accountView = InitializeAccountViewWithIssue(
                                                                 true,
                                                                             ex.Message);

                    return View(accountView);
                }
            }
            else
            {
                AccountView accountView = InitializeAccountViewWithIssue(true,
                               "Sorry we could not authenticate you. " +
                               " Please try again.");

                return View(accountView);
            }
        }
        public CreateCustomerResponse CreateCustomer(CreateCustomerRequest request)
        {
            CreateCustomerResponse response = new CreateCustomerResponse();
            Customer customer = new Customer();
            customer.IdentityToken = request.CustomerIdentityToken;
            customer.Email = request.Email;
            customer.FirstName = request.FirstName;
            customer.SecondName = request.SecondName;

            ThrowExceptionIfCustomerIsInvalid(customer);

            _customerRepository.Add(customer);
            _uow.Commit();

            response.Customer = customer.ConvertToCustomerDetailView();

            return response;
        }
        public ActionResult ReceiveTokenAndRegister(string token, string returnUrl)
        {
            User user = _externalAuthenticationService.GetUserDetailsFrom(token);

            if (user.IsAuthenticated)
            {
                _formsAuthentication.SetAuthenticationToken(
                                                         user.AuthenticationToken);

                // Register user
                CreateCustomerRequest createCustomerRequest =
                                                  new CreateCustomerRequest();
                createCustomerRequest.CustomerIdentityToken =
                                                  user.AuthenticationToken;
                createCustomerRequest.Email = user.Email;
                createCustomerRequest.FirstName = "[Please Enter]";
                createCustomerRequest.SecondName = "[Please Enter]";

                _customerService.CreateCustomer(createCustomerRequest);

                return RedirectBasedOn(returnUrl);
            }
            else
            {
                AccountView accountView = InitializeAccountViewWithIssue(true,
                                           "Sorry we could not authenticate you.");
                accountView.CallBackSettings.ReturnUrl =
                                            GetReturnActionFrom(returnUrl)
                                            .ToString(); ;

                return View("Register", accountView);
            }
        }