- User Profile
- DashBoard start
This commit is contained in:
@@ -115,6 +115,15 @@ var UserSchema = new mongoose.Schema({
|
||||
img: {
|
||||
type: String
|
||||
},
|
||||
nationality: {
|
||||
type: String
|
||||
},
|
||||
intcode_cell: {
|
||||
type: String
|
||||
},
|
||||
iso2_cell: {
|
||||
type: String
|
||||
},
|
||||
cell: {
|
||||
type: String
|
||||
},
|
||||
|
||||
@@ -3,7 +3,7 @@ const router = express.Router();
|
||||
|
||||
var {User} = require('../models/user');
|
||||
|
||||
router.get('/:email/:idapp', (req, res) => {
|
||||
router.get('/:idapp/:email', (req, res) => {
|
||||
var email = req.params.email;
|
||||
const idapp = req.params.idapp;
|
||||
|
||||
|
||||
@@ -247,7 +247,7 @@ router.patch('/chval', authenticate, (req, res) => {
|
||||
tools.mylogshow('PATCH CHVAL: ', id, fieldsvalue);
|
||||
|
||||
// If I change my record...
|
||||
if ((!User.isAdmin(req.user) && !User.isManager(req.user)) || (req.user._id === id)) {
|
||||
if ((!User.isAdmin(req.user) && !User.isManager(req.user)) && !(req.user._id.toString() === id)) {
|
||||
// If without permissions, exit
|
||||
return res.status(404).send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' });
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ module.exports = Object.freeze({
|
||||
RIS_CODE_EMAIL_ALREADY_VERIFIED: -5,
|
||||
RIS_CODE_EMAIL_VERIFIED: 1,
|
||||
|
||||
RIS_CODE_USERNAME_ALREADY_EXIST: -60,
|
||||
RIS_CODE_EMAIL_ALREADY_EXIST: -50,
|
||||
RIS_CODE_EMAIL_NOT_SENT: -40,
|
||||
RIS_CODE_ERR_UNAUTHORIZED: -30,
|
||||
RIS_CODE_LOGIN_ERR_GENERIC: -20,
|
||||
|
||||
Reference in New Issue
Block a user