Skip to content

Commit

Permalink
feat(create_user): add create event for security
Browse files Browse the repository at this point in the history
  • Loading branch information
Franco Méndez committed Oct 28, 2019
1 parent eff4b16 commit 1681c2d
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions create_user.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const aws = require('aws-sdk');
const uuidv4 = require('uuid/v4');
const moment = require('moment');
const bcrypt = require('bcryptjs');
const moment = require('moment');
const uuidv4 = require('uuid/v4');

const UsersTableName = process.env.dynamodb_users_table_name;
const UsersIndexName = process.env.dynamodb_users_index_name;
const EventsTableName = process.env.dynamodb_events_table_name;
const ImagesTableName = process.env.dynamodb_images_table_name;
const ImagesBaseUrl = process.env.salgode_images_bucket_base_url;
const UsersTableName = process.env.dynamodb_users_table_name;
const UsersIndexName = process.env.dynamodb_users_index_name;

const dynamoDB = new aws.DynamoDB.DocumentClient();

Expand All @@ -15,6 +16,24 @@ function hashPassword(userPassword) {
return bcrypt.hashSync(userPassword, Salt);
}

async function createEvent(userId, resourceId, resource, action, data) {
const eventId = `evt_${uuidv4()}`;
const timestamp = moment().format('YYYY-MM-DDTHH:mm:ss-04:00');
const params = {
TableName: EventsTableName,
Item: {
event_id: eventId,
user_id: userId,
resource_id: resourceId,
resource,
action,
event_data: data,
created_at: timestamp
}
};
await dynamoDB.put(params).promise();
}

async function checkEmail(userEmail) {
const params = {
TableName: UsersTableName,
Expand Down Expand Up @@ -123,6 +142,7 @@ exports.handler = async (event) => {
identificationImages,
createdAt
);
await createEvent(userId, userId, 'user', 'create', body);
const selfieUrl = identificationImages.selfie_image
? await getImageUrl(identificationImages.selfie_image)
: null;
Expand Down

0 comments on commit 1681c2d

Please sign in to comment.