Exemple #1
0
        public async Task <IActionResult> Send(
            [FromBody] ConfirmationCodeRequest confirmationCodeRequest,
            CancellationToken cancellationToken)
        {
            if (string.IsNullOrWhiteSpace(confirmationCodeRequest.PhoneNumber))
            {
                return(BuildError(
                           ErrorCodes.InvalidRequest,
                           "parameter phone_number is missing",
                           HttpStatusCode.BadRequest));
            }

            try
            {
                var option = await _smsAuthenticationOperation.Execute(confirmationCodeRequest.PhoneNumber, cancellationToken)
                             .ConfigureAwait(false);

                if (option is Option <ResourceOwner> .Error e)
                {
                    return(new ObjectResult(e.Details)
                    {
                        StatusCode = (int)e.Details.Status
                    });
                }
                return(new OkResult());
            }
            catch (Exception)
            {
                return(BuildError(
                           ErrorCodes.UnhandledExceptionCode,
                           "unhandled exception occurred please contact the administrator",
                           HttpStatusCode.InternalServerError));
            }
        }
        public async Task <IActionResult> Send([FromBody] ConfirmationCodeRequest confirmationCodeRequest)
        {
            var checkResult = Check(confirmationCodeRequest);

            if (checkResult != null)
            {
                return(checkResult);
            }

            IActionResult result = null;

            try
            {
                await _smsAuthenticationOperation.Execute(confirmationCodeRequest.PhoneNumber);

                result = new OkResult();
            }
            catch (IdentityServerException ex)
            {
                result = BuildError(ex.Code, ex.Message, HttpStatusCode.InternalServerError);
            }
            catch (Exception)
            {
                result = BuildError(ErrorCodes.UnhandledExceptionCode, "unhandled exception occured please contact the administrator", HttpStatusCode.InternalServerError);
            }

            return(result);
        }
        public async Task <ActionResult> ValidateCode([FromBody] ConfirmationCodeRequest request,
                                                      [FromServices] IPhoneConfirmationService phoneConfirmation)
        {
            var validated = await phoneConfirmation.ValidateConfirmationCodeAsync(request.PhoneNumber, request.Code);

            return(Json(ApiResponse.Success(validated)));
        }
        /// <summary>
        /// Check the parameter.
        /// </summary>
        /// <param name="confirmationCodeRequest"></param>
        /// <returns></returns>
        private IActionResult Check(ConfirmationCodeRequest confirmationCodeRequest)
        {
            if (confirmationCodeRequest == null)
            {
                return(BuildError(ErrorCodes.InvalidRequestCode, "no request", HttpStatusCode.BadRequest));
            }

            if (string.IsNullOrWhiteSpace(confirmationCodeRequest.PhoneNumber))
            {
                return(BuildError(ErrorCodes.InvalidRequestCode, $"parameter {SMS.Common.Constants.ConfirmationCodeRequestNames.PhoneNumber} is missing", HttpStatusCode.BadRequest));
            }

            return(null);
        }
Exemple #5
0
        public async Task <BaseResponse> Execute(Uri requestUri, ConfirmationCodeRequest request, string authorizationValue = null)
        {
            if (requestUri == null)
            {
                throw new ArgumentNullException(nameof(requestUri));
            }

            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var httpClient = _httpClientFactory.GetHttpClient();
            var json       = JsonConvert.SerializeObject(request);
            var req        = new HttpRequestMessage
            {
                Method     = HttpMethod.Post,
                Content    = new StringContent(json),
                RequestUri = requestUri
            };

            req.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            if (!string.IsNullOrWhiteSpace(authorizationValue))
            {
                req.Headers.Add("Authorization", "Basic " + authorizationValue);
            }

            var result = await httpClient.SendAsync(req);

            var content = await result.Content.ReadAsStringAsync();

            try
            {
                result.EnsureSuccessStatusCode();
            }
            catch
            {
                return(new BaseResponse
                {
                    ContainsError = true,
                    Error = JsonConvert.DeserializeObject <ErrorResponse>(content),
                    HttpStatus = result.StatusCode
                });
            }

            return(new BaseResponse());
        }
Exemple #6
0
 public Task <BaseResponse> Send(string requestUrl, ConfirmationCodeRequest request, string authorizationValue = null)
 {
     requestUrl += "/code";
     return(_sendSmsOperation.Execute(new Uri(requestUrl), request, authorizationValue));
 }
Exemple #7
0
        public Task GetConfirmationCode(ConfirmationCodeRequest request)
        {
            var uri = string.Format("/account/getconfirmationcode/{0}/{1}/{2}", request.Email, request.CountryCode, request.PhoneNumber);

            return(Client.GetAsync <string>(uri, logger: Logger));
        }
Exemple #8
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)
                    });
                }
            }
        }