Exemple #1
0
 // GET: AdminTH/BlackList
 public ActionResult Index()
 {
     return(View(_blackListService.GetAll()));
 }
Exemple #2
0
        public object Post(RegisterAccount request)
        {
            // Ensure user is not signed in
            RequestContext.Get <IHttpRequest>().RemoveSession();

            if (_accountDao.FindByEmail(request.Email) != null)
            {
                throw new HttpError(ErrorCode.CreateAccount_AccountAlreadyExist.ToString());
            }

            CountryCode countryCode = CountryCode.GetCountryCodeByIndex(CountryCode.GetCountryCodeIndexByCountryISOCode(request.Country));

            if (PhoneHelper.IsPossibleNumber(countryCode, request.Phone))
            {
                request.Phone = PhoneHelper.GetDigitsFromPhoneNumber(request.Phone);
            }
            else
            {
                throw new HttpError(string.Format(_resources.Get("PhoneNumberFormat"), countryCode.GetPhoneExample()));
            }

            if (_blackListEntryService.GetAll().Any(e => e.PhoneNumber.Equals(request.Phone)))
            {
                throw new HttpError(_resources.Get("PhoneBlackListed"));
            }

            if (request.FacebookId.HasValue())
            {
                // Facebook registration
                if (_accountDao.FindByFacebookId(request.FacebookId) != null)
                {
                    throw new HttpError(ErrorCode.CreateAccount_AccountAlreadyExist.ToString());
                }

                var command = new RegisterFacebookAccount();

                Mapper.Map(request, command);
                command.Id = Guid.NewGuid();

                _commandBus.Send(command);

                return(new Account {
                    Id = command.AccountId
                });
            }
            if (request.TwitterId.HasValue())
            {
                // Twitter registration
                if (_accountDao.FindByTwitterId(request.TwitterId) != null)
                {
                    throw new HttpError(ErrorCode.CreateAccount_AccountAlreadyExist.ToString());
                }

                var command = new RegisterTwitterAccount();

                Mapper.Map(request, command);
                command.Id = Guid.NewGuid();

                _commandBus.Send(command);

                return(new Account {
                    Id = command.AccountId
                });
            }
            else
            {
                // Normal registration
                var accountActivationDisabled = _serverSettings.ServerData.AccountActivationDisabled;
                var smsConfirmationEnabled    = _serverSettings.ServerData.SMSConfirmationEnabled;

                var confirmationToken = smsConfirmationEnabled
                    ? GenerateActivationCode()
                    : Guid.NewGuid().ToString();

                var command = new Commands.RegisterAccount();

                Mapper.Map(request, command);
                command.Id = Guid.NewGuid();

                command.ConfimationToken          = confirmationToken;
                command.AccountActivationDisabled = accountActivationDisabled;
                _commandBus.Send(command);

                if (!accountActivationDisabled)
                {
                    if (smsConfirmationEnabled &&
                        (request.ActivationMethod == null ||
                         request.ActivationMethod == ActivationMethod.Sms))
                    {
                        _commandBus.Send(new SendAccountConfirmationSMS
                        {
                            ClientLanguageCode = command.Language,
                            Code        = confirmationToken,
                            CountryCode = command.Country,
                            PhoneNumber = command.Phone
                        });
                    }
                    else
                    {
                        _commandBus.Send(new SendAccountConfirmationEmail
                        {
                            ClientLanguageCode = command.Language,
                            EmailAddress       = command.Email,
                            ConfirmationUrl    =
                                new Uri(string.Format("/api/account/confirm/{0}/{1}", command.Email, confirmationToken), UriKind.Relative),
                        });
                    }
                }

                return(new Account {
                    Id = command.AccountId
                });
            }
        }
Exemple #3
0
        public void Get(ConfirmationCodeRequest request)
        {
            var account = _accountDao.FindByEmail(request.Email);

            if (account == null)
            {
                throw new HttpError(HttpStatusCode.NotFound, "No account matching this email address");
            }

            if (!_serverSettings.ServerData.AccountActivationDisabled)
            {
                if (_serverSettings.ServerData.SMSConfirmationEnabled)
                {
                    var countryCodeForSMS = account.Settings.Country;
                    var phoneNumberForSMS = account.Settings.Phone;

                    CountryCode countryCodeFromRequest = CountryCode.GetCountryCodeByIndex(CountryCode.GetCountryCodeIndexByCountryISOCode(request.CountryCode));

                    if (countryCodeFromRequest.IsValid() &&
                        request.PhoneNumber.HasValue() &&
                        PhoneHelper.IsPossibleNumber(countryCodeFromRequest, request.PhoneNumber) &&
                        (account.Settings.Country.Code != countryCodeFromRequest.CountryISOCode.Code || account.Settings.Phone != request.PhoneNumber))
                    {
                        if (_blackListEntryService.GetAll().Any(e => e.PhoneNumber.Equals(request.PhoneNumber.ToSafeString())))
                        {
                            throw new HttpError(_resources.Get("PhoneBlackListed"));
                        }

                        countryCodeForSMS = countryCodeFromRequest.CountryISOCode;
                        phoneNumberForSMS = request.PhoneNumber;

                        var updateBookingSettings = new UpdateBookingSettings()
                        {
                            AccountId         = account.Id,
                            Email             = account.Email,
                            Name              = account.Name,
                            Country           = countryCodeFromRequest.CountryISOCode,
                            Phone             = request.PhoneNumber,
                            Passengers        = account.Settings.Passengers,
                            VehicleTypeId     = account.Settings.VehicleTypeId,
                            ChargeTypeId      = account.Settings.ChargeTypeId,
                            ProviderId        = account.Settings.ProviderId,
                            NumberOfTaxi      = account.Settings.NumberOfTaxi,
                            AccountNumber     = account.Settings.AccountNumber,
                            CustomerNumber    = account.Settings.CustomerNumber,
                            DefaultTipPercent = account.DefaultTipPercent,
                            PayBack           = account.Settings.PayBack
                        };

                        _commandBus.Send(updateBookingSettings);
                    }

                    _commandBus.Send(new SendAccountConfirmationSMS
                    {
                        ClientLanguageCode = account.Language,
                        Code        = account.ConfirmationToken,
                        CountryCode = countryCodeForSMS,
                        PhoneNumber = phoneNumberForSMS
                    });
                }
                else
                {
                    _commandBus.Send(new SendAccountConfirmationEmail
                    {
                        ClientLanguageCode = account.Language,
                        EmailAddress       = account.Email,
                        ConfirmationUrl    =
                            new Uri(string.Format("/api/account/confirm/{0}/{1}", account.Email,
                                                  account.ConfirmationToken), UriKind.Relative)
                    });
                }
            }
        }