aloux-iam 0.0.26 → 0.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/lib/services/auth.js +56 -55
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -55,6 +55,7 @@ Requiere las siguientes variables de entorno (.env)
|
|
|
55
55
|
| AWS_BUCKET | Required, para guardar la foto de perfil en AWS. |
|
|
56
56
|
| AWS_EMAIL_SENDER | Required, para mandar el correo de recuperación de contraseña |
|
|
57
57
|
| DEBUG | Required, para validar si el ambiente es dev o PROD |
|
|
58
|
+
| SWAGGER_SERVER | Required, para acceder al swagger de IAM |
|
|
58
59
|
| MASTER_PWD | Optional, para utilizar contraseña maestra de usuarios en desarrollo |
|
|
59
60
|
| BASE_URL | Optional, para swagger |
|
|
60
61
|
|
package/lib/services/auth.js
CHANGED
|
@@ -110,44 +110,44 @@ self.getMenu = (user) => {
|
|
|
110
110
|
for (let i in user._functions) {
|
|
111
111
|
if (user._functions[i].status === 'Activo') {
|
|
112
112
|
for (let j in user._functions[i]._menus) {
|
|
113
|
-
if (user._functions[i]._menus[j].status === 'Activo'){
|
|
113
|
+
if (user._functions[i]._menus[j].status === 'Activo') {
|
|
114
114
|
user._functions[i]._menus[j].submenus = []
|
|
115
115
|
result.push(user._functions[i]._menus[j])
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
|
|
121
|
-
let result2 = result.filter((item,index)=>{
|
|
120
|
+
|
|
121
|
+
let result2 = result.filter((item, index) => {
|
|
122
122
|
return result.indexOf(item) === index;
|
|
123
|
-
|
|
123
|
+
})
|
|
124
124
|
|
|
125
125
|
// Ordena elementos de menú
|
|
126
126
|
result2.sort(function (a, b) {
|
|
127
127
|
if (a.index > b.index) {
|
|
128
128
|
return 1;
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
}
|
|
130
|
+
if (a.index < b.index) {
|
|
131
131
|
return -1;
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
}
|
|
133
|
+
return 0;
|
|
134
134
|
})
|
|
135
135
|
|
|
136
136
|
let menus = []
|
|
137
137
|
let submenus = []
|
|
138
|
-
for(let i in result2){
|
|
139
|
-
if(!result2[i]._menu){
|
|
138
|
+
for (let i in result2) {
|
|
139
|
+
if (!result2[i]._menu) {
|
|
140
140
|
result2[i]._menu = []
|
|
141
141
|
menus.push(result2[i])
|
|
142
|
-
}else{
|
|
142
|
+
} else {
|
|
143
143
|
submenus.push(result2[i])
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
for(let i in submenus){
|
|
148
|
-
for(let j in menus){
|
|
147
|
+
for (let i in submenus) {
|
|
148
|
+
for (let j in menus) {
|
|
149
149
|
|
|
150
|
-
if(String(submenus[i]._menu._id) === String(menus[j]._id)){
|
|
150
|
+
if (String(submenus[i]._menu._id) === String(menus[j]._id)) {
|
|
151
151
|
menus[j].submenus.push(submenus[i])
|
|
152
152
|
}
|
|
153
153
|
}
|
|
@@ -167,12 +167,12 @@ self.me = async (req, res) => {
|
|
|
167
167
|
|
|
168
168
|
// Valida que los modelos existan hantes de hacer una consulta con populate
|
|
169
169
|
if (mongoose.modelNames().includes('Business') && mongoose.modelNames().includes('Client')) {
|
|
170
|
-
user = await User.findOne({ _id }).populate([{ path: "_functions", populate: [{ path: "_permissions" }, { path: "_menus" }] },{ path: "_business" }, { path: "_client" }]).select("-pwd -tokens").lean()
|
|
171
|
-
}else if(mongoose.modelNames().includes('Business')){
|
|
172
|
-
user = await User.findOne({ _id }).populate([{ path: "_functions", populate: [{ path: "_permissions" }, { path: "_menus" }] },{ path: "_business" }]).select("-pwd -tokens").lean()
|
|
173
|
-
}else if(mongoose.modelNames().includes('Client')){
|
|
170
|
+
user = await User.findOne({ _id }).populate([{ path: "_functions", populate: [{ path: "_permissions" }, { path: "_menus" }] }, { path: "_business" }, { path: "_client" }]).select("-pwd -tokens").lean()
|
|
171
|
+
} else if (mongoose.modelNames().includes('Business')) {
|
|
172
|
+
user = await User.findOne({ _id }).populate([{ path: "_functions", populate: [{ path: "_permissions" }, { path: "_menus" }] }, { path: "_business" }]).select("-pwd -tokens").lean()
|
|
173
|
+
} else if (mongoose.modelNames().includes('Client')) {
|
|
174
174
|
user = await User.findOne({ _id }).populate([{ path: "_functions", populate: [{ path: "_permissions" }, { path: "_menus" }] }, { path: "_client" }]).select("-pwd -tokens").lean()
|
|
175
|
-
} else{
|
|
175
|
+
} else {
|
|
176
176
|
user = await User.findOne({ _id }).populate([{ path: "_functions", populate: [{ path: "_permissions" }, { path: "_menus" }] }]).select("-pwd -tokens").lean()
|
|
177
177
|
}
|
|
178
178
|
|
|
@@ -404,10 +404,11 @@ self.verifyMailTokenAccount = async (req, res) => {
|
|
|
404
404
|
} else {
|
|
405
405
|
user.validateKey.validateEmail.verifyMailToken = null
|
|
406
406
|
user.validateKey.validateEmail.emailVerified = true
|
|
407
|
-
user.
|
|
407
|
+
user.tokens.push({ token: token })
|
|
408
|
+
await user.save()
|
|
408
409
|
}
|
|
409
410
|
|
|
410
|
-
if (user.validateKey.validateEmail.emailVerified
|
|
411
|
+
if (user.validateKey.validateEmail.emailVerified === true) {
|
|
411
412
|
await self.sendValidateEmail(user.email)
|
|
412
413
|
}
|
|
413
414
|
|
|
@@ -430,51 +431,51 @@ self.updatePicture = async (req, res) => {
|
|
|
430
431
|
|
|
431
432
|
self.verifyPhone = async (req, res) => {
|
|
432
433
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
434
|
+
const user = await User.findOne({ phone: req.user.phone })
|
|
435
|
+
if (!user) {
|
|
436
|
+
throw { code: 409, title: 'Usuario no encontrado.', detail: '', suggestion: 'Verifica que el usuario exista', error: new Error() }
|
|
437
|
+
}
|
|
437
438
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
439
|
+
const code = await self.generatecode()
|
|
440
|
+
const Message = "Tu código de " + process.env.PROJECT_NAME + " es: " + code + ". No lo compartas con nadie. " + process.env.PROJECT_URL
|
|
441
|
+
await User.updateOne({ _id: user._id }, { 'validateKey.validatePhone.codeVerifyPhone': code, 'validateKey.validatePhone.validCodePhone': false })
|
|
442
|
+
await sns.sendMessagePhone(req.user.phone, Message)
|
|
442
443
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
444
|
+
user.validateKey.validatePhone.codeVerifyPhone = code
|
|
445
|
+
let time = new Date()
|
|
446
|
+
const sumarMinutos = new Date(time.getTime() + 10 * 60000)
|
|
447
|
+
user.limitCodeTime = (new Date(sumarMinutos)).getTime()
|
|
448
|
+
await user.save()
|
|
448
449
|
|
|
449
|
-
|
|
450
|
+
return true
|
|
450
451
|
}
|
|
451
452
|
|
|
452
453
|
self.validatePhone = async (req, res) => {
|
|
453
|
-
|
|
454
|
-
let body = JSON.parse(JSON.stringify(req.body))
|
|
455
|
-
const user = await User.findOne({ phone: req.user.phone })
|
|
456
|
-
const newTime = new Date().getTime()
|
|
457
454
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
455
|
+
let body = JSON.parse(JSON.stringify(req.body))
|
|
456
|
+
const user = await User.findOne({ phone: req.user.phone })
|
|
457
|
+
const newTime = new Date().getTime()
|
|
461
458
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
459
|
+
if (!user) {
|
|
460
|
+
throw { code: 409, title: 'Usuario no encontrado.', detail: '', suggestion: 'Verifica que el usuario exista', error: new Error() }
|
|
461
|
+
}
|
|
465
462
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
user.validateKey.validatePhone.validCodePhone = true
|
|
463
|
+
if (user.limitCodeTime < newTime) {
|
|
464
|
+
throw { code: 409, title: 'El código ha caducado.', detail: '', suggestion: 'Verifica que el código sea correcto', error: new Error() }
|
|
465
|
+
}
|
|
470
466
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
467
|
+
if (user.validateKey.validatePhone.codeVerifyPhone == body.codeVerifyPhone) {
|
|
468
|
+
user.validateKey.validatePhone.codeVerifyPhone = null
|
|
469
|
+
user.limitCodeTime = null
|
|
470
|
+
user.validateKey.validatePhone.validCodePhone = true
|
|
471
|
+
|
|
472
|
+
await user.save()
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
throw { code: 409, title: 'Código incorrecto.', detail: '', suggestion: 'Verifica el código', error: new Error() }
|
|
476
|
+
}
|
|
476
477
|
|
|
477
|
-
|
|
478
|
+
return "Teléfono Verificado"
|
|
478
479
|
}
|
|
479
480
|
|
|
480
481
|
self.createCustomer = async (req, res) => {
|