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) {
|
||||
this.url = url;
|
||||
this.username = null;
|
||||
this.checkCredentials();
|
||||
};
|
||||
|
||||
Cloud.prototype.clear = function () {
|
||||
this.username = null;
|
||||
};
|
||||
|
||||
// Dictionary handling
|
||||
|
||||
|
@ -193,6 +189,18 @@ Cloud.prototype.withCredentialsRequest = function (
|
|||
|
||||
// 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) {
|
||||
var myself = this;
|
||||
this.getCurrentUser(
|
||||
|
@ -211,20 +219,25 @@ Cloud.prototype.getCurrentUser = function (onSuccess, onError) {
|
|||
};
|
||||
|
||||
Cloud.prototype.logout = function (onSuccess, onError) {
|
||||
this.username = null;
|
||||
this.request(
|
||||
'POST',
|
||||
'/users/' + this.username + '/logout',
|
||||
'/logout',
|
||||
onSuccess,
|
||||
onError,
|
||||
'logout failed'
|
||||
);
|
||||
};
|
||||
|
||||
Cloud.prototype.login = function (username, password, onSuccess, onError) {
|
||||
Cloud.prototype.login = function (username, password, persist, onSuccess, onError) {
|
||||
var myself = this;
|
||||
this.request(
|
||||
'POST',
|
||||
'/users/' + username + '/login?' + this.encodeDict({ password: password }),
|
||||
'/users/' + username + '/login?' +
|
||||
this.encodeDict({
|
||||
password: password,
|
||||
persist: persist
|
||||
}),
|
||||
function () {
|
||||
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) {
|
||||
var hash, usr, myself = this, urlLanguage = null;
|
||||
|
||||
// get persistent user data, if any
|
||||
if (this.hasLocalStorage()) {
|
||||
usr = localStorage['-snap-user'];
|
||||
if (usr) {
|
||||
SnapCloud.checkCredentials(
|
||||
function (username) {
|
||||
if (username) {
|
||||
this.source = 'cloud';
|
||||
}
|
||||
},
|
||||
function () {
|
||||
delete localStorage['-snap-user'];
|
||||
}
|
||||
);
|
||||
SnapCloud.initSession(
|
||||
function (username) {
|
||||
if (username) {
|
||||
myself.source = 'cloud';
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
this.buildPanes();
|
||||
world.add(this);
|
||||
|
@ -5055,10 +5046,8 @@ IDE_Morph.prototype.initializeCloud = function () {
|
|||
SnapCloud.login(
|
||||
user.username,
|
||||
user.password,
|
||||
user.choice,
|
||||
function () {
|
||||
if (user.choice) {
|
||||
localStorage['-snap-user'] = user.username;
|
||||
}
|
||||
myself.source = 'cloud';
|
||||
myself.showMessage('now connected.', 2);
|
||||
},
|
||||
|
@ -5082,11 +5071,7 @@ IDE_Morph.prototype.initializeCloud = function () {
|
|||
IDE_Morph.prototype.createCloudAccount = function () {
|
||||
var myself = this,
|
||||
world = this.world();
|
||||
/*
|
||||
// force-logout, commented out for now:
|
||||
delete localStorage['-snap-user'];
|
||||
SnapCloud.clear();
|
||||
*/
|
||||
|
||||
new DialogBoxMorph(
|
||||
null,
|
||||
function (user) {
|
||||
|
@ -5124,11 +5109,7 @@ IDE_Morph.prototype.createCloudAccount = function () {
|
|||
IDE_Morph.prototype.resetCloudPassword = function () {
|
||||
var myself = this,
|
||||
world = this.world();
|
||||
/*
|
||||
// force-logout, commented out for now:
|
||||
delete localStorage['-snap-user'];
|
||||
SnapCloud.clear();
|
||||
*/
|
||||
|
||||
new DialogBoxMorph(
|
||||
null,
|
||||
function (user) {
|
||||
|
@ -5194,14 +5175,11 @@ IDE_Morph.prototype.changeCloudPassword = function () {
|
|||
|
||||
IDE_Morph.prototype.logout = function () {
|
||||
var myself = this;
|
||||
delete localStorage['-snap-user'];
|
||||
SnapCloud.logout(
|
||||
function () {
|
||||
SnapCloud.clear();
|
||||
myself.showMessage('disconnected.', 2);
|
||||
},
|
||||
function () {
|
||||
SnapCloud.clear();
|
||||
myself.showMessage('disconnected.', 2);
|
||||
}
|
||||
);
|
||||
|
|
Ładowanie…
Reference in New Issue