Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit d23de6e

Browse files
committed
Add support for account, \n add db migration for userlockout \n add email asking user to reset when account lockout
1 parent c7364a4 commit d23de6e

File tree

6 files changed

+71
-3
lines changed

6 files changed

+71
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<% include ../common-en_US/header.ejs %>
2+
3+
<h1>Hi <%=name%>,</h1>
4+
5+
<p>We have noticed multiple failed attempts to login to your zen account so for security reasons have locked your account. </p>
6+
7+
<p>To unlock your account you will need to change your password.</p>
8+
<p>Please follow the link below to reset your password.</br>
9+
<a href="<%=resetlink%>"><%=resetlink%></a></p>
10+
11+
12+
<p>Best wishes,</br>
13+
The CoderDojo Foundation Team</p>
14+
15+
<% include ../common-en_US/footer.ejs %>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Hi <%=name%>;
2+
3+
We have noticed multiple failed attempts to login to your zen account so for security reasons have locked your account.
4+
5+
To unlock your account you will need to change your password.
6+
Please follow the link below to reset your password.
7+
<%=resetlink%>
8+
9+
Best wishes,
10+
The CoderDojo Foundation Team

lib/users/unlock-account-email.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
var async = require('async');
3+
var _ = require('lodash');
4+
var protocol = process.env.PROTOCOL || 'http';
5+
var zenHostname = process.env.HOSTNAME || '127.0.0.1:8000';
6+
7+
function unlockAccountEmail (args, cb) {
8+
var seneca = this;
9+
var email = args.email;
10+
var locality = args.locality || 'en_US';
11+
var emailCode = 'user-lockout-';
12+
var emailSubject = 'CoderDojo Zen Account Lockout';
13+
14+
seneca.act({role: 'cd-users', cmd: 'get_users_by_email', email: email}, function (err, users) {
15+
if (err) return done(err);
16+
if (options['email-notifications'].sendemail) {
17+
seneca.act({role: 'email-notifications', cmd: 'send'}, {
18+
code: emailCode,
19+
locality: locality,
20+
to: email,
21+
subject: emailSubject,
22+
content: {name: users[0].name, resetlink: protocol + '://' + zenHostname + '/reset_password', year: moment(new Date()).format('YYYY')}
23+
}, function (err, response) {
24+
if (err) return done(err);
25+
return done(null, { ok: true });
26+
});
27+
} else {
28+
return done(null, {ok: false});
29+
}
30+
});
31+
}
32+
33+
module.exports = unlockAccountEmail;

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@
4949
"po2json": "0.4.2",
5050
"postgrator": "2.8.1",
5151
"request": "2.58.0",
52-
"seneca": "1.4",
53-
"seneca-auth": "1.0",
52+
"seneca": "1.4.0",
53+
"seneca-auth": "1.0.0",
5454
"seneca-mail": "^0.2.2",
5555
"seneca-postgresql-store": "2.3",
5656
"seneca-store-query": "0.0.5",
57-
"seneca-user": "1.0",
57+
"seneca-user": "2.0.0",
5858
"shortid": "2.2.2",
5959
"util": "^0.10.3",
6060
"xoauth2": "1.1.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
DO $$
2+
BEGIN
3+
BEGIN
4+
ALTER TABLE sys_user ADD COLUMN lock_try integer;
5+
EXCEPTION
6+
WHEN duplicate_column THEN RAISE NOTICE 'column token already exists in sys_user.';
7+
END;
8+
END;
9+
$$

users.js

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module.exports = function (options) {
3838
seneca.add({role: plugin, cmd: 'kpi_number_of_youth_females_registered'}, cmd_kpi_number_of_youth_females_registered);
3939
seneca.add({role: plugin, cmd: 'is_self'}, require('./lib/users/is-self'));
4040
seneca.add({role: plugin, cmd: 'is_parent_of'}, require('./lib/users/is-parent-of'));
41+
seneca.add({role: plugin, cmd: 'unlock_account_email'}, require('./lib/users/unlock-account-email'));
4142
seneca.add({role: plugin, ctrl: 'user', cmd: 'load'}, require('./lib/controllers/users/load'));
4243
// LMS Integration
4344
seneca.add({role: plugin, cmd: 'get_lms_link'}, require('./lib/users/lms/get-lms-link'));

0 commit comments

Comments
 (0)