Skip to content

Commit 4312113

Browse files
authored
fix: edited generate password, send invite mail (#407)
1 parent 616d76e commit 4312113

5 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ module.exports = exports = {
8989

9090
// invitations constants
9191
INVITATIONS_INDEX: 'user-invitations',
92+
ORGANIZATIONS_INVITATIONS_INDEX: 'organization-invitations',
9293

9394
// token
9495
TOKEN_METADATA_FIELD_METADATA: '1',

src/utils/organization/addOrganizationMembers.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ async function addOrganizationMembers(opts) {
3636
}
3737
});
3838
await Promise.all(filterMembersJob);
39-
4039
const createdMembers = await registerOrganizationMembers.call(this, notRegisteredMembers);
4140

4241
const pipe = redis.pipeline();

src/utils/organization/registerOrganizationMembers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const {
1313
USERS_INDEX,
1414
USERS_ID_FIELD,
1515
} = require('../../constants.js');
16-
const hashPassword = require('../register/password/hash');
16+
const scrypt = require('../scrypt');
1717
const setMetadata = require('../updateMetadata');
1818

1919
async function registerOrganizationMember(member) {
@@ -29,7 +29,7 @@ async function registerOrganizationMember(member) {
2929
[USERS_ACTIVE_FLAG]: true,
3030
};
3131
const password = generatePassword(pwdReset.length, pwdReset.memorable);
32-
basicInfo[USERS_PASSWORD_FIELD] = await hashPassword.call(this, password);
32+
basicInfo[USERS_PASSWORD_FIELD] = await scrypt.hash(password);
3333

3434
const userDataKey = redisKey(userId, USERS_DATA);
3535
pipeline.hmset(userDataKey, basicInfo);

src/utils/organization/sendInviteMail.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const Promise = require('bluebird');
22
const generateEmail = require('../challenges/email/generate.js');
33
const {
4-
INVITATIONS_INDEX,
4+
ORGANIZATIONS_INVITATIONS_INDEX,
55
TOKEN_METADATA_FIELD_CONTEXT,
66
TOKEN_METADATA_FIELD_SENDED_AT,
77
} = require('../../constants.js');
@@ -24,5 +24,5 @@ module.exports = function sendInviteMail(params) {
2424
.then(token => Promise
2525
.bind(this, [email, action, { ...ctx, token }, { send: true }])
2626
.spread(generateEmail)
27-
.tap(() => redis.sadd(INVITATIONS_INDEX, email)));
27+
.tap(() => redis.sadd(ORGANIZATIONS_INVITATIONS_INDEX, email)));
2828
};

test/suites/organization/create.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const assert = require('assert');
44
const sinon = require('sinon');
55
const faker = require('faker');
66
const { createMembers, createOrganization } = require('../../helpers/organization');
7-
const hashPassword = require('../../../src/utils/register/password/hash');
7+
const scrypt = require('../../../src/utils/scrypt');
88
const registerOrganizationMembers = require('../../../src/utils/organization/registerOrganizationMembers');
99

1010
describe('#create organization', function registerSuite() {
@@ -26,7 +26,7 @@ describe('#create organization', function registerSuite() {
2626

2727
it('must be able to create organization and register user', async function test() {
2828
const sendInviteMailSpy = sinon.spy(registerOrganizationMembers, 'call');
29-
const generatePasswordSpy = sinon.spy(hashPassword, 'call');
29+
const generatePasswordSpy = sinon.spy(scrypt, 'hash');
3030

3131
const params = {
3232
name: faker.company.companyName(),
@@ -49,7 +49,7 @@ describe('#create organization', function registerSuite() {
4949
});
5050

5151
const [registeredMember] = await sendInviteMailSpy.returnValues[0];
52-
const registeredMemberPassword = generatePasswordSpy.firstCall.args[1];
52+
const registeredMemberPassword = generatePasswordSpy.firstCall.args[0];
5353
const loginParams = {
5454
username: registeredMember.email,
5555
password: registeredMemberPassword,

0 commit comments

Comments
 (0)