- User Profile

- DashBoard start
This commit is contained in:
Paolo Arena
2019-12-29 23:30:49 +01:00
parent 8fd04d3b1c
commit c39a14bb9e
5 changed files with 43 additions and 6 deletions

View File

@@ -31,9 +31,9 @@ function existSubScribe(userId, access, browser) {
}
// POST /users
router.post('/', (req, res) => {
router.post('/', async (req, res) => {
tools.mylog("POST /users");
const body = _.pick(req.body, ['email', 'password', 'username', 'name', 'surname', 'idapp', 'keyappid', 'lang']);
const body = _.pick(req.body, ['email', 'password', 'username', 'name', 'surname', 'idapp', 'keyappid', 'lang', 'profile']);
const user = new User(body);
// tools.mylog("LANG PASSATO = " + user.lang, "IDAPP", user.idapp);
@@ -47,6 +47,32 @@ router.post('/', (req, res) => {
user.verified_email = true;
}
let exit;
// Check if already esist email or username
exit = await User.findByUsername(user.idapp, user.username).then((useralreadyexist) => {
if (useralreadyexist) {
res.status(400).send({ code: server_constants.RIS_CODE_USERNAME_ALREADY_EXIST, msg: '' });
return 1;
}
});
if (exit === 1)
return;
exit = await User.findByEmail(user.idapp, user.email)
.then((useralreadyexist) => {
if (useralreadyexist) {
res.status(400).send({ code: server_constants.RIS_CODE_EMAIL_ALREADY_EXIST, msg: '' });
return 1;
}
});
if (exit === 1)
return;
user.save().then(() => {
User.findByUsername(user.idapp, user.username)
.then((usertrovato) => {
@@ -55,7 +81,7 @@ router.post('/', (req, res) => {
if (usertrovato !== null) {
return user.generateAuthToken(req);
} else {
res.status(11100).send();
res.status(400).send();
return 0;
}
}).then((token) => {
@@ -76,7 +102,7 @@ router.post('/', (req, res) => {
})
});
router.get('/:username/:idapp', (req, res) => {
router.get('/:idapp/:username', (req, res) => {
var username = req.params.username;
const idapp = req.params.idapp;