aloux-iam 0.0.87 → 0.0.89

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.
@@ -744,3 +744,31 @@ self.verifyMailTokenAccount = async (req, res) => {
744
744
  }
745
745
  }
746
746
 
747
+ self.addTimeToken = async (req, res) => {
748
+ try {
749
+ const userTokens = await User.findOne(
750
+ { "tokens.token": req.params.TOKEN, status: "Activo" },
751
+ { tokens: 1 }
752
+ );
753
+
754
+ if (userTokens) {
755
+ const tokenObject = userTokens.tokens.find(t => t.token === req.params.TOKEN);
756
+
757
+ if (tokenObject) {
758
+ tokenObject.dateEnd = Date.now() + process.env.SESSION_TIME * 60 * 1000;
759
+ // Guarda los cambios en la base de datos
760
+ await User.updateOne(
761
+ { _id: userTokens._id, "tokens.token": req.params.TOKEN },
762
+ { $set: { "tokens.$.dateEnd": tokenObject.dateEnd } }
763
+ );
764
+ } else {
765
+ throw new Error("Token no encontrado");
766
+ }
767
+ } else {
768
+ throw new Error("Usuario no encontrado o inactivo");
769
+ }
770
+ res.status(200).send('Usuario verificado con éxito')
771
+ } catch (error) {
772
+ res.status(400).send({ error: error.message })
773
+ }
774
+ }
@@ -85,7 +85,8 @@ adminSchema.methods.generateAuthToken = async function () {
85
85
 
86
86
  const token = jwt.sign({ _id: user._id }, process.env.AUTH_SECRET)
87
87
  const currentDate = (new Date()).getTime()
88
- user.tokens = user.tokens.concat({ token, date: currentDate })
88
+ const dateEnd = currentDate + process.env.SESSION_TIME * 60 * 1000;
89
+ user.tokens = user.tokens.concat({ token, date: currentDate, dateEnd })
89
90
 
90
91
  await user.save()
91
92
 
@@ -98,31 +98,3 @@ self.updatepassword = async (body, USER_ID) => {
98
98
  return result
99
99
  }
100
100
 
101
- self.addTimeToken = async (req, res) => {
102
- try {
103
- const userTokens = await User.findOne(
104
- { "tokens.token": req.params.TOKEN, status: "Activo" },
105
- { tokens: 1 }
106
- );
107
-
108
- if (userTokens) {
109
- const tokenObject = userTokens.tokens.find(t => t.token === req.params.TOKEN);
110
-
111
- if (tokenObject) {
112
- tokenObject.dateEnd = Date.now() + process.env.SESSION_TIME * 60 * 1000;
113
- // Guarda los cambios en la base de datos
114
- await User.updateOne(
115
- { _id: userTokens._id, "tokens.token": req.params.TOKEN },
116
- { $set: { "tokens.$.dateEnd": tokenObject.dateEnd } }
117
- );
118
- } else {
119
- throw new Error("Token no encontrado");
120
- }
121
- } else {
122
- throw new Error("Usuario no encontrado o inactivo");
123
- }
124
- res.status(200).send('Usuario verificado con éxito')
125
- } catch (error) {
126
- res.status(400).send({ error: error.message })
127
- }
128
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aloux-iam",
3
- "version": "0.0.87",
3
+ "version": "0.0.89",
4
4
  "description": "Aloux IAM for APIs ",
5
5
  "main": "index.js",
6
6
  "scripts": {