Beispiel #1
0
        public void Handle(RegisterTwitterAccount command)
        {
            var account = new Account(command.AccountId, command.Name, command.Country, command.Phone, command.Email,
                                      command.PayBack, twitterId: command.TwitterId, language: command.Language);

            _repository.Save(account, command.Id.ToString());
        }
Beispiel #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
                });
            }
        }