Allow {pair.pub} to login with pass (#1233)

* Update sea.js

* Update auth.js

* Update sea.js

* Update auth.js

* Update rs3.js

* added test for login via {pub}

* gh page build
This commit is contained in:
Bradley Matusiak 2022-04-29 19:26:26 -04:00 committed by GitHub
parent a092f5a725
commit e3eaf5e268
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 6 deletions

View File

@ -94,7 +94,7 @@ function Store(opt){
// Stream interface requires a final call to know when to be done.
cb.end = true; cb();
}
Gun.obj.map(cbs, cbe);
// Gun.obj.map(cbs, cbe); // lets see if fixes heroku
if(!IT){ Gun.obj.del(c.l, 1); return }
params.ContinuationToken = data.NextContinuationToken;
store.list(cb, match, params, cbs);

18
sea.js
View File

@ -964,7 +964,7 @@
User.prototype.auth = function(...args){ // TODO: this PR with arguments need to be cleaned up / refactored.
var pair = typeof args[0] === 'object' && (args[0].pub || args[0].epub) ? args[0] : typeof args[1] === 'object' && (args[1].pub || args[1].epub) ? args[1] : null;
var alias = !pair && typeof args[0] === 'string' ? args[0] : null;
var pass = alias && typeof args[1] === 'string' ? args[1] : null;
var pass = (alias || (pair && !(pair.priv && pair.epriv))) && typeof args[1] === 'string' ? args[1] : null;
var cb = args.filter(arg => typeof arg === 'function')[0] || null; // cb now can stand anywhere, after alias/pass or pair
var opt = args && args.length > 1 && typeof args[args.length-1] === 'object' ? args[args.length-1] : {}; // opt is always the last parameter which typeof === 'object' and stands after cb
@ -1048,6 +1048,17 @@
Gun.log("Your 'auth' callback crashed with:", e);
}
}
act.h = function(data){
if(!data){ return act.b() }
alias = data.alias
if(!alias)
alias = data.alias = "~" + pair.pub
if(!data.auth){
return act.g(pair);
}
pair = null;
act.c((act.data = data).auth);
}
act.z = function(){
// password update so encrypt private key using new pwd + salt
act.salt = String.random(64); // pseudo-random
@ -1084,7 +1095,10 @@
act.b(tmp);
}
if(pair){
act.g(pair);
if(pair.priv && pair.epriv)
act.g(pair);
else
root.get('~'+pair.pub).once(act.h);
} else
if(alias){
root.get('~@'+alias).once(act.a);

View File

@ -4,7 +4,7 @@
User.prototype.auth = function(...args){ // TODO: this PR with arguments need to be cleaned up / refactored.
var pair = typeof args[0] === 'object' && (args[0].pub || args[0].epub) ? args[0] : typeof args[1] === 'object' && (args[1].pub || args[1].epub) ? args[1] : null;
var alias = !pair && typeof args[0] === 'string' ? args[0] : null;
var pass = alias && typeof args[1] === 'string' ? args[1] : null;
var pass = (alias || (pair && !(pair.priv && pair.epriv))) && typeof args[1] === 'string' ? args[1] : null;
var cb = args.filter(arg => typeof arg === 'function')[0] || null; // cb now can stand anywhere, after alias/pass or pair
var opt = args && args.length > 1 && typeof args[args.length-1] === 'object' ? args[args.length-1] : {}; // opt is always the last parameter which typeof === 'object' and stands after cb
@ -88,6 +88,17 @@
Gun.log("Your 'auth' callback crashed with:", e);
}
}
act.h = function(data){
if(!data){ return act.b() }
alias = data.alias
if(!alias)
alias = data.alias = "~" + pair.pub
if(!data.auth){
return act.g(pair);
}
pair = null;
act.c((act.data = data).auth);
}
act.z = function(){
// password update so encrypt private key using new pwd + salt
act.salt = String.random(64); // pseudo-random
@ -124,7 +135,10 @@
act.b(tmp);
}
if(pair){
act.g(pair);
if(pair.priv && pair.epriv)
act.g(pair);
else
root.get('~'+pair.pub).once(act.h);
} else
if(alias){
root.get('~@'+alias).once(act.a);
@ -140,4 +154,4 @@
}catch(e){o={}};
return o;
}

View File

@ -331,6 +331,15 @@ describe('SEA', function(){
})
})
it('logout, login via {pub}', function(done){
var pub = user.is.pub;
user.leave();
user.auth({pub:pub}, 'testing123', function(ack){
expect(ack.err).to.not.be.ok();
done();
})
})
it('save data', function(done){
user.get('a').get('b').put(0, function(ack){
expect(ack.err).to.not.be.ok();
@ -765,3 +774,4 @@ describe('SEA', function(){
})
}());