use smtp.js in react - reactjs

im trying to use smtp.js in react, the problem is that when i use the code in the cdn to save it into a varible, so i can use the method send(), it says there is a syntax error, when it shouldnt happend
Line 18:83: Expected an assignment or function call and instead saw an expression no-unused-
expressions
Line 18:338: Expected an assignment or function call and instead saw an expression no-unused-
expressions
Line 18:561: Expected an assignment or function call and instead saw an expression no-unused-
expressions
Line 18:807: 'XDomainRequest' is not defined no-undef
ive been trying to import the code as a module, create a new Script tag, but nothing seems to work

You will need to include
<script src="https://smtpjs.com/v3/smtp.js"></script>
in between the <head></head> of your index.html file of your React App (you should load all scripts at the end).
Once you have done this, you can access Email by using window.Email.
Now you should be able to send an email by entering your SMTP credentials using the following code:
window.Email.send({
Host : "smtp.yourisp.com",
Username : "username",
Password : "password",
To : 'them#website.com',
From : "you#isp.com",
Subject : "This is the subject",
Body : "And this is the body"
}).then(
message => alert(message)
);
Where you put it is up to you. You could put it within a useEffect so it gets called when a particular Component is mounted to the DOM.

Related

Sentinel import inside Terraform Cloud confusion: key "find_resources" doesn't support function calls

I'm using a Sentinel policy inside a Terraform Cloud workspace. My policy is rather simple:
import "tfplan/v2" as tfplan
allBDs = tfplan.find_resources("aci_bridge_domain")
violatingBDs = tfplan.filter_attribute_does_not_match_regex(allBDs,
"description", "^demo(.+)", true)
main = rule {
length(violatingBDs["messages"]) is 0
}
Unfortunately, it fails when invoked with this message:
An error occurred: 1 error occurred:
* ./allowed-terraform-version.sentinel:3:10: key "find_resources" doesn't support function calls
The documentation and source for find_resources (doc) expects a string, yet the Sentinel interpreter seems to think I'm invoking a method of tfplan? It's quite unclear why that is, and the documentation doesn't really help.
Any ideas?
OK I found the issue. If I paste the code for find_resources and its dependencies (to_string, evaluate_attribute) then everything works as expected.
So I have a simple import problem and need to figure out how to properly import https://raw.githubusercontent.com/hashicorp/terraform-guides/master/governance/third-generation/common-functions/tfplan-functions/tfplan-functions.sentinel

How to execute a POST response content, that is an script tag, automatically in React?

I am working on a react project, that will replace the login page of our legacy system. This react app, however, still need to make a post request to this legacy ASP page because of integration and business rules reasons.
My challenge is to integrate the return of this ASP with react. The legacy response is a string in case of error, or a script html tag in case of success.
Changing the legacy response is not an option
Error response example:
Password/Username is invalid
Success example:
<script type='text/javascript'>top.location = 'http://www.contoso.com/myIndexPage.asp?token={FFF6F5F0F-F000-0F00-0000-F000F00F0000}'</script>
My problem is how to proper handle the request, and if is a success, execute this script tag automatically? I have tried using dangerouslySetInnerHTML, but it is not executing the script. The script tag is being inserted in the HTML correctly though.
This is how I am using it:
<div dangerouslySetInnerHTML={{__html: this.myASPReturn}} />
How do I execute the success script tag in case of a valid login, or just show the error message in case of an invalid login?
This is one solution.
First parse the html. I used this technique: Parse an HTML string with JS
const string = "<script type='text/javascript'>top.location = 'http://www.contoso.com/myIndexPage.asp?token={FFF6F5F0F-F000-0F00-0000-F000F00F0000}'</script>"
const el = document.createElement('div');
el.innerHTML = string;
Then get the code from the script element and eval() it.
const scriptString = el.firstChild.innerText;
eval(scriptString);

WebApi and Ampersands in name

So my angular website has a webapi with the following method.
[Route("items/{itemName}")]
public object GetMcguffinsByItem(string itemName)
{
return _mcguffinsService.GetAllByItemName(itemName);
}
However, an item name can have an ampersand as a valid character. However when attempting to use items that do have an ampersand, the method will return a 400 badrequest.
Im not sure how to go about fixing this problem.
For more verification: I was under the impression that encoding and using %26 is all required to pass an ampersand to part of the URI. It seems to be a common answer when searching my problem. I have excluded the angular as I can verify that it builds the string correctly, and other names produce the desired result.
The javascript method encodeURIComponent() followed by using the angular service double encodes the item name, and returns a 404.
EDIT:
Sample Input:
A&B 266
After Encoding:
A%26B%20266
Console:
angular.js:10722 GET http://localhost:60894/api/v1/mcguffins/items/A%26B%20266 404 (Not Found)
Using the browser on api directly with same input gives this error:
[HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (&).]
System.Web.HttpRequest.ValidateInputIfRequiredByConfig() +11944671
System.Web.PipelineStepManager.ValidateHelper(HttpContext context) +55

CakePHP routing not redirecting correctly

I have a problem and i have no idea what's wrong.
I have build a basic authentication system, simple one. but what i noticed is that the URL- from the side bar is different from the one that is generatet from cakephp for example:
http://localhost/sitename/users
is the url that displays on toolbar.
When i do:
echo Router::url($this->here, true );
the result is:
http://localhost/sitename/sitename/users
The site still works, but time after time generates an error such as:
http://localhost/sitename/sitename/users/
Missing Controller
Error: SitenameController could not be found.
Error: Create the class SitenameController below in file: app\Controller\SitenameController.php
<?php class SitenameController extends AppController {
}
So i dont know what is causing the problem...
If someone, anyone could help me i would very appruciate it...
Thank you very much.
Your app is in a subdirectory so you should use
Router::url(null, true);
If the $url param is null the method will find the address to the actual controller/action. Read more here.
From the book:
$this->request->here contains the full address to the current request.
The full address includes the subdirectory as well. So if you use Router::url() with the $full param set to true it "duplicates" the subdirectory.

CakePHP Cakemenu plugin fails after global error due to incorrect string encoding

I am using CakePHP 2.1.2 with PHP 5.3.5 and a plugin called 'Cakemenu' which normally works fine. The plugin stores menus in a db table with the menu link stored as text like
array('plugin'=>null,'controller'=>'assets','action'=>'index');
The helper in the plugin gets those values, then executes this code to convert that text to an array:
//Try to evaluate the link (if starts with array)
if (eregi('^array', $value['Menu']['link'])) {
$code = "\$parse = " . $value['Menu']['link'] . ";";
$result = eval($code);
if (is_array($parse)) {
$value['Menu']['link'] = $parse;
}
}
Everything works fine unless CakePHP is handling an error. For example if I mistype the name of a controller in the browser I should get a menu and then the missing controller message. Instead I get a page full "Parse error: syntax error, unexpected $end in..." messages pointing to the line with the eval statement. If I printout the variable that is getting eval'ed I see that it has been (incorrectly) encoded with Html entities when it normally does not.
Good string to be eval'ed:
$parse = array('plugin'=>null,'controller'=>'assets','action'=>'index');
Bad string to be eval'ed:
$parse = array('plugin'=>null,'controller'=>'Parts','action'=>'add');
To temporarily fix the problem I added two statements to just replace the offending characters
$value['Menu']['link'] = str_replace( ''','\'',$value['Menu']['link']);
$value['Menu']['link'] = str_replace( '>','>',$value['Menu']['link']);
and everything works great again. Some other pieces of information that might be helpful is that the array of data used to generate the menu is read during the beforeFilter of the app and saved in a view variable and then the menu is generated as an element in the view.
I'm thinking that the error causes CakePHP (or PHP) to skip some loading or configuration process and that causes the string to be mishandled. Any help would be appreciated, thanks
Your beforeFilter() method won't be executed on error pages. You'll have to handle your errors yourself and manually call beforeFilter(). I wrote a blog post on how to use custom error pages - pay close attention to the Controller Callbacks section.

Resources