From 829ef678af0df7e9b98872799ccc931811ecb1ed Mon Sep 17 00:00:00 2001 From: valzav Date: Wed, 7 Sep 2016 18:31:28 -0400 Subject: [PATCH] invite waiting list users script --- scripts/send_waiting_list_invites.js | 26 +++++++++++++++++++++ server/server_pages/enter_confirm_email.jsx | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 scripts/send_waiting_list_invites.js diff --git a/scripts/send_waiting_list_invites.js b/scripts/send_waiting_list_invites.js new file mode 100644 index 0000000000..b68edc9369 --- /dev/null +++ b/scripts/send_waiting_list_invites.js @@ -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}); + }); + } +}); diff --git a/server/server_pages/enter_confirm_email.jsx b/server/server_pages/enter_confirm_email.jsx index f04b1800be..75c4ac5ce1 100644 --- a/server/server_pages/enter_confirm_email.jsx +++ b/server/server_pages/enter_confirm_email.jsx @@ -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'); }