Unable to customize AWS SES email template - javascript

I am trying to send a forgot password mail through AWS SES service. I made this template
{
"Template":{
"TemplateName": "forgotpasswrd",
"SubjectPart": "Forgot password ",
"TextPart":"Text area",
"HtmlPart":"<p>We heard that you lost your password. Sorry about that!<\/p>\r\n <p>But don\u2019t worry! You can use the following link to reset your password:<\/p>\r\n <a href=${url}>${url}<\/a>\r\n <p>If you don\u2019t use this link within 1 hour, it will expire.<\/p>\r\n "
}
}
And this is my code in nodejs to input password reset link.
const params = {};
const destination = {
ToAddresses: [String(email)],
};
const templateData = {};
templateData.url = String(Url);
params.Source = 'myemailid#gmail.com';
params.Destination = destination;
params.Template = 'forgotpassword';
params.TemplateData = JSON.stringify(templateData);
In this Url is what i am trying to send.
However when I receive the mail its it does not show the link but only the html text
" But don’t worry! You can use the following link to reset your password:
${url}
If you don’t use this link within 1 hour, it will expire."
How do I send the link in the mail?

It should be {{url}}, not ${url}. See the documentation.

Related

Is it possible to change this text email link to html, or at least show alternate text?

The code block below, upon a button click, will open an email with the some text and a link that I dynamically generate in the body of the email. It all works how I want, except that the link is long and looks like gibberish to the person receiving the email of course.
Is it possible to have my mailto: have either alternate text like an HTML link would have? Or even a button instead of the linked printed out in full?
sendSurvey(employee, employeeId, employmentLevel, audit, client) {
let stringEmployee = employee.replace(/ /g, "%20");
stringEmployee = encodeURI(stringEmployee);
let stringEmploymentLevel = employmentLevel.replace(/ /g, "%20");
stringEmploymentLevel = encodeURI(stringEmploymentLevel);
let stringClient = this.state.selectedClient;
stringClient = stringClient.replace(/ /g, "%20");
stringClient = encodeURI(stringClient);
const link = `http://localhost:3000/hca-survey/${employeeId}/${stringEmployee}/${stringEmploymentLevel}/${this.state.selectedAudit}/${stringClient}`;
const subject = `Human Capital Analysis - ${employee}`;
const body = `Hello, ${employee}. ${client} has selected you to participate in our Human Capital Analysis survey. Please click the link below in order to complete the survey at your convenience.`;
window.open(`mailto:?subject=${subject}&body=${body}
%0D%0A%0D%0A${link}
%0D%0A%0D%0AThank%20You%20for%20your%20responses...`);
}

Unable to retrieve data for displaying in the browser

I have a web app where I can login using Firebase. I know the details are stored in the Firebase database. I want the username value to be displayed on the browser in a certain field. Here are the screenshots.
This is the firebase data. In this picture, see the username karthik babu.
I want that username to be displayed on the area in the picture below:
So, instead of the username, I need the actual username value to be displayed.
Here is the code I tried:
var provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('https://www.googleapis.com/auth/plus.login');
firebase.auth().signInWithPopup(provider).then(function(user) {
var token = user.credential.accessToken;
var user = user.user;
var usersRef = firebase.database().ref("WoofyDesktop/UserList");
if (user) {
usersRef.child(user.uid).set({
useremail: user.email,
useruid: user.uid,
username: user.displayName
});
firebase retrieve code i tried:
var rootRef = firebase.database().ref().child("UserList");
rootRef.on("child_added", snap => {
var username = snap.child("username").val();
$("username").append("<div><a><label>" + username + "</label></a></div>");
console.log(username);
});
html code for username..
<div>
<a href="#" class="user">
<label for="username" id="username" >username</label>
</a></div>
Any suggestions on how or what I should change for displaying the required data?
Edit: Tried the updated query as in the answer by aks79 and this is what I am getting. Any insights?
You cannot embed another label inside a label tag
Limitations of label tag...
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label
use a different tag like div instead
try using it like
HTML Code
<div class="user" id="username"></div>
and the jquery as
$("#username").append("<a href='javascript:void(0)'><label>" + username + "</label></a>");

Firebase email verification workflow

I have a simple input box asking for users emails.
I want them to input something, for me to check it is a string, and then send a verification email to their email address entered.
Then once verified within users mail client and the link is clicked, I want the user to be added to my Firebase users.
At the moment, I am just testing without any email sending via SMTP, just adding data to Firebase. However, no emails I add are being added to my Firebase database.
Current code in the bottom of the body of the HTML, before the other script tags (should this be in the head?):
<script src="https://www.gstatic.com/firebasejs/3.6.1/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "myapikey",
authDomain: "mydomain.firebaseapp.com",
databaseURL: "https://mydomain.firebaseio.com",
storageBucket: "mydomain.appspot.com",
messagingSenderId: "mymessagesenderid"
};
firebase.initializeApp(config);
</script>
<script src="assets/js/saveEmail.js" type="text/javascript"></script>
Then I have an input box:
<div class="mtb">
<h2 class="signup-title">Sign up for updates on our project</h2>
<p id="signup-success" class="text-success"></p>
<p id="signup-error" class="text-danger"></p>
<form class="signup-form form-inline" id="signup-form" role="form" onsubmit="return signup(this)">
<div id="div">
<input type="email" name="email" class="subscribe-input" placeholder="Enter your e-mail address..." required>
<button class='btn btn-conf btn-yellow' id="signup-button" type="submit">Submit
</button>
</div>
</form>
</div>
And this is saveEmail.js:
var signupForm = document.getElementById('signup-form');
var signupSuccess = document.getElementById('signup-success');
var signupError = document.getElementById('signup-error');
var signupBtn = document.getElementById('signup-button');
var onSignupComplete = function (error) {
signupBtn.disabled = false;
if (error) {
signupError.innerHTML = 'Sorry. Could not signup.';
} else {
signupSuccess.innerHTML = 'Thanks for signing up!';
// hide the form
signupForm.style.display = 'none';
}
};
function signup(formObj) {
// Store emails to firebase
var myFirebaseRef = new Firebase("https://mydomain.firebaseio.com/signups");
myFirebaseRef.push({
email: formObj.email.value,
}, onSignupComplete);
signupBtn.disabled = true;
return false;
}
I know that the signup function is being called as I tried a simple JS alert, which does pop up when the submit button is clicked. However, I am seeing nothing change in my Firebase data dashboard under the /signups section. Also, the URL changes to:
http://localhost:5000/?email=theemailthatwasputintothebox
I modified my rules to:
{"rules":
{".read": true,
".write": true
}
}
So I assume this is not about rules as I have enabled everything for testing purposes.
How can I achieve what I want to achieve (without, and then with the email confirmation part)?
What is going wrong with the existing setup, without email confirmation via SendGrid etc?
I have a simple input box asking for users emails.
I want them to input something, for me to check it is a string, and
then send a verification email to their email address entered.
Then once verified within users mail client and the link is clicked, I want the user to be added to my Firebase users.
I do not think Firebase works that way. Unless the user is registered, you cannot send a verification email to an arbitrary email address. The sendEmailVerification method works on a currentUser.
According to the docs:
You can send an address verification email to a user with the sendEmailVerification method
Now, to your snippet, aren't you simply trying to take a user input and save it to the database? With the recent SDK, you can try this, as per docs
....
var database = firebase.database();
function signup(formObj) {
// Store emails to firebase
database.ref('signups')
.push({
email: formObj.email.value,
})
.then(function(res) {
console.log(res)
// call whatever callback you want here
})
.catch( .... )
}
FYI if you are using Firebase email verification think about testing it during your end-to-end or smoke tests.
Use a service like emaile2e.com to generate random email addresses during a test which you can send and receive from. That way you can verify users during a test programmatically.

Displaying Facebook Avatar in Meteor

I've been trying to get the bengott:avatar package from atmosphere.js to work with Facebook but have not been able to do so. When I use {{> avatar user=this shape="circle"}}it only seems to display a gray circle with no picture inside.
Other calls such as {{currentUser.profile.name}}work perfectly fine.
How can I successfully display an avatar with or without the bengott:avatar package?
Use this instead, you don't need an access token or anything special to get their profile picture, just their facebook user id.
Accounts.onCreateUser(function(options, user) {
if (options.profile) {
options.profile.picture = "http://graph.facebook.com/" + user.services.facebook.id + "/picture/?type=large";
user.profile = options.profile;
}
return user;
});
I use a helper function based off of the Facebook ID of the user to grab the image on the server. Hope this helps.
userPicHelper: function() {
if (this.profile) {
var id = this.profile.facebookId;
var img = 'http://graph.facebook.com/' + id + '/picture?type=square&height=160&width=160';
return img;
}
},
In the template you would use the helper like this:
<img src="{{userPicHelper}}" alt="" />

how to create message box on javaScript(server side) using submit button (onclick)

This is my sample script i write.
Task :
-To create a pop up message to show user if they haven't register as a member on system.
-User must have name inside the note view "Staff information by name"
-if user have name inside the view, it will write a message to a reviewer, to inform review what they request for.
-if user don't have name in "staff information by name" view, it will pop up a message to told user what to do.
// address book
var db:NotesDatabase = session.getDatabase("websvr/pcs", "names", false);
var vw2:NotesView = db.getView("($VIMPeople)");
var dc2:NotesDocumentCollection = vw2.getAllDocumentsByKey(document1.getItemValue("Name"),true);
var doc2:NotesDocument=dc2.getFirstDocument();
while (doc2!=null){
sname=doc2.getItemValueString('LastName')
doc2=dc2.getNextDocument();
}
// end of address book
//current database
var vw:NotesView = database.getView("Staff Information By Name");
var doc:NotesDocument = vw.getDocumentByKey(sname, true);
//check whether have setting on reviewer for current user else will be hard code to specific person
if (doc!=null)
{
revname=doc.getItemValueString("Reviewer")
rev=doc.getItemValueString("ReviewerEmail");
//set Email
var maildoc:NotesDocument=database.createDocument();
var body=maildoc.createMIMEEntity();
var stream=session.createStream();
var content="Dear "+revname+",<br></br>"+
"Please click <a href='http://"+applicationScope.hostname+"/"+(applicationScope.dbfilepath).replace(/(\\)/g, "/")+"/"+
"RequisitionForm.xsp?databaseName="+applicationScope.serverCN+"!!"+
applicationScope.dbfilepath+"&documentId="+
document1.getDocument().getUniversalID()+
"&action=editDocument'>here</a> to view it if you are in a web browser (eg: Internet Explorer, Mozilla Firefox, Google Chrome etc.)"+
"<br /><br /><b>OR</b><br /><br />"+
"<a href='"+document1.getDocument().getNotesURL()+"'>here</a> if you are in the Notes Client. Thank you.";
stream.writeText(content);
body.setContentFromText(stream, "text/html; charset=iso-8859-1", 0);
maildoc.replaceItemValue('Subject', 'Kindly review this '+document1.getItemValueString('Item')+' request by '+document1.getItemValueString('Name')+" on "+I18n.toString(#Today(), 'dd/MM/yyyy'));
maildoc.send(rev);
document1.replaceItemValue("TotalCost",document1.getValue("Cost")*document1.getValue("Qty"));
document1.replaceItemValue("Status","Pending");
document1.save();
context.redirectToPage("/MyRequisition.xsp");
}
else
{
a = 'alert("You do not have access right, please contact admin to register!")' ;
view.postScript(a);
break;
}
The sample script that work on other page :
a = 'alert("The applicant details must be unique!")' ;
b = 'alert("Applicant Details inserted!")' ;
var vw:NotesView = database.getView("Staff information by Name");
var doc:NotesDocument = vw.getDocumentByKey(getComponent("Name").getValue(), true);
if (doc!=null){
view.postScript(a);
break;
}
else
{
var newDoc = database.createDocument();
newDoc.appendItemValue("Form", "Staff Form");
newDoc.appendItemValue("Name", getComponent("Name").getValue());
newDoc.appendItemValue("Designation", getComponent("Designation").getValue());
newDoc.appendItemValue("Department", getComponent("Department").getValue());
newDoc.appendItemValue("Reviewer", getComponent("Reviewer").getValue());
newDoc.appendItemValue("Email", getComponent("Email").getValue());
newDoc.appendItemValue("ReviewerEmail", getComponent("ReviewerEmail").getValue());
newDoc.save();
getComponent("Name").setValue("");
getComponent("Designation").setValue("");
getComponent("Department").setValue("");
getComponent("Reviewer").setValue("");
getComponent("Email").setValue("");
getComponent("ReviewerEmail").setValue("");
view.postScript(b);
}
postScript() works only with partial refresh. If your code runs in event handler in full refresh mode, your postScript statement will have no effect.
Alternate solution is to use Output script (xp:scriptBlock) component with something like this:
var message = "#{requestScope.message}";
if (message) {
alert(message);
}
In your SSJS just set your message:
requestScope.message = condition ? "True!" : "False!";
http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/index.jsp?topic=%2Fcom.ibm.designer.domino.ui.doc%2Fwpd_controls_cref_scriptblock.html
You can user facesContext and postscript to call JavaScript function on server side.
facesContext.getViewRoot().postScript("alert('"+documentName.getItemValueString("FieldName"));

Categories

Resources