Skip to content

Commit

Permalink
fix: add check if user is already created for /user/add endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
yaroslav-fedyshyn-nordwhale committed Oct 31, 2019
1 parent d661214 commit 41f1148
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/server/db/mongo/models/user-private.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export const UserPrivateSchema = new mongoose.Schema({
},
emailVerificationCode: {
type: String
},
createdDate: {
type: Date
}
})

Expand Down
2 changes: 1 addition & 1 deletion src/server/storage/__tests__/storageAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('storageAPI', () => {
await UserDBPrivate.updateUser({ identifier: '0x7ac080f6607405705aed79675789701a48c76f55', mauticId: mauticId })
const user: UserRecord = {
identifier: '0x7ac080f6607405705aed79675789701a48c76f55',
email: 'useraddtest1@gooddollar.org' // required for mautic create contact
email: 'useraddtest@gooddollar.org' // required for mautic create contact
}
let res = await request(server)
.post('/user/add')
Expand Down
8 changes: 6 additions & 2 deletions src/server/storage/storageAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ const setup = (app: Router, storage: StorageAPI) => {
)
throw new Error('User email or mobile not verified!')

if (!conf.allowDuplicateUserData && userRecord.createdDate) {
throw new Error('You cannot create more than 1 account with the same credentials')
}

const { email, mobile, ...bodyUser } = body.user

const user: UserRecord = defaults(bodyUser, {
identifier: userRecord.loggedInAs,
createdDate: new Date().toString(),
email: get('userRecord', 'otp.email', email), //for development/test use email from body
mobile: get('userRecord', 'otp.mobile', mobile) //for development/test use mobile from body
email: get(userRecord, 'otp.email', email), //for development/test use email from body
mobile: get(userRecord, 'otp.mobile', mobile) //for development/test use mobile from body
})

if (conf.disableFaceVerification) {
Expand Down

0 comments on commit 41f1148

Please sign in to comment.