Skip to content

Commit

Permalink
Fix signin bug that creates an entirely new user
Browse files Browse the repository at this point in the history
  • Loading branch information
austencollins committed Aug 6, 2015
1 parent b9dbf6e commit becb4fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion api/users/show/event.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"body": {},
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiJ1X2RmNzVmNWUwLTNiZDktMTFlNS1iZTk4LWI5NjFjMzVmOWZjNyIsImlhdCI6MTQzODgyNDI5OCwiZXhwIjoxNDM5NDI5MDk4LCJpc3MiOiJKQVdTIn0.G2Ugcds7Q6gQ5arP_fp-rbn4-xg1QQ3-OrdJO9iAdDo"
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiJ1X2FkN2Y5MGMwLTNiZWItMTFlNS05MDVjLWUzNzViNDljNDhkMiIsImlhdCI6MTQzODgzMTk3NSwiZXhwIjoxNDM5NDM2Nzc1LCJpc3MiOiJKQVdTIn0.FlISdHxUrFdrDkovrq_RRwxHqlzaSL3GShr27xlvcB0"
}
18 changes: 12 additions & 6 deletions lib/models/model_user.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ User.prototype.signIn = function(data, callback) {
// Update User
user.sign_in_count++;

console.log(user);


/**
* Save
Expand Down Expand Up @@ -319,6 +319,8 @@ User.prototype.save = function(user, callback) {
message: 'Bad Request: Password is required'
}, null);

console.log(user);


/**
* Perform Save
Expand All @@ -328,8 +330,7 @@ User.prototype.save = function(user, callback) {
TableName: dynamodb_table,
ReturnValues: 'ALL_NEW',
Key: {
'_id': user._id,
'created': moment().unix()
'_id': user._id
},
UpdateExpression: 'SET ',
ExpressionAttributeNames: {},
Expand Down Expand Up @@ -366,13 +367,18 @@ User.prototype.save = function(user, callback) {
params.ExpressionAttributeNames['#a4'] = 'sign_in_count';
params.ExpressionAttributeValues[':sign_in_count_val'] = user.sign_in_count;

// created
if (isNaN(user.created)) user.created = moment(user.created).unix();
params.UpdateExpression = params.UpdateExpression + '#b0 = :created_val, ';
params.ExpressionAttributeNames['#b0'] = 'created';
params.ExpressionAttributeValues[':created_val'] = user.created;

// updated
params.UpdateExpression = params.UpdateExpression + '#b0 = :updated_val, ';
params.ExpressionAttributeNames['#b0'] = 'updated';
params.UpdateExpression = params.UpdateExpression + '#b1 = :updated_val, ';
params.ExpressionAttributeNames['#b1'] = 'updated';
params.ExpressionAttributeValues[':updated_val'] = moment().unix();



/**
* Save
*/
Expand Down

0 comments on commit becb4fa

Please sign in to comment.