Skip to content

Commit

Permalink
param correction and expiry info of 24 hours in verification email
Browse files Browse the repository at this point in the history
  • Loading branch information
mauryakrishna committed Nov 19, 2020
1 parent 76d35b8 commit 589ba69
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 89 deletions.
65 changes: 32 additions & 33 deletions src/resolvers/authors.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { cursorFormat, createdAtFormat, publishDateFormat, addMinutesInCurrentTi
export const verifyMe = (_, __, context) => {
const { displayname, authoruid } = context;
const valid = !!(displayname && authoruid);
if (valid) {
if (valid) {
return { valid, displayname, authoruid };
}
return { valid };
Expand All @@ -19,7 +19,7 @@ export const verifyMe = (_, __, context) => {
// get Authors details along both published experiences and unpublished experiences
// itsme: true - when author himself visit the page
// need to know if its authors own or is visitng different author page, difference would be not showing experiences in draft
export const getAuthor = async (_, { cursor, experienceperpage, uid, itsme }, context) => {
export const getAuthor = async (_, { cursor, experienceperpage, uid, itsme }, context) => {
cursor = cursor || cursorFormat(new Date());
experienceperpage = experienceperpage || EXPERIENCES_PER_PAGE;
itsme = (uid == context.authoruid);
Expand All @@ -28,16 +28,16 @@ export const getAuthor = async (_, { cursor, experienceperpage, uid, itsme }, co
SELECT *
FROM experiences
WHERE authoruid = ? AND updated_at < ?
${(itsme ? '': 'AND ispublished=true')}
${(itsme ? '' : 'AND ispublished=true')}
ORDER BY updated_at DESC
LIMIT ?
`;

const experiencesResult = await mysql.query(experiencesQuery, [uid, cursor, experienceperpage]);

const len = experiencesResult.length;
if (len > 0) {

if (len > 0) {
cursor = cursorFormat(new Date(experiencesResult[len - 1].updated_at));
}

Expand All @@ -46,34 +46,34 @@ export const getAuthor = async (_, { cursor, experienceperpage, uid, itsme }, co
const result = await mysql.query(query, [uid]);

const author = result[0];
author.experiences = experiencesResult.map((exp) => {
author.experiences = experiencesResult.map((exp) => {
exp.created_at = createdAtFormat(exp.created_at);
if (exp.publishdate) {

if (exp.publishdate) {
exp.publishdate = publishDateFormat(exp.publishdate);
}

return exp;
});

return { cursor, author };
};

const getUniqueUid = async (username) => {
const getUniqueUid = async (username) => {

const query = `
SELECT uid FROM authors
WHERE uid like '${username}%'
`;

const result = await mysql.query(query);

let uid = username;
const usernameset = result.map((user) => { return user.uid });

if (usernameset.includes(username)) {
// if found means uid duplicate, so generate unique
do {
do {
let randomNumber = Math.floor(Math.random(3) * 1000); // 3 digit
uid = `${username}${randomNumber}`;
}
Expand All @@ -83,28 +83,28 @@ const getUniqueUid = async (username) => {
return uid;
}

const getExisitingAuthor = async (email) => {
const getExisitingAuthor = async (email) => {
const query = `SELECT email, isemailverified FROM authors WHERE email = ?`;

const result = await mysql.query(query, [email]);
if (result && result.length) {
return {exist: true, isemailverified: result[0].isemailverified}

if (result && result.length) {
return { exist: true, isemailverified: result[0].isemailverified }
}
return {exist: false};
return { exist: false };
}

/**
* because fb Oauth is not used, below methodis not in force
*/
export const buttonPressRegister = async (_, __, context) => {
export const buttonPressRegister = async (_, __, context) => {
const { displayname, email } = context;
const variables = { input: { displayname, email } };

return await signupAuthor(_, variables, context);
}

const setForAccountVerification = async (displayname, email) => {
const setForAccountVerification = async (email, displayname) => {
// after inserting a user, set for email verification
const verificationkey = getAlphanumeric();
const verificationQuery = `
Expand All @@ -113,24 +113,24 @@ const setForAccountVerification = async (displayname, email) => {
`;

const verifytracker = await mysql.query(verificationQuery, [email, verificationkey, addMinutesInCurrentTime(VERIFICATION_LINK_EXPIRY_TIME)]);

//send mail for verifying email address
await SendEmailVerificationLink(displayname, email, verificationkey);
};

export const resendVerificationLink = async (_, { email }, context) => {
export const resendVerificationLink = async (_, { email }, context) => {
await setForAccountVerification(email);
return { resendsuccess: true };
}

// kind of register user
export const signupAuthor = async (_, { input }, context) => {

const { displayname, email, password, shortintro, region, languages } = input;

// the below is just backend protection from crreatng a duplicate author
const { exist, isemailverified } = await getExisitingAuthor(email);

// if found already, this should never happen that while registering we found if the user for
// given email exist, it will be done before reaching this point
if (exist) {
Expand Down Expand Up @@ -165,19 +165,18 @@ export const signinAuthor = async (_, { email, password }, context) => {
FROM authors
WHERE email=?
`;

const result = await mysql.query(query, [email]);
const author = result[0];

// user may not have signed up
if (!result || !result.length) {
if (!result || !result.length) {
return { exist: false };
}
else
{
else {
const { isemailverified } = result[0];
// for asking to validate email
if (!isemailverified) {
if (!isemailverified) {
return { exist: true, isemailverified };
}

Expand All @@ -192,7 +191,7 @@ export const signinAuthor = async (_, { email, password }, context) => {
exist: true, author: { ...author, authoruid: author && author.authoruid }, token, isemailverified
}
}
else {
else {
return {
exist: true, message: "Authentication failed.", isemailverified
};
Expand Down
111 changes: 55 additions & 56 deletions src/templates/emailverification.html
Original file line number Diff line number Diff line change
@@ -1,69 +1,68 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<style>
body {
width: 500px;
margin: auto;
}

p {
font-size: 18px;
}

.verify-button {
padding:12px 20px;
color: white;
background-color:#319795;
text-decoration: none;
text-align: center;
cursor: pointer;
font-size: 20px;
border: none;
}
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<style>
body {
width: 500px;
margin: auto;
}

/* background color here matches with footer on home page */
.footer {
background-color: #f0fff4;
}
p {
font-size: 18px;
}

.footer-text {
font-size: 14px;
color: black;
}
.verify-button {
padding: 12px 20px;
color: white;
background-color: #319795;
text-decoration: none;
text-align: center;
cursor: pointer;
font-size: 20px;
border: none;
}

</style>
</head>
<body style="width:500px; margin:auto;">
<div class="header"></div>
<div class="content">
<p style="font-size:'14px'">Hi <%= displayname %>,</p>
<p style="font-size:'14px'">Click the button below to verify your email address.</p>

<a
style="padding:'12px 20px'; color:white; background-color:#319795; text-decoration: none; text-align: center; cursor: pointer; font-size: 20px; border: none;"
type="button"
class="verify-button"
href="<%= url %>"
target="_blank"
noopener noreferer
>
/* background color here matches with footer on home page */
.footer {
background-color: #f0fff4;
}

.footer-text {
font-size: 14px;
color: black;
}
</style>
</head>

<body style="width:500px; margin:auto;">
<div class="header"></div>
<div class="content">
<p style="font-size:'14px'">Hi <%= displayname %>,</p>
<p style="font-size:'14px'">Click the button below to verify your email address. This link will be valid for 24
hours.</p>

<a style="padding:'12px 20px'; color:white; background-color:#319795; text-decoration: none; text-align: center; cursor: pointer; font-size: 20px; border: none;"
type="button" class="verify-button" href="<%= url %>" target="_blank" noopener noreferer>
<span style="font-size:14px;">Verify my email address</span>
</a>
<br />
<p style="font-size: '14px'">Once done, you will be able to share experiences, keep a draft and a lot more coming in future.</p>
<p style="font-size:'14px'">Feeling excited and want to know more or want to give us a feedback about your experiences with us, write us at <%= writetousemail %></p>

<p style="font-size:'14px'">Team experiences.guru</p>
</div>
<!--
</a>
<br />
<p style="font-size: '14px'">Once done, you will be able to share experiences, keep a draft and a lot more coming in
future.</p>
<p style="font-size:'14px'">Feeling excited and want to know more or want to give us a feedback about your
experiences with us, write us at <%= writetousemail %></p>

<p style="font-size:'14px'">Team experiences.guru</p>
</div>
<!--
<div class="footer" style="background-color:#f0fff4">
<span><a class="footer-text" style="font-size: 12px; margin:2px;" href="https://experiences.guru" target="_blank">Experiences©<%= new Date().getFullYear() %></a></span>
<span><a class="footer-text" style="font-size: 12px; margin:2px;" target="_blank">About</a></span>
<span><a class="footer-text" style="font-size: 12px; margin:2px;" heref="https://experiences.guru/privacy" target="_blank">Privacy</a></span>
</div>
-->
</body>
</html>
</body>

</html>

0 comments on commit 589ba69

Please sign in to comment.