-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #203 from AltCamp/fix/feedback
improve: email verification & reset password
- Loading branch information
Showing
13 changed files
with
2,973 additions
and
2,755 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,30 @@ | ||
const { Token } = require('../../model'); | ||
const { BadRequestError } = require('../../utils/customError'); | ||
const { generate4DigitOTP } = require('../../utils/helper'); | ||
const redisClient = require('../common/cache/cacheService'); | ||
|
||
class TokenService { | ||
static async createToken({ type, owner, timeToLive }) { | ||
const otpCode = Math.floor(Math.random() * 9000) + 1000; | ||
const ttlMs = Date.now() + 60 * 1000 * timeToLive; | ||
const expiresAt = new Date(ttlMs); | ||
static async createToken({ requestId, type, owner, timeToLive }) { | ||
const otpCode = generate4DigitOTP(); | ||
|
||
const data = await Token.create({ token: otpCode, owner, type, expiresAt }); | ||
if (!data) | ||
try { | ||
await redisClient.set( | ||
`${type + requestId}`, | ||
JSON.stringify({ token: otpCode, owner }), | ||
{ EX: timeToLive } | ||
); | ||
return otpCode; | ||
} catch (error) { | ||
throw new BadRequestError('An error occurred while creating token!'); | ||
return data; | ||
} | ||
} | ||
|
||
static async getToken(where) { | ||
return await Token.findOne(where); | ||
const token = await redisClient.get(where); | ||
return token ? JSON.parse(token) : token; | ||
} | ||
|
||
static async deleteToken(_id) { | ||
return await Token.deleteOne(_id); | ||
return await redisClient.del(_id); | ||
} | ||
} | ||
module.exports = TokenService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters