Office.js getAttachmentsAsync fails in client - javascript

I successfully call the getAttachmentsAsync function from office.js in the webbrowser, all attachments are returend, but in the client, the function returns "failed" and - sorry a german error message - "Dieser Vorgang wird nicht unterstützt" what means "This process is not supported".
I've implemented the call on base on this documentation:
https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/add-and-remove-attachments-to-an-item-in-a-compose-form
var item = Office.context.mailbox.item;
var options = { asynContext: { currentItem: item } };
item.getAttachmentsAsync(options, function (result) {
console.log(result.error.message);
});
To reproduce the error:
create a web addin with the code above (for edit mode)
open new email, attach some files
and call the code
The call returns the following:
code: 5000
name: Hostfehler
message: Dieser Vorgang wird nicht unterstützt

Related

Call listener from script when listener is in the background.js - chrome extension

I create my extension.
I create a content.js file that inject in the page my "script".
var SE = document.createElement('script');
SE.src = chrome.extension.getURL('SE.js');
(document.head || document.documentElement).appendChild(SE);
in the SE.js file I get this script. In my seExtID it's my chrome extension ID because if i do not pass the seExtID i get this error :
Uncaught Error: chrome.runtime.connect() called from a webpage must specify an Extension ID (string) for its first argument
So i pass my extentionID to the sendMessage method
chrome.runtime.sendMessage(seExtID, {
method: "LoadSettings"
},
function (config) {
defaultSettings = config;
});
in my background.js file
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
debugger;
switch(request.method){
case "SaveSettings":
var se_json = request.settings;
localStorage.setItem("se_settings", se_json);
break;
case "LoadSettings":
var obj = JSON.parse(localStorage.getItem("se_settings"));
sendResponse(obj);
break;
}
}
);
The problem is, if i call my SendMessage from the default_popup or from the content.js it's work.
In the content.js or in the default_popup, probably the context of the execution already exists, so the seExtID is not needed. I can call my send message witout the seExtID like and it's work :
chrome.runtime.sendMessage( {
method: "LoadSettings"
},
function (config) {
defaultSettings = config;
});
If i take a look on the documentation https://developer.chrome.com/extensions/runtime#method-sendMessage
string (optional) extensionId
The ID of the extension/app to send the message to. If omitted, the message will be sent to your own extension/app. Required if sending messages from a web page for web messaging.
I probably miss something ... someone could help me on this one ?

symfony 3 ajax redirect if session is expired

In my Symfony 3 app I made so, that if the user is inactive for some time, it is logged out and requested to login again. This is done with the following code:
//RequestListener.php
public function onKernelRequest(GetResponseEvent $event)
{
if (HttpKernelInterface::MASTER_REQUEST != $event->getRequestType()) {
return;
}
if ($this->maxIdleTime > 0) {
$lapse = time() - $this->session->getMetadataBag()->getCreated();
$lapse_short = time() - $this->session->getMetadataBag()->getLastUsed();
if ($lapse >= $this->maxIdleTime || $lapse_short >= $this->shortIdleTime) {
$username = $this->securityToken->getToken()->getUser();
if ($username !== 'anon.'){
$this->session->invalidate();
$this->securityToken->setToken(null);
$event->setResponse(new RedirectResponse($this->router->generate('login')));
}
}
}
}
But in ths case redirect to login form is happened when the page is reloaded. I also want to force redirect on every ajax call also. By default my ajax calls are served by the following address: /ajax
But when the session is expired the ajax is 'redirected' to my login page address and in browsers Network tab I see the following:
My ajax function which is supposed to redirect is as follows:
function requestAjax(json_data, url) {
if(url.indexOf('login') !== -1){
window.location = './login';
}
var request = $.ajax({
url: root + '/' + url
, method: 'post'
, data: json_data
});
return request;
}
But no redirect is happened. So The question is how to force redirect on expired sessions and ajax calls and also why ajax status is 200 but not say 302 in this case? Thank you
UPD_1 My services.yml for RequestListener.php
app.handler.session_idle:
class: AppBundle\EventListener\RequestListener
arguments: ["#session", "#security.token_storage", "#router", "#app.logger", "%session_lifetime%", "%session_active_lifetime%", "%instance_path%"]
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
You could try something like this (tested and working in Symfony 2.8)
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
class AjaxAuthenticationListener {
/*
* function onCoreException
* Check if session is expired and handles security related exceptions
* #param GetResponseForExceptionEvent $event An GetResponseForExceptionEvent instance
*
*/
public function onCoreException(GetResponseForExceptionEvent $event) {
$exception = $event->getException();
$event_request = $event->getRequest();
$session = $event->getRequest()->getSession();
if ($event_request->isXmlHttpRequest()) {
if ($exception instanceof AuthenticationException || $exception instanceof AccessDeniedException) {
$session->getFlashBag()->add('warning', 'You have been signed out automatically due to inactivity.');
$event->setResponse(new Response('Session expired', 403));
}
}
}
}
As you can see, "onCoreException" function returns a 403 status code.
Now, in home page (in my case) or page where you will have ajax calls, you could use "ajaxError" and catch the jqXHR.status, if it is 403, then redirect to login page and using a "FlashBag" to display a message related to expired session.
$(document).ready(function () {
//Catch AjaxAuthenticationListener response
$(document).ajaxError(function (event, jqXHR) {
if (403 === jqXHR.status) {
$(location).attr('href', '{{ path('login') }}');
}
});
I have omitted explain how "onCoreException" function works as a service and how it handles the session when it has been expired, taking into account that this part is working properly in your code.
services.yml:
app.gt.ajax.authentication.listener:
class: AppBundle\EventListener\AjaxAuthenticationListener
tags:
- { name: kernel.event_listener, event: kernel.exception, method: onCoreException, priority: 1000 }
I hope this is useful for you.
Symfony 5 solution
Have been researching on this care for quite some hours. In the symfony 5 How to Customize Access Denied Responses docs, you can customize one of the following:
1. App entry point
2. Access denied handler
3. All Access Denied Responses
Going with customizing All Access Denied Responses, i created a kernel.exception subscriber/listener:
namespace App\EventSubscribers;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
class AccessDeniedHandler implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
// the priority must be greater than the Security HTTP
// ExceptionListener, to make sure it's called before
// the default exception listener
KernelEvents::EXCEPTION => ['onKernelException', 2]
];
}
public function onKernelException(ExceptionEvent $event): void
{
// Ajax is returning login page instead of session expired/access denied
// Creating a custom handler for ajax
// more at https://symfony.com/doc/current/security/access_denied_handler.html#customize-the-unauthorized-response
$request = $event->getRequest();
if($request->isXmlHttpRequest()){
$event->setResponse(new Response('Your session has expired!', 403));
return;
}
}
}

Stripe Payment in Javascript createToken callback not calling

In the following code, I have a problem where Stripe is not processing the payment. I'm getting all the values from the form correctly, however in the stripeResponseHandler function nothing is logging. I'm using the test credit cards available on their website and I successfully used it a couple of times prior to this error.
I loaded the https://js.stripe.com/v2/stripe-debug.js into my javascript and it was logging in the chrome console that "It looks like Stripe.js was loaded more than one time. Please only load it once per page.", however I only setPublishableKey here within this JS file and load
Stripe.setPublishableKey('pk_test_TK18ZwUnK2CT1Wmof8WsQl8S');
var payMeal = function(){
console.log("inside the paymeals function");
var x = document.getElementsByClassName("form-payment");
console.log("Number is " + x[0].value)
console.log("CVC is " + x[1].value)
console.log("Exp_Month is " + x[2].value)
console.log("Exp_Year is " + x[3].value)
console.log("The Stripe Object is",Stripe)
Stripe.card.createToken({
number: x[0].value,
cvc: x[1].value,
exp_month: x[2].value,
exp_year: x[3].value
}, stripeResponseHandler)
window.location.href = "../../meals"
};
var stripeResponseHandler = function(status, response){
console.log("IM IN THE RESPONSE HANDLER!!!!+++++***")
if(response.error){
console.log("THERE IS AN ERROR!!***")
console.log(response);
}
else{
console.log("submitting ajax to server with token");
token = response.id;
ajaxToServer(token);
}
}

Codeigniter Can't change view page

I need your help with an issue that is dragging me crazy.
You have to know that My view page has 4 view pages called: Header, Menu, Sub menu and Content and I'm using SQL database to store the information the user fill in Content.
I want to change Content page after the user hit submit button.
The submit button will call a JS that arranges the information into an array and call a controller function that call a database function and fill the table and send a TRUE if the table was filled. After all that code, I take the created array and TRUE and send it to a new Content view and display the information that the user filled and tell him "upload success".
The main problem is the new content view isn't showing, I checked the database and the information is uploaded. This is part of the controller function that is sended to the database.
This is the Javascript, i'm using ajax.
$("#btn_enviar").click(function(){
var r = confirm("Los datos ingresados no podran ser modificados una vez enviados, presione aceptar si desea continuar");
if (r == true){
var url = base_url + "/inventario/insert_inventario";
$.ajax({
type: "POST",
url: url,
data: $("#form_inventario").serialize(),
success: function(data)
{
$("#contenido").html(data.mensaje);
}
});
var elem = document.getElementById('btn_enviar');
}
return false;
});
This is the Controller. array_db is the array with the user information.
$obj_inv = $this->Inventario_model->insert_inventario($array_db);
if($obj_inv){
$edit_view = $this->load->view(base_url()."inventario/edit",$array_db,TRUE);
$response = array('mensaje' => $edit_view
);
$this->output
->set_status_header(200)
->set_content_type('application/json', 'utf-8')
->set_output(json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES))
->_display();
exit;
} else {
echo('ERROR: Uno o mas datos son incorrectos o no estan llenados.');
}
This is the model. Inventario_model is the function that calls the database and return a True or False is the information is inserted.
public function insert_inventario($array_data) {
$id = $this->db->insert('inventario',$array_data);
$obj_activo = $this->db->get('inventario');
return $id;
}
What I'm missing? Why the edit view isn't showing?
The only clue I have is, in development Console is throwing me this:
http://[IP]/Inventario_Remedy/inventario/insert_inventario Failed to load resource: the server responded with a status of 500 (Internal Server Error)
Edited to show the error log
PHP 1. {main}() C:\Xampp\htdocs\Inventario_Remedy\index.php:0
PHP 2. require_once()
C:\Xampp\htdocs\Inventario_Remedy\index.php:293
PHP 3. call_user_func_array()
C:\Xampp\htdocs\Inventario_Remedy\system\core\CodeIgniter.php:514
PHP 4. Inventario->insert_inventario()
C:\Xampp\htdocs\Inventario_Remedy\system\core\CodeIgniter.php:514
PHP 5. Inventario_model->insert_inventario()
C:\Xampp\htdocs\Inventario_Remedy\application\controllers\Inventario.php:105
PHP 6. CI_DB_query_builder->insert()
C:\Xampp\htdocs\Inventario_Remedy\application\models\Inventario_model.php:29
PHP 7. CI_DB_driver->query()
C:\Xampp\htdocs\Inventario_Remedy\system\database\DB_query_builder.php:1608
PHP 8. CI_DB_driver->display_error()
C:\Xampp\htdocs\Inventario_Remedy\system\database\DB_driver.php:675
PHP 9. CI_Exceptions->show_error()
C:\Xampp\htdocs\Inventario_Remedy\system\database\DB_driver.php:1698
PHP 10. _error_handler()
C:\Xampp\htdocs\Inventario_Remedy\system\database\DB_driver.php:182
PHP 11. CI_Exceptions->show_php_error()
C:\Xampp\htdocs\Inventario_Remedy\system\core\Common.php:623
CI VERSION 3.0

Is there a very simple way to update a page in Perl Dancer using jQuery/AJAX?

I have the following code in my main Dancer app .pm:
package Deadlands;
use Dancer ':syntax';
use Dice;
our $VERSION = '0.1';
get '/' => sub {
my ($dieQty, $dieType, $bonus);
my $button = param('button');
$dieQty = param('dieQty');
$dieType = param('dieType');
$bonus = param('bonus');
if (defined $dieQty && defined $dieType) {
return Dice::Dice->new(dieType => $dieType, dieQty => $dieQty, bonus => $bonus)->getStandardResult();
}
template 'index';
};
true;
Here is my JavaScript:
$(document).ready(function() {
$('#standardRoll').click(function() {
$.get("/lib/Deadlands.pm", { button: '1', dieType: $("#dieType").val(), dieQty: $("#dieQty").val(), bonus: $("#bonus").val() }, processData);
function processData(data) {
$("#result").html(data);
}
});
});
I have a div in my web page called result that I want to be updated with the die roll result from Perl. Dancer keeps coming back with a 404 error in the command window when I push the submit button.
/lib/Deadlands.pm needs to be the URL of your route (probably / in this case), not the filesystem path of your Perl module.
Your AJAX request needs to point to a URL that actually exists, not a filename that has nothing to do with the web. Looks like $.get('/', ...) would do in this case.

Categories

Resources