public async Task <IActionResult> Index(ulong?localInvoiceId = null)
        {
            var model = new CallbackViewModel();

            if (localInvoiceId.HasValue)
            {
                model = await Callback(localInvoiceId.Value);
            }
            model.Time = await _services.GetTime();

            return(View(model));
        }
        public ActionResult Callback()
        {
            var p         = HttpContext.Request.Path;
            var path      = Request.Path;
            var query     = Request.Query;
            var viewModel = new CallbackViewModel
            {
                IdentityToken = query[Core.Constants.StandardAuthorizationResponseNames.IdTokenName],
                AccessToken   = query[Core.Constants.StandardAuthorizationResponseNames.AccessTokenName],
                State         = query[Core.Constants.StandardAuthorizationResponseNames.StateName]
            };

            return(View(viewModel));
        }
Пример #3
0
        /// <summary>
        /// A sample callback page as called by one of the user interface pages Enroll or Verify.
        /// </summary>
        /// <param name="access_token">The BWS web token that has been passed to the user interface.</param>
        /// <param name="error">An optional error string reported by the user interface.</param>
        /// <param name="state">The state parameter as passed to the user interface.</param>
        /// <returns>A view showing the error and/or results.</returns>
        public ActionResult Callback(string access_token, string error, string state)
        {
            var model = new CallbackViewModel();
            if (!string.IsNullOrWhiteSpace(error))
            {
                if (error == "user_abort")
                    model.GuiError = "You aborted the BWS user interface.";
                else
                    model.GuiError = error;
            }

            // let's see whether we can fetch some results
            try
            {
                var httpClient = new HttpClient();
                // Note: for demonstration we use the token for authentication, but it is recommended to use your App-ID and -secret with basic authentication:
                //httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(string.Format("{0}:{1}", appId, appSecret))));
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", access_token);
                // Note: here we assume that bws.bioid.com is the host that was used for the biometric task!
                UriBuilder uri = new UriBuilder("https", "bws.bioid.com", 443, "extension/result", string.Format("?access_token={0}", access_token));
                var response = httpClient.GetAsync(uri.Uri).Result;
                var responseStream = response.Content.ReadAsStreamAsync().Result;
                // we got a valid response
                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    var json = JObject.Load(new JsonTextReader(new StreamReader(responseStream)));
                    model.Success = (bool)json["Success"];
                    model.BCID = (string)json["BCID"];
                    model.Action = (string)json["Action"];
                    model.Error = (string)json["Error"];
                }
                // no result has been logged for this token
                else if (response.StatusCode == System.Net.HttpStatusCode.NoContent)
                {
                    model.Error = "You have not performed any biometric action.";
                }
                // we got an error
                else if (responseStream.Length > 0)
                {
                    var json = JObject.Load(new JsonTextReader(new StreamReader(responseStream)));
                    model.Error = (string)json["Message"];
                }
            }
            catch (Exception ex)
            {
                model.Error = string.Format("Error: {0}", ex.Message);
            }
            return View(model);
        }
        private async Task <CallbackViewModel> Callback(ulong localInvoiceId)
        {
            try
            {
                var tranResult = await _services.GetTranResult(localInvoiceId);

                var model = new CallbackViewModel
                {
                    TranResult = tranResult,
                };

                return(model);
            }
            catch (Exception exc)
            {
                return(new CallbackViewModel
                {
                    ErrorMessage = exc.Message
                });
            }
        }
Пример #5
0
 public IActionResult Callback(CallbackViewModel model, string returnUrl)
 {
     if (ModelState.IsValid)
     {
         //пытаемся отправить данные из формы
         try
         {
             //создаём объект сообщение
             MimeMessage message = new MimeMessage();
             //отправитель
             message.From.Add(new MailboxAddress(Config.CompanyName, Email.From));
             //куда отправляем
             message.To.Add(MailboxAddress.Parse(Email.To));
             //тема письма
             message.Subject = $"Заказ звонка - {Config.CompanyName}";
             //текст письма
             message.Body = new BodyBuilder()
             {
                 TextBody = $"{model.Phone} {model.Name}"
             }.ToMessageBody();
             //отправляем
             using (SmtpClient client = new SmtpClient())
             {
                 //данные сервера
                 client.Connect(Email.SMTPServer, Email.SMTPPort, Email.SMTPSSL);
                 //данные авторизации
                 client.Authenticate(Email.From, Email.FromPassword);
                 //отправка
                 client.Send(message);
             }
             ViewBag.Message = "Ваш запрос отправлен. Ожидайте звонка!";
         }
         catch
         {
             ViewBag.Message = "Запрос НЕ отправлен. Перезвоните по номеру " + Config.CompanyName;
         }
         ViewBag.returnUrl = returnUrl;
     }
     return(View(model));
 }
Пример #6
0
        public JsonResult <bool> Post([FromBody] CallbackViewModel vm)
        {
            // TODO Add status codes
            // Catch Exceptions

            Thread.Sleep(2000);

            if (ModelState.IsValid)
            {
                if (_repo.SaveCallback(vm.ToModel()))
                {
                    return(Json(true));
                }
                else
                {
                    return(Json(false));
                }
            }



            return(Json(false));
        }