Skip to content

Commit

Permalink
invite waiting list users script
Browse files Browse the repository at this point in the history
  • Loading branch information
valzav committed Sep 7, 2016
1 parent cda848f commit 829ef67
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions scripts/send_waiting_list_invites.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import models from '../db/models';
import sendEmail from '../server/sendEmail';

models.User.findAll({
attributes: ['id', 'email'],
where: {waiting_list: true, email: {$ne: null}},
order: 'id DESC',
limit: 2
}).then(users => {
for(let u of users) {
const email = u.email.toLowerCase();
const m = email.match(/\.(\w+)$/);
if (!m || m[1] === 'ru') continue;
const confirmation_code = Math.random().toString(36).slice(2);
const i_attrs = {
provider: 'email',
user_id: u.id,
email,
verified: false,
confirmation_code
};
models.Identity.create(i_attrs).then(() => {
sendEmail('waiting_list_invite', email, {confirmation_code});
});
}
});
2 changes: 1 addition & 1 deletion server/server_pages/enter_confirm_email.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function *confirmEmailHandler() {
}
if (!eid.verified) {
yield eid.update({verified: true});
yield models.User.update({email: eid.email}, {where: {id: eid.user_id}});
yield models.User.update({email: eid.email, waiting_list: false}, {where: {id: eid.user_id}});
}
this.redirect('/create_account');
}
Expand Down

0 comments on commit 829ef67

Please sign in to comment.