summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-09-15 17:49:40 +0200
committerTor Andersson <tor@ccxvii.net>2022-10-05 17:36:50 +0200
commit8dfef7634ee84eb731461058bb1785f8cf472564 (patch)
tree655b83840bfacadddc6f9189581499f2f9a220dc
parent9bc6ff25186537ef0e07b0ff559a35c6d629ad31 (diff)
downloadserver-8dfef7634ee84eb731461058bb1785f8cf472564.tar.gz
Add checkbox for mail notifications on signup page.
-rw-r--r--public/style.css2
-rw-r--r--server.js5
-rw-r--r--views/signup.pug6
3 files changed, 10 insertions, 3 deletions
diff --git a/public/style.css b/public/style.css
index 6298195..65c92df 100644
--- a/public/style.css
+++ b/public/style.css
@@ -48,7 +48,7 @@ div.logo img {
input[type="checkbox"] {
margin-right: 7px;
}
-input[type="text"], input[type="password"], textarea {
+input[type="text"], input[type="password"], input[type="email"], textarea {
padding: 5px;
margin: 5px 0;
border: 1px solid black;
diff --git a/server.js b/server.js
index bda099a..7e63528 100644
--- a/server.js
+++ b/server.js
@@ -263,7 +263,7 @@ const SQL_BLACKLIST_MAIL = SQL("SELECT EXISTS ( SELECT 1 FROM blacklist_mail WHE
const SQL_EXISTS_USER_NAME = SQL("SELECT EXISTS ( SELECT 1 FROM users WHERE name=? )").pluck()
const SQL_EXISTS_USER_MAIL = SQL("SELECT EXISTS ( SELECT 1 FROM users WHERE mail=? )").pluck()
-const SQL_INSERT_USER = SQL("INSERT INTO users (name,mail,password,salt) VALUES (?,?,?,?) RETURNING user_id,name,mail,notify")
+const SQL_INSERT_USER = SQL("INSERT INTO users (name,mail,password,salt,notify) VALUES (?,?,?,?,?) RETURNING user_id,name,mail,notify")
const SQL_SELECT_USER_BY_NAME = SQL("SELECT * FROM user_view WHERE name=?")
const SQL_SELECT_LOGIN_BY_MAIL = SQL("SELECT * FROM user_login_view WHERE mail=?")
@@ -451,6 +451,7 @@ app.post('/signup', function (req, res) {
let name = req.body.username
let mail = req.body.mail
let password = req.body.password
+ let notify = req.body.notify === 'true'
name = clean_user_name(name)
if (!is_valid_user_name(name))
return err("Invalid user name!")
@@ -466,7 +467,7 @@ app.post('/signup', function (req, res) {
return err("Password is too long!")
let salt = crypto.randomBytes(32).toString('hex')
let hash = hash_password(password, salt)
- let user = SQL_INSERT_USER.get(name, mail, hash, salt)
+ let user = SQL_INSERT_USER.get(name, mail, hash, salt, notify ? 1 : 0)
login_insert(res, user.user_id)
res.redirect('/profile')
})
diff --git a/views/signup.pug b/views/signup.pug
index b0cf901..f0ff37f 100644
--- a/views/signup.pug
+++ b/views/signup.pug
@@ -27,5 +27,11 @@ html
label Password:
br
input(type="password" name="password" required)
+ div
+ label
+ input(type="checkbox" name="notify" value="true")
+ | Enable mail notifications
+ div(style="margin-left:2rem")
+ i (when it is your turn, your games are ready to start, etc.)
p
button(type="submit") Create account