|
|
@@ -8,13 +8,13 @@ const SecurePassword = require('secure-password')
|
|
8
|
8
|
|
|
9
|
9
|
// Configuration for Brevo
|
|
10
|
10
|
const SibApiV3Sdk = require('sib-api-v3-sdk')
|
|
11
|
|
-const { access, accessSync } = require('fs')
|
|
12
|
11
|
const defaultClient = SibApiV3Sdk.ApiClient.instance
|
|
13
|
12
|
const apiKey = defaultClient.authentications['api-key']
|
|
14
|
13
|
apiKey.apiKey = process.env.BREVO_KEY
|
|
15
|
|
-
|
|
16
|
14
|
const apiInstance = new SibApiV3Sdk.TransactionalEmailsApi()
|
|
17
|
15
|
|
|
|
16
|
+// TODO: Consider implementing, nice use of SecurePassword,
|
|
|
17
|
+// but currently not used anywhere...
|
|
18
|
18
|
const hasher = async (pwd, steak) => {
|
|
19
|
19
|
const hash = await pwd.hash(steak)
|
|
20
|
20
|
const result = await pwd.verify(steak, hash)
|
|
|
@@ -57,24 +57,7 @@ module.exports = class UserService extends Schmervice.Service {
|
|
57
|
57
|
const pwd = new SecurePassword()
|
|
58
|
58
|
// TODO: Invalidate this application state somehow after a
|
|
59
|
59
|
// certain time period has passed
|
|
60
|
|
- this.activeSessions = {
|
|
61
|
|
- // abc123456: '123456689',
|
|
62
|
|
- // eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...hashedSessionToken: {
|
|
63
|
|
- // email: rawEmailString,
|
|
64
|
|
- // name: 'Joe Doe',
|
|
65
|
|
- // seeking: 'candidate'
|
|
66
|
|
- // sessionToken: rawSessionToken, // use for expires instead of expires?
|
|
67
|
|
- // expires: expirationTime in seconds
|
|
68
|
|
- // }
|
|
69
|
|
- }
|
|
70
|
|
- // Check the hashedCookie which is our hashedSessionToken string
|
|
71
|
|
- // validate whether or not the rawAccessToken is still valid, if valid good to go.
|
|
72
|
|
- // if NOT valid, then we need to reassign accessToken to a newAccessToken
|
|
73
|
|
- // this.activeSessions = {
|
|
74
|
|
- // eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...hashedSessionToken: {
|
|
75
|
|
- // accessToken: 'as;dflkja;;dlfkja;sldkf... rawAccessToken'
|
|
76
|
|
- // }
|
|
77
|
|
- // }
|
|
|
60
|
+ this.activeSessions = {}
|
|
78
|
61
|
|
|
79
|
62
|
this.pwd = {
|
|
80
|
63
|
hash: Util.promisify(pwd.hash.bind(pwd)),
|
|
|
@@ -334,9 +317,7 @@ module.exports = class UserService extends Schmervice.Service {
|
|
334
|
317
|
* @ returns {Object}
|
|
335
|
318
|
*/
|
|
336
|
319
|
async emailSent(userCredentials) {
|
|
337
|
|
- const hashedSessionToken = await this.hashToken(
|
|
338
|
|
- userCredentials.sessionToken,
|
|
339
|
|
- )
|
|
|
320
|
+ const hashedSessionToken = this.hashToken(userCredentials.sessionToken)
|
|
340
|
321
|
if (Object.keys(this.activeSessions).includes(hashedSessionToken)) {
|
|
341
|
322
|
return new Error('session already in cache!!')
|
|
342
|
323
|
}
|