Permalink
Browse files

Add users.verified feature

When a user's verified flag is set, the user can register riders (add /
remove / modify) and the verified flags of those riders are not cleared.
  • Loading branch information...
andreas-gruenbacher committed Apr 15, 2017
1 parent fe22ca4 commit cdddbba602b1056fa048ba33f17761a04ec95cf3
Showing with 20 additions and 16 deletions.
  1. +15 −13 backend/index.js
  2. +2 −1 convert-db.sql
  3. +3 −2 create-db.sql
View
@@ -139,7 +139,7 @@ async function validate_user(connection, user) {
throw 'Wrong email or password';
var rows = await connection.queryAsync(`
SELECT email, password, user_tag, admin
SELECT email, password, user_tag, verified, admin
FROM users
WHERE email = ? AND password IS NOT NULL`, [user.email]);
@@ -2611,14 +2611,14 @@ async function change_password(req, res, next) {
}
}
async function register_save_rider(connection, id, number, rider, user_tag, version) {
async function register_save_rider(connection, id, number, rider, user, version) {
await cache.begin(connection);
try {
var event = await get_event(connection, id);
var old_rider;
if (number != null) {
old_rider = await get_rider(connection, id, number);
if (old_rider.user_tag != user_tag)
if (old_rider.user_tag != user.user_tag)
throw new HTTPError(403, 'Forbidden');
} else {
var result = await connection.queryAsync(`
@@ -2657,14 +2657,16 @@ async function register_save_rider(connection, id, number, rider, user_tag, vers
delete rider.non_competing;
delete rider.rankings;
delete rider.registered;
rider.verified = false;
rider.user_tag = user_tag;
if (!event.features.verified) {
event = cache.modify_event(id);
event.features = Object.assign({}, event.features);
event.features.verified = true;
delete rider.verified;
if (!user.verified) {
rider.verified = false;
if (!event.features.verified) {
event = cache.modify_event(id);
event.features = Object.assign({}, event.features);
event.features.verified = true;
}
}
rider.user_tag = user.user_tag;
rider = Object.assign(cache.modify_rider(id, number), rider);
} else {
@@ -3359,7 +3361,7 @@ app.get('/api/register/event/:id/suggestions', function(req, res, next) {
app.post('/api/register/event/:id/rider', async function(req, res, next) {
var rider = req.body;
try {
rider = await register_save_rider(req.conn, req.params.id, null, rider, req.user.user_tag);
rider = await register_save_rider(req.conn, req.params.id, null, rider, req.user);
res.status(201);
res.json(rider);
} catch (err) {
@@ -3370,7 +3372,7 @@ app.post('/api/register/event/:id/rider', async function(req, res, next) {
app.put('/api/register/event/:id/rider/:number', async function(req, res, next) {
var rider = req.body;
try {
rider = await register_save_rider(req.conn, req.params.id, req.params.number, rider, req.user.user_tag);
rider = await register_save_rider(req.conn, req.params.id, req.params.number, rider, req.user);
res.json(rider);
} catch (err) {
next(err);
@@ -3379,7 +3381,7 @@ app.put('/api/register/event/:id/rider/:number', async function(req, res, next)
app.delete('/api/register/event/:id/rider/:number', async function(req, res, next) {
try {
await register_save_rider(req.conn, req.params.id, req.params.number, null, req.user.user_tag, req.query.version);
await register_save_rider(req.conn, req.params.id, req.params.number, null, req.user, req.query.version);
res.json({});
} catch (err) {
next(err);
View
@@ -50,7 +50,7 @@ ALTER TABLE fahrer
CHANGE punkte marks INT,
CHANGE rang rank INT,
ADD COLUMN user_tag CHAR(16),
ADD COLUMN verified BOOLEAN DEFAULT 1;
ADD COLUMN verified BOOLEAN NOT NULL DEFAULT 1;
UPDATE riders
SET country = NULL
@@ -213,6 +213,7 @@ ALTER TABLE benutzer
CHANGE name email VARCHAR(60) NOT NULL,
ADD secret_expires TIMESTAMP NULL DEFAULT NULL AFTER password,
ADD secret CHAR(16) AFTER password,
ADD verified BOOLEAN NOT NULL DEFAULT 0 after secret_expires,
ADD user_tag CHAR(16) NOT NULL AFTER password,
CHANGE admin super_admin BOOLEAN NOT NULL DEFAULT '0',
ADD COLUMN admin BOOLEAN NOT NULL DEFAULT '0' after secret_expires,
View
@@ -324,7 +324,7 @@ CREATE TABLE `riders` (
`marks` int(11) DEFAULT NULL,
`rank` int(11) DEFAULT NULL,
`user_tag` char(16) DEFAULT NULL,
`verified` tinyint(1) DEFAULT '1',
`verified` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`,`number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -500,6 +500,7 @@ CREATE TABLE `users` (
`user_tag` char(16) NOT NULL,
`secret` char(16) DEFAULT NULL,
`secret_expires` timestamp NULL DEFAULT NULL,
`verified` tinyint(1) NOT NULL DEFAULT '0',
`admin` tinyint(1) NOT NULL DEFAULT '0',
`super_admin` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`user`),
@@ -568,4 +569,4 @@ CREATE TABLE `zones` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2017-04-11 15:48:21
-- Dump completed on 2017-04-12 2:07:02

0 comments on commit cdddbba

Please sign in to comment.