Skip to content

Commit

Permalink
Beginning user dashboard work.
Browse files Browse the repository at this point in the history
  • Loading branch information
lesleyjanenorton committed Apr 4, 2019
1 parent 8744920 commit 330d651
Show file tree
Hide file tree
Showing 20 changed files with 397 additions and 83 deletions.
2 changes: 1 addition & 1 deletion controllers/scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const crypto = require("crypto");

const AppConstants = require("../app-constants");
const { FluentError } = require("../locale-utils");
const { generatePageToken } = require("./utils");
// const { generatePageToken } = require("./utils");
const mozlog = require("../log");
const scanResult = require("../scan-results");
const sha1 = require("../sha1-utils");
Expand Down
43 changes: 39 additions & 4 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ function _requireSessionUser(req) {
return req.session.user;
}

async function resend(req, res) {
return res.json("Resend the email");
}

async function add(req, res) {
// need to decide how to handle resends

_requireSessionUser(req);
const email = req.body.email;

Expand Down Expand Up @@ -52,14 +58,42 @@ async function add(req, res) {
});
}

const getDashboard = async(req, res) => {
const bundleVerifiedEmails = async(email, emailSha1, ifPrimary, allBreaches) => {
const foundBreaches = await HIBP.getBreachesForEmail(emailSha1, allBreaches, true);

const emailEntry = {
"email": email,
"breaches": foundBreaches,
"primary": ifPrimary,
};
return emailEntry;
};

async function getDashboard(req, res) {
const allBreaches = req.app.locals.breaches;
const user = req.session.user;
const userEmails = await DB.getUserEmails(user.id);
console.log(userEmails);
const monitoredEmails = await DB.getUserEmails(user.id);

const verifiedEmails = [];
const unverifiedEmails = [];

verifiedEmails.push(await bundleVerifiedEmails(user.primary_email, user.primary_sha1, true, allBreaches));

for (const email of monitoredEmails) {
if (email.verified) {
const formattedEmail = await bundleVerifiedEmails(email.email, email.sha1, email.verified, allBreaches);
verifiedEmails.push(formattedEmail);
} else {
unverifiedEmails.push(email);
}
}

// console.log(verifiedEmails);
res.render("dashboard", {
title: req.fluentFormat("user-dash"),
verifiedEmails, unverifiedEmails,
});
};
}


async function _verify(req) {
Expand Down Expand Up @@ -205,4 +239,5 @@ module.exports = {
getUnsubSurvey,
postUnsubSurvey,
logout,
resend,
};
7 changes: 7 additions & 0 deletions locales/en/app.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -547,3 +547,10 @@ feat-email-alerts= Email alerts for new breaches
feat-info-about= Info about other {-brand-Mozilla} services
sign-up-for-fxa= Sign up for a {-brand-fxa}
appears-in-x-breaches =
{ $breachCount ->
[one] Appears in { $breachCount } breach.
*[other] appears in { $breachCount } breaches.
}
6 changes: 5 additions & 1 deletion public/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ body {
--radius: 1rem;
--blue: #4f42ff;
--borderColors: var(--blue) #c78d20 #ff7e88 #ac3eff;
--borderColor: rgba(219, 219, 219, 0.81);
--deepBlue: #3100f5;
--darkBlue: #2e04d7;

display: flex;
flex-direction: column;
Expand All @@ -34,6 +37,7 @@ body {
background-color: rgba(249, 249, 250, 1);
color: var(--color);
font-family: "SF Pro Text", "Inter UI", -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Open Sans', 'Helvetica Neue', sans-serif;
font-weight: 300;
font-size: 0.9rem;
overflow-y: scroll;
overflow-x: hidden;
Expand Down Expand Up @@ -376,7 +380,7 @@ li:hover .arrow {
}

.brdr {
border: 1px solid #eee;
border: 1px dashed var(--borderColor);
border-radius: var(--radius);
}

Expand Down
6 changes: 3 additions & 3 deletions public/css/breach-stats.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
width: 4rem;
height: 3rem;
justify-content: center;
border-right: 1px solid rgba(219, 219, 219, 0.9);
border-right: 1px dashed var(--borderColor);
margin: 0.15rem;
}

Expand All @@ -20,7 +20,7 @@

.breach-stats {
background-color: rgba(255, 255, 255, 0);
border: 1px solid rgba(219, 219, 219, 0.9);
border: 1px dashed var(--borderColor);
border-radius: var(--radius);
overflow: hidden;
display: flex;
Expand All @@ -36,7 +36,7 @@

.breach-stat-row {
width: 100%;
border-bottom: 1px solid rgba(219, 219, 219, 0.9);
border-bottom: 1px dashed var(--borderColor);
}

.breach-stat-row.flx:first-of-type {
Expand Down
132 changes: 132 additions & 0 deletions public/css/dashboard.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/* User breach stats */
main.dashboard {
border-top: 1px dashed var(--borderColor);
}

main.dashboard .row {
flex-wrap: wrap;
max-width: 1400px;
}

.breach-stats.user-stats {
margin: 0 0 var(--margin) 0;
}

/* table of monitored email addresses */
.email-table {
border-radius: 1rem;
overflow: hidden;
}

/* email cards */
.e-toggle-info-wrapper {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: var(--margin) 0;
border-bottom: 1px solid#eee;
}

.e-info { /* wraps email address info */
display: inline-flex;
flex-direction: column;
}

/* email card styling */
.e-address {
font-weight: 400;
margin-bottom: 0.5rem;
font-size: 1.2rem;
}

.e-num-breaches {
font-style: italic;
font-weight: 300;
color: #666;
}

/* email card breaches */
.email-card .e-breach-list {
visibility: hidden;
opacity: 0;
max-height: 0;
transition: all 0.3s ease;
}

.email-card.inactive .e-breach-list > * {
max-height: 0;
transition: all 0.3s ease;
}

.email-card.active .e-breach-list > * {
max-height: 10000px;
transition: all 0.3s ease;
}

.email-card.active .e-breach-list {
visibility: visible;
opacity: 1;
max-height: 20000px;
transition: all 0.3s ease;
}

/* unverified emails */
button.resend-email {
border-width: 0;
border-radius: 0.25rem;
padding: 0.5rem;
}

button.resend-email:hover {
outline: none;
border: none;
background-color: rgba(0, 0, 0, 0.05);
box-shadow: none;
}

/* toggle transition on card open */
.email-card .toggle {
display: flex;
justify-content: flex-end;
flex: 1 1 50%;
position: relative;
transition: all 0.1s ease;
}

svg.toggle-down {
width: 20px;
height: 20px;
position: absolute;
top: 0;
bottom: 0;
margin: auto;
right: var(--padding);
}

.email-card.active .toggle-down {
transform: rotate(180deg);
transition: all 0.1s ease;
}

/* sidebar */
.skinny-headline.breach-summary {
font-size: 1rem;
}

@media screen and (max-width: 800px) {
main.dashboard {
border-top: none;
}

.dash-stats,
.breach-stats {
max-width: 100%;
}
}

@media screen and (max-width: 600px) {
.row.dashboard-wrap-reverse {
flex-direction: column-reverse;
}
}
1 change: 1 addition & 0 deletions public/css/forms.css
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ input[type="email"] {
font-weight: 300;
border-color: var(--borderColors);
text-indent: var(--margin);
background-color: transparent;
transition: all 0.1s ease-out;
}

Expand Down
13 changes: 8 additions & 5 deletions public/css/latest-breach.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
box-shadow: 1px 1px 10px #8181810e;
border-radius: var(--radius);
padding: 0;
background-color: rgba(249, 249, 250, 1);

/* background-color: rgba(249, 249, 250, 1); */
color: rgba(255, 255, 255, 0.8);
background-color: var(--darkBlue);
}

.latest-breach {
Expand All @@ -20,7 +23,7 @@
font-weight: 200;
text-transform: uppercase;
letter-spacing: 2px;
background-color: white;
background-color: rgba(255, 255, 255, 0.1);
}

.latest-breach .logo-wrapper {
Expand All @@ -43,7 +46,7 @@

.latest-breach-info {
padding: var(--padding) calc(var(--padding) * 2) calc(var(--padding) * 2) calc(var(--padding) * 2);
background-color: rgba(249, 249, 250, 1);
background-color: rgba(249, 249, 250, 0.15);
border-top: 1px solid #7cdfff0d;
}

Expand Down Expand Up @@ -102,7 +105,7 @@

.latest-breach-headline {
padding: 1rem 1rem 1rem 1rem;
border: 1px dashed rgba(238, 238, 238, 0.2);
border: 1px dashed var(--borderColor);
border-bottom: none;
border-top-right-radius: 1rem;
border-top-left-radius: 1rem;
Expand All @@ -113,7 +116,7 @@
padding-bottom: 2rem;
padding-left: 1rem;
padding-right: 1rem;
border: 1px dashed rgba(238, 238, 238, 0.2);
border: 1px dashed var(--borderColor);
border-bottom-right-radius: 1rem;
border-bottom-left-radius: 1rem;
}
Expand Down
45 changes: 45 additions & 0 deletions public/js/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"use strict";

const findAncestor = (el, cls) => {
while ((el = el.parentElement) && !el.classList.contains(cls));
return el;
};

const toggleEl = (e) => {
const toggleElem = e.target;
const toggleParent = findAncestor(toggleElem, "toggle-parent");
["inactive", "active"].forEach(className => {
toggleParent.classList.toggle(className);
});
};

const resendEmail = async(e) => {
const resendLink = e.target;
const parentDiv = findAncestor(resendLink, "e-toggle-info-wrapper");
const emailToSend = parentDiv.querySelector("span.unverified-e-address").innerText;

JSON.stringify(emailToSend);

await fetch("/user/resend-email", {
headers: {
"Content-Type": "application/json; charset=utf-8",
},
mode: "cors",
method: "POST",
body: JSON.stringify({ "email": emailToSend }),
});
};

if (document.querySelector(".toggle")) {
const toggles = document.querySelectorAll(".toggle");
toggles.forEach(el => {
el.addEventListener("click", toggleEl);
});

if (document.querySelector(".resend-email")) {
const resendLinks = document.querySelectorAll(".resend-email");
resendLinks.forEach(link => {
link.addEventListener("click", resendEmail);
});
}
}
Loading

0 comments on commit 330d651

Please sign in to comment.