Permalink
Browse files

Rename column users.tag to users.user_tag

  • Loading branch information...
andreas-gruenbacher committed Apr 10, 2017
1 parent 48e5f9c commit febe6bca2637ab4ea03c22f7f16a739001c8b8f5
Showing with 24 additions and 24 deletions.
  1. +14 −14 backend/index.js
  2. +4 −4 convert-db.sql
  3. +2 −2 create-db.sql
  4. +4 −4 create-users
View
@@ -138,7 +138,7 @@ async function validate_user(connection, user) {
throw 'Wrong email or password';
var rows = await connection.queryAsync(`
SELECT email, password, tag, admin
SELECT email, password, user_tag, admin
FROM users
WHERE email = ? AND password IS NOT NULL`, [user.email]);
@@ -2197,13 +2197,13 @@ function register_filter_rider(rider) {
return result;
}
async function register_get_riders(connection, id, tag) {
async function register_get_riders(connection, id, user_tag) {
var rows = await connection.queryAsync(`
SELECT number
FROM riders
WHERE id = ? AND user_tag = ? AND NOT COALESCE(`+'`group`'+`, 0)
ORDER BY last_name, first_name, date_of_birth, number`,
[id, tag]);
[id, user_tag]);
var riders = [];
for (let row of rows) {
@@ -2228,7 +2228,7 @@ async function create_user_secret(connection, email, create_user) {
if (create_user) {
try {
await connection.queryAsync(`
INSERT INTO users (user, email, tag, secret, secret_expires)
INSERT INTO users (user, email, user_tag, secret, secret_expires)
SELECT COALESCE(MAX(user), 0) + 1 AS user, ?, ?, ?, ?
FROM users
`, [email, random_tag(), secret, expires]);
@@ -2608,14 +2608,14 @@ async function change_password(req, res, next) {
}
}
async function register_save_rider(connection, id, number, rider, tag, version) {
async function register_save_rider(connection, id, number, rider, user_tag, 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 != tag)
if (old_rider.user_tag != user_tag)
throw new HTTPError(403, 'Forbidden');
} else {
var result = await connection.queryAsync(`
@@ -2655,7 +2655,7 @@ async function register_save_rider(connection, id, number, rider, tag, version)
delete rider.rankings;
delete rider.registered;
rider.verified = false;
rider.user_tag = tag;
rider.user_tag = user_tag;
event = cache.modify_event(id);
if (!event.features.verified)
@@ -3277,7 +3277,7 @@ app.get('/api/register/event/:id', auth, function(req, res, next) {
});
app.get('/api/register/event/:id/riders', function(req, res, next) {
register_get_riders(req.conn, req.params.id, req.user.tag)
register_get_riders(req.conn, req.params.id, req.user.user_tag)
.then((result) => {
res.json(result);
}).catch(next);
@@ -3293,7 +3293,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.tag);
rider = await register_save_rider(req.conn, req.params.id, null, rider, req.user.user_tag);
res.status(201);
res.json(rider);
} catch (err) {
@@ -3304,7 +3304,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.tag);
rider = await register_save_rider(req.conn, req.params.id, req.params.number, rider, req.user.user_tag);
res.json(rider);
} catch (err) {
next(err);
@@ -3313,7 +3313,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.tag, req.query.version);
await register_save_rider(req.conn, req.params.id, req.params.number, null, req.user.user_tag, req.query.version);
res.json({});
} catch (err) {
next(err);
@@ -3434,7 +3434,7 @@ app.get('/api/event/:id/find-riders', will_read_event, function(req, res, next)
app.post('/api/event/:id/rider', will_write_event, async function(req, res, next) {
var rider = req.body;
try {
rider = await admin_save_rider(req.conn, req.params.id, null, rider, req.user.tag);
rider = await admin_save_rider(req.conn, req.params.id, null, rider, req.user.user_tag);
res.status(201);
res.json(rider);
} catch (err) {
@@ -3452,7 +3452,7 @@ app.post('/api/event/:id/reset', will_write_event, async function(req, res, next
app.put('/api/event/:id/rider/:number', will_write_event, async function(req, res, next) {
var rider = req.body;
try {
rider = await admin_save_rider(req.conn, req.params.id, req.params.number, rider, req.user.tag);
rider = await admin_save_rider(req.conn, req.params.id, req.params.number, rider, req.user.user_tag);
res.json(rider);
} catch (err) {
next(err);
@@ -3461,7 +3461,7 @@ app.put('/api/event/:id/rider/:number', will_write_event, async function(req, re
app.delete('/api/event/:id/rider/:number', will_write_event, async function(req, res, next) {
try {
await admin_save_rider(req.conn, req.params.id, req.params.number, null, req.user.tag, req.query.version);
await admin_save_rider(req.conn, req.params.id, req.params.number, null, req.user.user_tag, req.query.version);
res.json({});
} catch (err) {
next(err);
View
@@ -213,7 +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 tag CHAR(16) NOT NULL AFTER password,
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,
CHANGE password password VARCHAR(40) NULL;
@@ -225,9 +225,9 @@ UPDATE users
CREATE UNIQUE INDEX email ON users (email);
UPDATE users
SET tag = SUBSTRING(TO_BASE64(SHA1(RAND())), 1, 16)
WHERE tag IS NULL OR tag = '';
CREATE UNIQUE INDEX tag ON users (tag);
SET user_tag = REPLACE(REPLACE(SUBSTRING(TO_BASE64(SHA1(RAND())), 1, 16), '/', '_'), '+', '-')
WHERE user_tag IS NULL OR user_tag = '';
CREATE UNIQUE INDEX user_tag ON users (user_tag);
DROP TABLE IF EXISTS groups;
ALTER TABLE gruppe
View
@@ -497,14 +497,14 @@ CREATE TABLE `users` (
`user` int(11) NOT NULL,
`email` varchar(60) NOT NULL,
`password` varchar(40) DEFAULT NULL,
`tag` char(16) NOT NULL,
`user_tag` char(16) NOT NULL,
`secret` char(16) DEFAULT NULL,
`secret_expires` timestamp NULL DEFAULT NULL,
`admin` tinyint(1) NOT NULL DEFAULT '0',
`super_admin` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`user`),
UNIQUE KEY `email` (`email`),
UNIQUE KEY `tag` (`tag`)
UNIQUE KEY `user_tag` (`user_tag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
View
@@ -25,14 +25,14 @@ user=$(
' | $DB -N)
for email in $emails; do
tag=$(random_tag)
user_tag=$(random_tag)
echo -n "
INSERT INTO users (user, email, tag)
VALUES ($user, '$email', '$tag');
INSERT INTO users (user, email, user_tag)
VALUES ($user, '$email', '$user_tag');
"
echo -n "
UPDATE riders
SET user_tag = '$tag'
SET user_tag = '$user_tag'
WHERE email = '$email';
"
((user++))

0 comments on commit febe6bc

Please sign in to comment.