From e1744d69642b573cc03dd358db4e16b334e207dc Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 14 Jun 2019 16:29:06 +1000 Subject: [PATCH] Added option for promotional emails to signup page --- server/accounts.js | 10 +++++----- sql/create_database_structure.sql | 2 ++ sql/update.sql | 28 ++++++++++++---------------- src/components/pages/signup.jsx | 4 +--- src/components/panels/signup.jsx | 12 +++++++++++- 5 files changed, 31 insertions(+), 25 deletions(-) diff --git a/server/accounts.js b/server/accounts.js index 14c3f50..d02149a 100644 --- a/server/accounts.js +++ b/server/accounts.js @@ -18,7 +18,7 @@ const signupRequest = (connection) => (req, res) => { //parse form form.parse(req, (err, fields) => { if (err) throw err; - +console.log(fields); //prevent too many clicks if (isThrottled(fields.email)) { res.status(400).write(log('Signup throttled', fields.email)); @@ -74,8 +74,8 @@ const signupRequest = (connection) => (req, res) => { let rand = Math.floor(Math.random() * 100000); //save the generated data to the signups table - let query = 'REPLACE INTO signups (email, username, salt, hash, verify) VALUES (?, ?, ?, ?, ?);'; - connection.query(query, [fields.email, fields.username, salt, hash, rand], (err) => { + let query = 'REPLACE INTO signups (email, username, salt, hash, promotions, verify) VALUES (?, ?, ?, ?, ?, ?);'; + connection.query(query, [fields.email, fields.username, salt, hash, fields.promotions ? true : false, rand], (err) => { if (err) throw err; //TODO: make the verification email prettier @@ -145,8 +145,8 @@ const verifyRequest = (connection) => (req, res) => { log('Trying to create account', req.query.email); //move the data from signups to accounts - let query = 'INSERT IGNORE INTO accounts (email, username, salt, hash) VALUES (?, ?, ?, ?);'; - connection.query(query, [results[0].email, results[0].username, results[0].salt, results[0].hash], (err) => { + let query = 'INSERT IGNORE INTO accounts (email, username, salt, hash, promotions) VALUES (?, ?, ?, ?, ?);'; + connection.query(query, [results[0].email, results[0].username, results[0].salt, results[0].hash, results[0].promotions], (err) => { if (err) throw err; //delete from signups diff --git a/sql/create_database_structure.sql b/sql/create_database_structure.sql index 34c4b2a..cd9fd7e 100644 --- a/sql/create_database_structure.sql +++ b/sql/create_database_structure.sql @@ -25,6 +25,7 @@ CREATE TABLE IF NOT EXISTS signups ( username VARCHAR(100) UNIQUE, salt VARCHAR(50), hash VARCHAR(100), + promotions BOOLEAN DEFAULT FALSE, verify INTEGER DEFAULT 0 ); @@ -37,6 +38,7 @@ CREATE TABLE IF NOT EXISTS accounts ( username VARCHAR(100) UNIQUE, salt VARCHAR(50), hash VARCHAR(100), + promotions BOOLEAN DEFAULT FALSE, lastActivityTime TIMESTAMP DEFAULT '2019-01-01 00:00:00' ); diff --git a/sql/update.sql b/sql/update.sql index 0b16593..69c1f65 100644 --- a/sql/update.sql +++ b/sql/update.sql @@ -1,20 +1,16 @@ -#NOTE: ALWAYS, ALWAYS, ALWAYS write a script in revert.sql that undoes these changes +ALTER TABLE + signups +ADD COLUMN + promotions BOOLEAN DEFAULT FALSE +AFTER + hash +; ALTER TABLE - pastSpying -MODIFY COLUMN - success ENUM ('success', 'failure', 'ineffective') -; - -UPDATE - pastSpying -SET - success = 'ineffective' -WHERE - success = 'success' -AND - spoilsGold = 0 -AND - (SELECT COUNT(*) FROM equipmentStolen WHERE pastSpyingId = pastSpying.id) = 0 + accounts +ADD COLUMN + promotions BOOLEAN DEFAULT FALSE +AFTER + hash ; diff --git a/src/components/pages/signup.jsx b/src/components/pages/signup.jsx index f730e42..ca3a66a 100644 --- a/src/components/pages/signup.jsx +++ b/src/components/pages/signup.jsx @@ -32,9 +32,7 @@ class Signup extends React.Component { Return Home
-

Remember to verify your email!

-
-

Check our rules concerning
conduct in this game.

+

(Remember to verify your email!)

); } diff --git a/src/components/panels/signup.jsx b/src/components/panels/signup.jsx index 1eb3d01..cb8d766 100644 --- a/src/components/panels/signup.jsx +++ b/src/components/panels/signup.jsx @@ -11,6 +11,7 @@ class Signup extends React.Component { username: '', password: '', retype: '', + promotions: false, warning: '' }; } @@ -49,6 +50,11 @@ class Signup extends React.Component {
+
+ + +
+ @@ -121,7 +127,7 @@ class Signup extends React.Component { } clearInput() { - this.setState({ email: '', username: '', password: '', retype: '', warning: '' }); + this.setState({ email: '', username: '', password: '', retype: '', promotions: false, warning: '' }); } updateEmail(evt) { @@ -139,6 +145,10 @@ class Signup extends React.Component { updateRetype(evt) { this.setState({ retype: evt.target.value }); } + + updatePromotions(evt) { + this.setState({ promotions: evt.target.value }); + } }; Signup.propTypes = {