Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

resolevd

  • Loading branch information...
commit dce8c974eee26159876c1034aa3f6e890c78ac21 2 parents a7d0281 + b12050d
Lance Welsh authored
Showing with 131 additions and 84 deletions.
  1. +101 −79 api/user.js
  2. +27 −4 web/login.js
  3. +3 −1 web/server.js
180 api/user.js
View
@@ -1013,109 +1013,131 @@ exports.link = function (request, reply) {
if (err === null) {
- var survivingId = user._id ;
+ // now it's not the new guest id,
+ // but the next most recent
+ // tho it requires a redirect w new session/id
+ // var survivingId = user._id ;
console.log( 'querying users that match ' + user._id ) ;
Db.query('user', criteria, function (musers, err) {
console.log( 'got ' + musers.length + ' users to match ' + user._id ) ;
- for( var tmi = musers.length-1 ; tmi >= 0 ; tmi-- ) {
- console.log( ' ' + tmi + ': ' + musers[tmi]._id ) ;
- }
- // count backwards to be sure we don't get bit by array compression for( var mi = 0 ; mi < count ; mi++ )
- for( var mi = musers.length-1 ; mi >= 0 ; mi-- ) {
+ if( musers.length <= 1 ) { // only need to combine if multiple
+
+ // ? Stream.update({ object: 'profile', user: user._id }, request);
+ reply({ status: 'ok' });
+
+ } else {
+
+ var survivingId = null ;
+ // surviving id is more recent that's not this/guest one
+ // maybe we presume too much in order and perhaps should check creation date
+ for( var tmi = musers.length-1 ; tmi >= 0 ; tmi-- ) {
+ var tuser = musers[tmi] ;
+ console.log( ' tuser ' + tmi + ': ' + tuser._id + ' ' + survivingId ) ;
+ if( !survivingId && tuser._id !== user._id ) {
+ survivingId = tuser._id ;
+ // should/could break
+ }
+ }
+
+ // count backwards to be sure we don't get bit by array compression for( var mi = 0 ; mi < count ; mi++ )
+ for( var mi = musers.length-1 ; mi >= 0 ; mi-- ) {
- var duser = musers[mi] ;
+ var duser = musers[mi] ;
- console.log( 'processing ' + mi + ' user ' + duser._id + ' and comoparing to survivingId ' + survivingId ) ;
+ console.log( 'processing ' + mi + ' user ' + duser._id + ' and comoparing to survivingId ' + survivingId ) ;
- if( duser._id !== survivingId ) { // don't delete last one merged into
+ if( duser._id !== survivingId ) { // don't delete last one merged into
- // first, before deletes and updates, merge docs - may be many querys and updates
- // any other collections have embedded users besides projects?
+ // first, before deletes and updates, merge docs - may be many querys and updates
+ // any other collections have embedded users besides projects?
- // this works better than querying through projects for participant.id's and then using that project id in the updateCreiteria field
- // not sure what that second id arg does in updateCriteria as it seemed to only work on the first one
+ // this works better than querying through projects for participant.id's and then using that project id in the updateCreiteria field
+ // not sure what that second id arg does in updateCriteria as it seemed to only work on the first one
- var projectCriteria = { 'participants.id': duser._id };
- var projectChange = { $set: { 'participants.$.id': survivingId } };
- Db.updateCriteria('project', null, projectCriteria, projectChange, function (err) {
- if (err === null) {
- console.log( 'replaced participants id in project ' ) ;
- } else {
- console.log( 'error replacing participants id in project ' ) ;
- }
- });
-
- /* can't update an _id
- var projectSortCriteria = { '_id': duser._id };
- var projectSortChange = { $set: { '_id': survivingId } };
- Db.updateCriteria('project.sort', null, projectSortCriteria, projectSortChange, function (err) {
- if (err === null) {
- console.log( 'replaced participants id in project.sort ' ) ;
- } else {
- console.log( 'error replacing participants id in project.sort ' ) ;
- }
- });
- */
- Db.get('project' + '.sort', duser._id, function (item, err) {
-
- if (err === null) {
+ var projectCriteria = { 'participants.id': duser._id };
+ var projectChange = { $set: { 'participants.$.id': survivingId } };
+ Db.updateCriteria('project', null, projectCriteria, projectChange, function (err) {
+ if (err === null) {
+ console.log( 'replaced participants id in project ' ) ;
+ } else {
+ console.log( 'error replacing participants id in project ' ) ;
+ }
+ });
+
+ /* can't update an _id
+ var projectSortCriteria = { '_id': duser._id };
+ var projectSortChange = { $set: { '_id': survivingId } };
+ Db.updateCriteria('project.sort', null, projectSortCriteria, projectSortChange, function (err) {
+ if (err === null) {
+ console.log( 'replaced participants id in project.sort ' ) ;
+ } else {
+ console.log( 'error replacing participants id in project.sort ' ) ;
+ }
+ });
+ */
+ Db.get('project' + '.sort', duser._id, function (item, err) {
+
+ if (err === null) {
- if( item ) {
+ if( item ) {
- item._id = survivingId ;
- Db.insert( 'project' + '.sort', item, function (itemReturn, err) {
- if (err === null) {
- console.log( 'added new participants id in project.sort ' + item._id + ' ' + itemReturn._id ) ;
- } else {
- console.log( 'error adding new participants id in project.sort ' + item._id + ' ' + itemReturn._id ) ;
- }
- });
+ item._id = survivingId ;
+ Db.insert( 'project' + '.sort', item, function (itemReturn, err) {
+ if (err === null) {
+ console.log( 'added new participants id in project.sort ' + item._id + ' ' + itemReturn._id ) ;
+ } else {
+ console.log( 'error adding new participants id in project.sort ' + item._id + ' ' + itemReturn._id ) ;
+ }
+ });
- } else {
+ } else {
- console.log( 'error getting old participants id in project.sort ' ) ;
+ console.log( 'error getting old participants id in project.sort ' ) ;
- }
+ }
- // needs to be after insertion to ensure it's still available for it
- // seems to return err === undefined instead of err === null
- Db.remove( 'project' + '.sort', duser._id, function (err) {
- if (err === null) { // || err === undefined
- console.log( 'removed old participants id in project.sort ' ) ;
- } else {
- console.log( 'error removing participants id in project.sort ' + err ) ;
- }
- });
+ // needs to be after insertion to ensure it's still available for it
+ // seems to return err === undefined instead of err === null
+ Db.remove( 'project' + '.sort', duser._id, function (err) {
+ if (err === null) { // || err === undefined
+ console.log( 'removed old participants id in project.sort ' ) ;
+ } else {
+ console.log( 'error removing participants id in project.sort ' + err ) ;
+ }
+ });
- }
+ }
- });
-
- // our could pull outside of loop, and before update, delete w critera network:id
- console.log( 'Lance deleting user ' + duser._id + ' aka ' + duser.username ) ;
- Db.remove('user', duser._id, function (err) {
- // not that since these callbacks are async, the clousure var duser may be iterated
- if (err === null) {
- console.log( 'Lance deleted user ' + duser._id) ;
- } else {
- console.log( 'Lance error deleting user ' + duser._id + ' ' + err ) ;
- }
- });
+ });
+
+ // our could pull outside of loop, and before update, delete w critera network:id
+ console.log( 'Lance deleting user ' + duser._id + ' aka ' + duser.username ) ;
+ Db.remove('user', duser._id, function (err) {
+ // not that since these callbacks are async, the clousure var duser may be iterated
+ if (err === null) {
+ console.log( 'Lance deleted user ' + duser._id) ;
+ } else {
+ console.log( 'Lance error deleting user ' + duser._id + ' ' + err ) ;
+ }
+ });
- }
+ }
- }
+ }
- // todo: only do this upon successful merge and delete?
- // Stream.update({ object: 'profile', user: user._id }, req);
- // res.api.result = { status: 'ok' };
- // next();
- Stream.update({ object: 'profile', user: user._id }, request);
- reply({ status: 'ok' });
+ // todo: only do this upon successful merge and delete?
+ // Stream.update({ object: 'profile', user: user._id }, req);
+ // res.api.result = { status: 'ok' };
+ // next();
+ Stream.update({ object: 'profile', user: user._id }, request);
+ reply({ status: 'relogin' }); // user id changed - need to login again
+
+ }
+
});
31 web/login.js
View
@@ -48,8 +48,21 @@ exports.login = function (req, res, next) {
!req.api.session.tos ||
req.api.session.tos < Tos.minimumTOS) {
- res.api.redirect = '/tos' + (req.query.next && req.query.next.charAt(0) === '/' ? '?next=' + encodeURIComponent(req.query.next) : '');
- next();
+ // res.api.redirect = '/tos' + (req.query.next && req.query.next.charAt(0) === '/' ? '?next=' + encodeURIComponent(req.query.next) : '');
+ // next();
+ // Lance - just post a faux acceptance for now and save the redirect until we have maningful tos
+ Api.clientCall('POST', '/user/' + req.api.profile.id + '/tos/' + Tos.currentTOS, '', function (result, err, code) {
+
+ // Refresh token
+
+ Session.refresh(req, res, req.api.session, function (session, err) {
+
+ // if we're redirecting just to refresh the cookies, let's find another way
+ res.api.redirect = '/tos' + (req.body.next ? '?next=' + encodeURIComponent(req.body.next) : '');
+ next();
+ });
+ });
+
}
else {
@@ -540,8 +553,18 @@ exports.auth = function (req, res, next) {
}, function (result, err, code) {
// res.api.redirect = '/account/linked'; // -Lance.
- res.api.redirect = '/view'; // reload view
- next();
+ // res.api.redirect = '/view'; // reload view
+ // next();
+
+ if( result.status === 'relogin' ) {
+ console.log( 'finalizedLogin relogin ' ) ;
+ exports.relogin( req, res, next ) ; // Session.refresh(req, res, req to /view
+ } else {
+ // done by entry?
+ // res.api.redirect = '/view'; // reload view
+ // next();
+ }
+
});
}
else {
4 web/server.js
View
@@ -163,7 +163,9 @@ internals.preprocessRequest = function (req, res, next) {
isNotWithStupid = ((req.api.agent.name === 'chrome' && Semver.satisfies(version, '>= 11.x.x')) ||
(req.api.agent.name === 'safari' && Semver.satisfies(version, '>= 5.x.x')) ||
- (req.api.agent.name === 'firefox' && Semver.satisfies(version, '>= 4.x.x')));
+ (req.api.agent.name === 'firefox' && Semver.satisfies(version, '>= 4.x.x')) ||
+ // (req.api.agent.name === 'msie' && Semver.satisfies(version, '>= 8.x.x')) ||
+ false );
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.