kopia lustrzana https://github.com/backface/turtlestitch
persistent login
rodzic
f075bbd9ff
commit
dceb296f55
27
cloud.js
27
cloud.js
|
@ -46,12 +46,8 @@ function Cloud(url) {
|
||||||
Cloud.prototype.init = function (url) {
|
Cloud.prototype.init = function (url) {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.username = null;
|
this.username = null;
|
||||||
this.checkCredentials();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Cloud.prototype.clear = function () {
|
|
||||||
this.username = null;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Dictionary handling
|
// Dictionary handling
|
||||||
|
|
||||||
|
@ -193,6 +189,18 @@ Cloud.prototype.withCredentialsRequest = function (
|
||||||
|
|
||||||
// Credentials management
|
// Credentials management
|
||||||
|
|
||||||
|
Cloud.prototype.initSession = function (onSuccess) {
|
||||||
|
var myself = this;
|
||||||
|
this.request(
|
||||||
|
'POST',
|
||||||
|
'/init',
|
||||||
|
function () { myself.checkCredentials(onSuccess); },
|
||||||
|
nop,
|
||||||
|
null,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
Cloud.prototype.checkCredentials = function (onSuccess, onError) {
|
Cloud.prototype.checkCredentials = function (onSuccess, onError) {
|
||||||
var myself = this;
|
var myself = this;
|
||||||
this.getCurrentUser(
|
this.getCurrentUser(
|
||||||
|
@ -211,20 +219,25 @@ Cloud.prototype.getCurrentUser = function (onSuccess, onError) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Cloud.prototype.logout = function (onSuccess, onError) {
|
Cloud.prototype.logout = function (onSuccess, onError) {
|
||||||
|
this.username = null;
|
||||||
this.request(
|
this.request(
|
||||||
'POST',
|
'POST',
|
||||||
'/users/' + this.username + '/logout',
|
'/logout',
|
||||||
onSuccess,
|
onSuccess,
|
||||||
onError,
|
onError,
|
||||||
'logout failed'
|
'logout failed'
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
Cloud.prototype.login = function (username, password, onSuccess, onError) {
|
Cloud.prototype.login = function (username, password, persist, onSuccess, onError) {
|
||||||
var myself = this;
|
var myself = this;
|
||||||
this.request(
|
this.request(
|
||||||
'POST',
|
'POST',
|
||||||
'/users/' + username + '/login?' + this.encodeDict({ password: password }),
|
'/users/' + username + '/login?' +
|
||||||
|
this.encodeDict({
|
||||||
|
password: password,
|
||||||
|
persist: persist
|
||||||
|
}),
|
||||||
function () {
|
function () {
|
||||||
myself.checkCredentials(onSuccess, onError);
|
myself.checkCredentials(onSuccess, onError);
|
||||||
},
|
},
|
||||||
|
|
40
gui.js
40
gui.js
|
@ -268,22 +268,13 @@ IDE_Morph.prototype.init = function (isAutoFill) {
|
||||||
IDE_Morph.prototype.openIn = function (world) {
|
IDE_Morph.prototype.openIn = function (world) {
|
||||||
var hash, usr, myself = this, urlLanguage = null;
|
var hash, usr, myself = this, urlLanguage = null;
|
||||||
|
|
||||||
// get persistent user data, if any
|
SnapCloud.initSession(
|
||||||
if (this.hasLocalStorage()) {
|
function (username) {
|
||||||
usr = localStorage['-snap-user'];
|
if (username) {
|
||||||
if (usr) {
|
myself.source = 'cloud';
|
||||||
SnapCloud.checkCredentials(
|
}
|
||||||
function (username) {
|
|
||||||
if (username) {
|
|
||||||
this.source = 'cloud';
|
|
||||||
}
|
|
||||||
},
|
|
||||||
function () {
|
|
||||||
delete localStorage['-snap-user'];
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
|
|
||||||
this.buildPanes();
|
this.buildPanes();
|
||||||
world.add(this);
|
world.add(this);
|
||||||
|
@ -5055,10 +5046,8 @@ IDE_Morph.prototype.initializeCloud = function () {
|
||||||
SnapCloud.login(
|
SnapCloud.login(
|
||||||
user.username,
|
user.username,
|
||||||
user.password,
|
user.password,
|
||||||
|
user.choice,
|
||||||
function () {
|
function () {
|
||||||
if (user.choice) {
|
|
||||||
localStorage['-snap-user'] = user.username;
|
|
||||||
}
|
|
||||||
myself.source = 'cloud';
|
myself.source = 'cloud';
|
||||||
myself.showMessage('now connected.', 2);
|
myself.showMessage('now connected.', 2);
|
||||||
},
|
},
|
||||||
|
@ -5082,11 +5071,7 @@ IDE_Morph.prototype.initializeCloud = function () {
|
||||||
IDE_Morph.prototype.createCloudAccount = function () {
|
IDE_Morph.prototype.createCloudAccount = function () {
|
||||||
var myself = this,
|
var myself = this,
|
||||||
world = this.world();
|
world = this.world();
|
||||||
/*
|
|
||||||
// force-logout, commented out for now:
|
|
||||||
delete localStorage['-snap-user'];
|
|
||||||
SnapCloud.clear();
|
|
||||||
*/
|
|
||||||
new DialogBoxMorph(
|
new DialogBoxMorph(
|
||||||
null,
|
null,
|
||||||
function (user) {
|
function (user) {
|
||||||
|
@ -5124,11 +5109,7 @@ IDE_Morph.prototype.createCloudAccount = function () {
|
||||||
IDE_Morph.prototype.resetCloudPassword = function () {
|
IDE_Morph.prototype.resetCloudPassword = function () {
|
||||||
var myself = this,
|
var myself = this,
|
||||||
world = this.world();
|
world = this.world();
|
||||||
/*
|
|
||||||
// force-logout, commented out for now:
|
|
||||||
delete localStorage['-snap-user'];
|
|
||||||
SnapCloud.clear();
|
|
||||||
*/
|
|
||||||
new DialogBoxMorph(
|
new DialogBoxMorph(
|
||||||
null,
|
null,
|
||||||
function (user) {
|
function (user) {
|
||||||
|
@ -5194,14 +5175,11 @@ IDE_Morph.prototype.changeCloudPassword = function () {
|
||||||
|
|
||||||
IDE_Morph.prototype.logout = function () {
|
IDE_Morph.prototype.logout = function () {
|
||||||
var myself = this;
|
var myself = this;
|
||||||
delete localStorage['-snap-user'];
|
|
||||||
SnapCloud.logout(
|
SnapCloud.logout(
|
||||||
function () {
|
function () {
|
||||||
SnapCloud.clear();
|
|
||||||
myself.showMessage('disconnected.', 2);
|
myself.showMessage('disconnected.', 2);
|
||||||
},
|
},
|
||||||
function () {
|
function () {
|
||||||
SnapCloud.clear();
|
|
||||||
myself.showMessage('disconnected.', 2);
|
myself.showMessage('disconnected.', 2);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Ładowanie…
Reference in New Issue