Added option for promotional emails to signup page

This commit is contained in:
2019-06-14 16:29:06 +10:00
parent 921693c12d
commit e1744d6964
5 changed files with 31 additions and 25 deletions
+5 -5
View File
@@ -18,7 +18,7 @@ const signupRequest = (connection) => (req, res) => {
//parse form //parse form
form.parse(req, (err, fields) => { form.parse(req, (err, fields) => {
if (err) throw err; if (err) throw err;
console.log(fields);
//prevent too many clicks //prevent too many clicks
if (isThrottled(fields.email)) { if (isThrottled(fields.email)) {
res.status(400).write(log('Signup throttled', 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); let rand = Math.floor(Math.random() * 100000);
//save the generated data to the signups table //save the generated data to the signups table
let query = 'REPLACE INTO signups (email, username, salt, hash, verify) VALUES (?, ?, ?, ?, ?);'; let query = 'REPLACE INTO signups (email, username, salt, hash, promotions, verify) VALUES (?, ?, ?, ?, ?, ?);';
connection.query(query, [fields.email, fields.username, salt, hash, rand], (err) => { connection.query(query, [fields.email, fields.username, salt, hash, fields.promotions ? true : false, rand], (err) => {
if (err) throw err; if (err) throw err;
//TODO: make the verification email prettier //TODO: make the verification email prettier
@@ -145,8 +145,8 @@ const verifyRequest = (connection) => (req, res) => {
log('Trying to create account', req.query.email); log('Trying to create account', req.query.email);
//move the data from signups to accounts //move the data from signups to accounts
let query = 'INSERT IGNORE INTO accounts (email, username, salt, hash) VALUES (?, ?, ?, ?);'; 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], (err) => { connection.query(query, [results[0].email, results[0].username, results[0].salt, results[0].hash, results[0].promotions], (err) => {
if (err) throw err; if (err) throw err;
//delete from signups //delete from signups
+2
View File
@@ -25,6 +25,7 @@ CREATE TABLE IF NOT EXISTS signups (
username VARCHAR(100) UNIQUE, username VARCHAR(100) UNIQUE,
salt VARCHAR(50), salt VARCHAR(50),
hash VARCHAR(100), hash VARCHAR(100),
promotions BOOLEAN DEFAULT FALSE,
verify INTEGER DEFAULT 0 verify INTEGER DEFAULT 0
); );
@@ -37,6 +38,7 @@ CREATE TABLE IF NOT EXISTS accounts (
username VARCHAR(100) UNIQUE, username VARCHAR(100) UNIQUE,
salt VARCHAR(50), salt VARCHAR(50),
hash VARCHAR(100), hash VARCHAR(100),
promotions BOOLEAN DEFAULT FALSE,
lastActivityTime TIMESTAMP DEFAULT '2019-01-01 00:00:00' lastActivityTime TIMESTAMP DEFAULT '2019-01-01 00:00:00'
); );
+12 -16
View File
@@ -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 ALTER TABLE
pastSpying accounts
MODIFY COLUMN ADD COLUMN
success ENUM ('success', 'failure', 'ineffective') promotions BOOLEAN DEFAULT FALSE
; AFTER
hash
UPDATE
pastSpying
SET
success = 'ineffective'
WHERE
success = 'success'
AND
spoilsGold = 0
AND
(SELECT COUNT(*) FROM equipmentStolen WHERE pastSpyingId = pastSpying.id) = 0
; ;
+1 -3
View File
@@ -32,9 +32,7 @@ class Signup extends React.Component {
<Panel /> <Panel />
<Link to='/' className='centered'>Return Home</Link> <Link to='/' className='centered'>Return Home</Link>
<div className='break' /> <div className='break' />
<p className='centered'>Remember to verify your email!</p> <p className='centered'><em>(Remember to verify your email!)</em></p>
<div className='break' />
<p className='centered'>Check our rules concerning<br /><Link to='/rules'>conduct in this game</Link>.</p>
</div> </div>
); );
} }
+11 -1
View File
@@ -11,6 +11,7 @@ class Signup extends React.Component {
username: '', username: '',
password: '', password: '',
retype: '', retype: '',
promotions: false,
warning: '' warning: ''
}; };
} }
@@ -49,6 +50,11 @@ class Signup extends React.Component {
<input id='retype' type='password' name='retype' value={this.state.retype} onChange={this.updateRetype.bind(this)} /> <input id='retype' type='password' name='retype' value={this.state.retype} onChange={this.updateRetype.bind(this)} />
</div> </div>
<div style={{paddingLeft: '34px', alignSelf: 'flex-start', flex: '1', display:'flex', flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center'}}>
<label htmlFor='promotions'>Allow Emails:</label>
<input id='promotions' type='checkbox' name='promotions' value={this.state.promotions} onChange={this.updatePromotions.bind(this)} />
</div>
<button type='submit' disabled={!this.state.email}>Sign Up</button> <button type='submit' disabled={!this.state.email}>Sign Up</button>
</form> </form>
</div> </div>
@@ -121,7 +127,7 @@ class Signup extends React.Component {
} }
clearInput() { clearInput() {
this.setState({ email: '', username: '', password: '', retype: '', warning: '' }); this.setState({ email: '', username: '', password: '', retype: '', promotions: false, warning: '' });
} }
updateEmail(evt) { updateEmail(evt) {
@@ -139,6 +145,10 @@ class Signup extends React.Component {
updateRetype(evt) { updateRetype(evt) {
this.setState({ retype: evt.target.value }); this.setState({ retype: evt.target.value });
} }
updatePromotions(evt) {
this.setState({ promotions: evt.target.value });
}
}; };
Signup.propTypes = { Signup.propTypes = {