Skip to content

Commit

Permalink
feature(auth): let users confirm their account
Browse files Browse the repository at this point in the history
- On the user's dashboard, they can click a button to get a link
in their mailbox with which to confirm their account
- If the account is already confirmed, this link is hidden

[Delivers #166278087]
  • Loading branch information
chidimo committed May 28, 2019
1 parent da61943 commit 99306f3
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 24 deletions.
14 changes: 13 additions & 1 deletion UI/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,18 @@ footer {

/* Dashboard */

#mailverification {
padding: 5px;
margin-bottom: 10px;
font-size: 28px;
}

#mailverification button {
width: 100%;
height: 60px;
font-size: 28px;
}

.card {
padding: 10px;
width: 450px;
Expand All @@ -552,7 +564,7 @@ footer {
overflow: hidden;
}

.fa-check-circle {
.status-ok {
color: green;
}

Expand Down
5 changes: 5 additions & 0 deletions UI/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ <h2 class="page_heading"><span class='capitalize firstname'></span> <span class=

<hr class="section_divider">

<div id="mailverification">
<p>Your email address has not been confirmed. Click the box below to get your verification email</p>

<button class="">Get confirmation email</button>
</div>

<div class="user_information">
<div class="user_card card">
Expand Down
37 changes: 14 additions & 23 deletions UI/js/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-undef */

const mailverification = document.getElementById('mailverification');
const profile_pix = document.getElementById('profile_pix');
const img_uploader = document.querySelector('input[id=img_uploader]');
const images = document.getElementsByClassName('photos');
Expand Down Expand Up @@ -40,6 +41,15 @@ profile_pix.addEventListener('click', e => {
img_uploader.click();
});

mailverification.addEventListener('click', async e => {
e.preventDefault();
const url = `${base_url}/users/${id}/get-mail`;
const { data, status } = await axios.get(url);
if (status === 200) {
alert(`${data.msg}\nPlease check your inbox`);
}
});

// DOM substitutions
for (const image of images) {
image.src = photo;
Expand All @@ -61,29 +71,10 @@ for (const circle of circles) {
}
}

// const reload_pix = () => {
// const container = document.getElementById('photo_window');
// const content = container.innerHTML;
// container.innerHTML = content;

// // this line is to watch the result in console , you can remove it later
// console.log('Refreshed');
// };

// const update_profile_pix = file => {
// const reader = new FileReader();
// reader.addEventListener('load', () => {
// const { result } = reader;
// profile_pix.src = result;
// });
// if (file) {
// reader.readAsDataURL(file);
// }
// else {
// const src = `https://${endpoint}/quick-credit/profile_photos/${id}`;
// profile_pix.src = src;
// }
// };
if (mailverified) {
mailverification.style.display = 'none';
}
// end DOM substitutions

img_uploader.onchange = async e => {
e.preventDefault();
Expand Down
14 changes: 14 additions & 0 deletions controllers/AuthController.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ const AuthController = {
}
return res.status(404).json({ error: 'Incorrect password' });
},

confirm_email: async (req, res) => {
const { id } = req.params;
try {
const clause = `WHERE id=${id}`;
const err_msg = `User with id ${id} not found`;
const user = await get_existing_user(
users_model, res, clause, err_msg);
sendSignUpMessage(user, req);
return res.status(200).json({ msg: 'Success' });
}
catch (e) { return; }

},
};

export default AuthController;
3 changes: 3 additions & 0 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ router.patch('/users/:id/verify',
AuthenticationMiddleware.verifyToken,
UsersController.verify_user
);

router.get('/users/:id/get-mail', AuthController.confirm_email);

router.get('/users/:id/account-confirmation',
UsersController.confirm_account
);
Expand Down

0 comments on commit 99306f3

Please sign in to comment.