aboutsummaryrefslogtreecommitdiffstats
path: root/users.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-01-27 23:16:22 -0800
committerAdam Soltys <[email protected]>2020-01-27 23:16:22 -0800
commite34f41697eb4b96508dc27197b91ef06bd47a641 (patch)
treebdc18dc5253f99c74e70e1460745f4b3bb778b4b /users.js
parent5eb6950c8f6dfea83c230c403c51c64234f23e3d (diff)
downloadcoinos-server-e34f41697eb4b96508dc27197b91ef06bd47a641.tar.gz
coinos-server-e34f41697eb4b96508dc27197b91ef06bd47a641.zip
test existence on username change
Diffstat (limited to 'users.js')
-rw-r--r--users.js15
1 files changed, 14 insertions, 1 deletions
diff --git a/users.js b/users.js
index 498bc33b..d797b2f8 100644
--- a/users.js
+++ b/users.js
@@ -104,6 +104,7 @@ module.exports = (addresses, auth, app, bc, db, emit) => {
app.post("/user", auth, async (req, res) => {
let { user } = req;
let {
+ username,
currency,
email,
phone,
@@ -125,6 +126,18 @@ module.exports = (addresses, auth, app, bc, db, emit) => {
requestPhone(user);
}
+ let exists = await db.User.findOne({
+ where: {
+ username
+ }
+ });
+
+ if (username !== user.username && exists) {
+ res.status(500).send("username taken");
+ } else {
+ user.username = username;
+ }
+
user.currency = currency;
user.email = email;
user.phone = phone;
@@ -145,7 +158,7 @@ module.exports = (addresses, auth, app, bc, db, emit) => {
}
await user.save();
- emit(req.user.username, "user", req.user);
+ emit(user.username, "user", req.user);
res.send(user);
});