mirror of
https://github.com/amark/gun.git
synced 2025-03-30 15:08:33 +00:00
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:
parent
a092f5a725
commit
e3eaf5e268
@ -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
18
sea.js
@ -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);
|
||||
|
20
sea/auth.js
20
sea/auth.js
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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(){
|
||||
})
|
||||
|
||||
}());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user