Escape Chars in Email Templates - gmail

I have an email template that contains a var - ${token} for a temporary password. In this case, token == #.iJ<ep2C]a-d$}4xK{. When rendered in Gmail token is truncated at the < character and rendered as #.iJ. How can I escape chars in token so they render correctly in Gmail?
Template
From: info#mycompany.com
Subject: New User Activation
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="alternative_boundary"
This is a message with multiple parts in MIME format.
--alternative_boundary
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Dear ${firstName} ${lastName},
Please click on the below link and use Temporary password: ${token} to activate your new account.
${reset_url}
--alternative_boundary
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>New account activation</title>
</head>
<body>
<p>Dear ${firstName} ${lastName},</p>
<p>Please click here to activate your new account and use verification code: ${token} in the page</p>
</body>
</html>

You'll want to escape the reserved characters per the MDN docs:
& &
< <
> >
" "
Gmail thinks the < is the start of an HTML tag.
Assuming you're using JavaScript replace these in the token like Fastest method to escape HTML tags as HTML entities?:
function escapeHtmlEntities(str) {
return str
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"');
}
In your template:
...${escapeHtmlEntities(token)}...

Related

EJS/Node/Express - Having a header partial, how to change title for each page?

I recently took a course on back-end web developing.
As the title says, I don't get how can I use a header partial for the whole website but have different titles for each page. (because is included in the tag)
Is there any trick?
1st) In your Express route:
app.get("/", function(req, res){
res.locals.title = "Abel's Home Page"; // THIS LINE IS KEY
res.render("home.ejs");
});
2nd) In your views/home.ejs file:
<% include partials/header.ejs %>
3rd) In your views/partials/header.ejs file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title><%= title %></title> <!-- THIS LINE IS KEY -->
<link rel="stylesheet" href="../style.css">
<link rel="shortcut icon" href="../logo_sm.png" type="image/x-icon">
</head>
<body>
Each page that includes the partial is free to pass data to said partial through parameters. See here for an example.

Exception parsing document error while using Thymeleaf

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<title>Hello Thymeleaf!</title>
</head>
<body>
<p th:text="'Hello, ' + ${name} + '!'" />
<img th:src="#{data:image/jpeg;base64, /9j/4AAQSkZJRgABAgAAAQABAAD/7QCEUGhvdG9zaG9wI...
}">
</body>
</html>
I am displaying an image which is converted to Base64 (MIME type conversion) format and I am using Thyme-leaf template, can someone figure out what's happening?
One possible error could be that thymeleaf check the html-syntax strict and you don't close your image-tag. So try to change it like this:
<img th:src="#{data:image/jpeg;base64, /9j/4AAQSkZJRgABAgAAAQ... }" />

Return url is loading INTO lightbox with Paypal adaptive payment, not window

I'm using a simple payment set up on an embedded flow.
Everything works well, except the return and cancel urls are being loaded into the lightbox, not the parent window, so I end up with a greyed out window with the return url page in it, and the user can't do anything.
As an example, here's the exact code from my cancel page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="https://www.paypalobjects.com/js/external/dg.js"></script>
</head>
<body>
<div class="center">
<p>Unable to complete payment, due to either a payment cancelation, or an error.</p>
<p>No funds were transfered.</p>
</div>
<script type="text/javascript" charset="utf-8">
dgFlow = top.dgFlow || top.opener.top.dgFlow;
dgFlow.closeFlow();
top.close();
</script>
</body>
When I check out the console output, it says
top.opener is null
and it's referring to the line
dgFlow = top.dgFlow || top.opener.top.dgFlow;
Should the return URL not load into the parent window instead?
Thanks for taking a look.

Rendering wrong head with login layout

Can anyone tell me how it is possibile that the following layout in a Rails 4 app
# app/views/layout/login.html.erb
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title>PIPPO</title>
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black-translucent" name="apple-mobile-web-app-status-bar-style">
<meta name="viewport" content="initial-scale = 1.0,maximum-scale = 1.0" />
<link href="/assets/login.css" media="all" rel="stylesheet" />
<script src="/assets/login.js"></script>
<%= csrf_meta_tags %>
</head>
<body>
<div class="main-content">
<%= yield %>
</div>
</body>
</html>
With the following controller
class SessionsController < ApplicationController
layout 'login'
...
def destroy
Session.find(session[:id]).close
reset_session
respond_to do |format|
flash[:success] = t('sessions.logout')
format.html { redirect_to login_url }
end
end
end
and routes
...
get 'login', to: 'sessions#new', as: 'login'
get 'logout', to: 'sessions#destroy', as: 'logout'
...
produces the following HTML once I click on <%= link_to 'logout', logout_path %>?
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title>PIPPO</title>
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black-translucent" name="apple-mobile-web-app-status-bar-style">
<meta name="viewport" content="initial-scale = 1.0,maximum-scale = 1.0" />
<link href="/assets/application.css" media="all" rel="stylesheet" />
<script src="/assets/application.js"></script>
<meta content="authenticity_token" name="csrf-param" />
<meta content="l9+umk+wjpXY4UFiKEeuQkGgMvjbbZ2uDxyJHowTJFo=" name="csrf-token" />
</head>
Am I missing anything here? It is two days I'm trying to figure this out.
Why is it using the head from the main layout instead of the one in login?
Thanks for your help.
UPDATE - Forgot to mention my log file states:
Rendered sessions/new.html.erb within layouts/login (1.4ms)
As per the layout name given in the question, i.e.,
app/views/layout.login.html.erb
There are couple of things wrong here:
layouts should be placed in app/views/layouts folder
File name should be login.html.erb and not layout.login.html.erb
In your case, Rails could not find login.html.erb in app/views/layouts, it rendered the default layout app/views/layouts/application.html.erb.

PHP: Problems with Facebook Connect authentification

I would like to develop an external website using Facebook Connect instead of an own login and registration process.
On the first page (index.php) I have the following code for the login button:
<fb:login-button v="2" size="large" autologoutlink="false" onlogin="window.location='/index.php'">Connect with Facebook</fb:login-button>
For authentification, I use this library for PHP.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="content-language" content="de" />
<meta http-equiv="content-script-type" content="text/javascript" />
<meta http-equiv="content-style-type" content="text/css" />
</head>
<body>
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/de_DE" type="text/javascript"></script><script type="text/javascript">FB.init("XYZ");</script>
<?php
error_reporting(E_ALL);
include_once '/XYZ/facebook.php';
include_once 'lib.php';
include_once 'config.php';
$facebook = new Facebook($api_key, $secret);
$user = $facebook->require_login();
$loggedin = FALSE;
if (isset($user)) {
if ($user != '') {
echo '<p>Hello <fb:name firstnameonly="true" uid="'.$user.'" useyou="false" /></p>';
echo '<p>Log out</p>';
$loggedin = TRUE;
}
}
if ($loggedin == FALSE) {
echo '<p><fb:login-button onlogin="window.location=\'/\'"></fb:login-button></p>';
}
?>
</body>
</html>
Unfortunately, it doesn't work yet. What is wrong here?
When I want to access this page, I'm redirected to http://www.facebook.com/login.php?api_key=XYZ&v=1.0&next=XYZ where I have to log in. Then, being logged in to Facebook, I'm redirected again. This time, I get to https://login.facebook.com/login.php?auth_token=XYZ
try
$user = $facebook->get_loggedin_user();
instead of
$user = $facebook->require_login();
require_login() will force you to the facebook login.php

Resources