Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Fix regression on "Remember Me" feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Jan 6, 2016
1 parent 5a3da82 commit f067536
Show file tree
Hide file tree
Showing 9 changed files with 333 additions and 30 deletions.
2 changes: 2 additions & 0 deletions core/src/plugins/gui.ajax/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = function(grunt) {
'res/js/core/util/XMLUtils.js',
'res/js/core/util/PathUtils.js',
'res/js/core/util/HasherUtils.js',
'res/js/core/util/CookiesManager.js',
'res/js/core/model/Router.js',
'res/js/core/model/AjxpNode.js',
'res/js/ui/prototype/util/ajxp_utils.js',
Expand Down Expand Up @@ -160,6 +161,7 @@ module.exports = function(grunt) {
'res/js/core/util/XMLUtils.js',
'res/js/core/util/PathUtils.js',
'res/js/core/util/HasherUtils.js',
'res/js/core/util/CookiesManager.js',
'res/js/core/model/Router.js',
'res/js/core/model/AjxpNode.js',
'res/js/ui/prototype/util/ajxp_utils.js',
Expand Down
1 change: 1 addition & 0 deletions core/src/plugins/gui.ajax/res/js/ajaxplorer_core.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ js/core/util/LangUtils.js
js/core/util/XMLUtils.js
js/core/util/PathUtils.js
js/core/util/HasherUtils.js
js/core/util/CookiesManager.js
js/core/model/Router.js
js/core/model/AjxpNode.js
js/core/model/User.js
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/gui.ajax/res/js/es6/Pydio.es6
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Pydio extends Observable{
if(this.UI.modal) this.UI.modal.initForms();
this.UI.initObjects();

this.tryLogUserFromCookie();
PydioApi.getClient().tryToLogUserFromRememberData();
this.fire("registry_loaded", this.Registry.getXML());

window.setTimeout(function(){
Expand Down
85 changes: 56 additions & 29 deletions core/src/plugins/gui.ajax/res/js/es6/http/PydioApi.es6
Original file line number Diff line number Diff line change
Expand Up @@ -288,38 +288,28 @@ class PydioApi{
}

userSavePreference(prefName, prefValue){
var conn = new Connexion();
conn.setMethod('post');
conn.discrete = true;
conn.addParameter("get_action", "save_user_pref");
conn.addParameter("pref_name_" + 0, prefName);
conn.addParameter("pref_value_" + 0, prefValue);
conn.sendAsync();
this.request({get_action:"save_user_pref", "pref_name_0":prefName, "pref_value_0":prefValue}, null, null, {discrete:true, method:'post'});
}

userSavePreferences(preferences, completeCallback){
var conn = new Connexion();
conn.addParameter("get_action", "save_user_pref");
var params = {'get_action':'save_user_pref'};
var i=0;
preferences.forEach(function(value, key){
conn.addParameter("pref_name_"+i, key);
conn.addParameter("pref_value_"+i, value);
params["pref_name_"+i] = key;
params["pref_value_"+i] = value;
i++;
});
conn.onComplete = completeCallback;
conn.sendAsync();

this.request(params, completeCallback, null, {discrete:true, method:'post'});
}

userSavePassword(oldPass, newPass, seed, completeCallback){
var conn = new Connexion();
conn.addParameter("get_action", "save_user_pref");
conn.addParameter("pref_name_"+i, "password");
conn.addParameter("pref_value_"+i, newPass);
conn.addParameter("crt", oldPass);
conn.addParameter("pass_seed", seed);
conn.onComplete = completeCallback;
conn.sendAsync();
this.request({
get_action:'save_user_pref',
pref_name_0:"password",
pref_value_0:newPass,
crt:oldPass,
pass_seed:seed
}, completeCallback, null, {discrete:true, method:'post'});

}

Expand Down Expand Up @@ -454,14 +444,9 @@ class PydioApi{
if(result == '1')
{
try{
/*
TODO: REMEMBER COOKIE STUFF
if(childs[i].getAttribute('remember_login') && childs[i].getAttribute('remember_pass')){
var login = childs[i].getAttribute('remember_login');
var pass = childs[i].getAttribute('remember_pass');
storeRememberData(login, pass);
PydioApi.storeRememberData();
}
*/
}catch(e){
Logger.error('Error after login, could prevent registry loading!', e);
}
Expand Down Expand Up @@ -558,9 +543,51 @@ class PydioApi{
* Trigger a simple download
* @param url String
*/
triggerDownload(url){
static triggerDownload(url){
document.location.href = url;
}

static storeRememberData(){
if(!CookiesManager.supported()) return false;
var cManager = new CookiesManager({
expires: 3600*24*10,
path:'/',
secure: true
});
cManager.putCookie('remember', 'true');
}

static clearRememberData(){
if(!CookiesManager.supported()) return false;
var cManager = new CookiesManager({
path:'/',
secure: true
});
return cManager.removeCookie('remember');
}

static hasRememberData(){
if(!CookiesManager.supported()) return false;
var cManager = new CookiesManager({
path:'/',
secure: true
});
return (cManager.getCookie('remember') === 'true');
}

tryToLogUserFromRememberData(){
if(!CookiesManager.supported()) return false;
if(PydioApi.hasRememberData()){
this.request({
get_action:'login',
userid:'notify',
password:'notify',
cookie_login:'true'
}, function(transport){
this.parseXmlMessage(transport.responseXML);
}.bind(this), null, {async:false});
}
}


}
181 changes: 181 additions & 0 deletions core/src/plugins/gui.ajax/res/js/es6/util/CookiesManager.es6
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/*
* Copyright 2007-2016 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
* This file is part of Pydio.
*
* Pydio is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <https://pydio.com/>.
*
* Pure Javascript (ES6) Cookie Manager inspired by CookieJar that was relying on PrototypeJS.
*
* ----
* CookieJAR Original Header
*
* Javascript code to store data as JSON strings in cookies.
* It uses prototype.js 1.5.1 (http://www.prototypejs.org)
*
* Author : Lalit Patel
* Website: http://www.lalit.org/lab/jsoncookies
* License: Creative Commons Attribution-ShareAlike 2.5
* http://creativecommons.org/licenses/by-sa/2.5/
* Version: 0.4
* Updated: Aug 11, 2007 10:09am
*
* Chnage Log:
* v 0.4
* - Removed a extra comma in options (was breaking in IE and Opera). (Thanks Jason)
* - Removed the parameter name from the initialize function
* - Changed the way expires date was being calculated. (Thanks David)
* v 0.3
* - Removed dependancy on json.js (http://www.json.org/json.js)
* - empty() function only deletes the cookies set by CookieJar
*/

class CookiesManager{

static supported(){
return (document && document.cookie !== undefined);
}

/**
* Initializes the cookie jar with the options.
*/
constructor(options) {
/**
* Append before all cookie names to differntiate them.
*/
this._appendString = "__PYDIO__";

this.options = {
expires: 3600, // seconds (1 hr)
path: '', // cookie path
domain: '', // cookie domain
secure: '' // secure ?
};
this.options = LangUtils.objectMerge(this.options, options || {});

if (this.options.expires != '') {
var date = new Date();
date = new Date(date.getTime() + (this.options.expires * 1000));
this.options.expires = '; expires=' + date.toGMTString();
}
if (this.options.path != '') {
this.options.path = '; path=' + encodeURI(this.options.path);
}
if (this.options.domain != '') {
this.options.domain = '; domain=' + encodeURI(this.options.domain);
}
if (this.options.secure == 'secure') {
this.options.secure = '; secure';
} else {
this.options.secure = '';
}
}

/**
* Adds a name values pair.
*/
putCookie(name, value) {
name = this._appendString + name;
var cookie = this.options;
var type = typeof value;
switch(type) {
case 'undefined':
case 'function' :
case 'unknown' : return false;
case 'boolean' :
case 'string' :
case 'number' : value = String(value.toString());
}
var cookie_str = name + "=" + encodeURI(JSON.stringify(value));
try {
document.cookie = cookie_str + cookie.expires + cookie.path + cookie.domain + cookie.secure;
} catch (e) {
return false;
}
return true;
}

/**
* Removes a particular cookie (name value pair) form the Cookie Jar.
*/
removeCookie(name) {
name = this._appendString + name;
var cookie = this.options;
try {
var date = new Date();
date.setTime(date.getTime() - (3600 * 1000));
var expires = '; expires=' + date.toGMTString();
document.cookie = name + "=" + expires + cookie.path + cookie.domain + cookie.secure;
} catch (e) {
return false;
}
return true;
}

/**
* Return a particular cookie by name;
*/
getCookie(name) {
name = this._appendString + name;
var cookies = document.cookie.match(name + '=(.*?)(;|$)');
if (cookies) {
return JSON.parse(decodeURI(cookies[1]));
} else {
return null;
}
}

/**
* Empties the Cookie Jar. Deletes all the cookies.
*/
emptyAll() {
var keys = this.getKeys();
var size = keys.size();
for(var i=0; i<size; i++) {
this.removeCookie(keys[i]);
}
}

/**
* Returns all cookies as a single object
*/
getPack() {
var pack = {};
var keys = this.getKeys();

var size = keys.size();
for(var i=0; i<size; i++) {
pack[keys[i]] = this.get(keys[i]);
}
return pack;
}

/**
* Returns all keys.
*/
getKeys() {
var keys = [];
var keyRe= /[^=; ]+(?=\=)/g;
var str = document.cookie;
var CJRe = new RegExp("^" + this._appendString);
var match;
while((match = keyRe.exec(str)) != undefined) {
if (CJRe.test(match[0].strip())) {
keys.push(match[0].strip().gsub("^" + this._appendString,""));
}
}
return keys;
}
}
23 changes: 23 additions & 0 deletions core/src/plugins/gui.ajax/res/js/es6/util/HasherUtils.es6
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
/*
* Copyright 2007-2016 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
* This file is part of Pydio.
*
* Pydio is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <https://pydio.com/>.
*
*/
/**
* Utilitary class for hashing methods
*/
class HasherUtils{

/*
Expand Down
23 changes: 23 additions & 0 deletions core/src/plugins/gui.ajax/res/js/es6/util/LangUtils.es6
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
/*
* Copyright 2007-2016 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
* This file is part of Pydio.
*
* Pydio is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <https://pydio.com/>.
*
*/
/**
* Utilitary class for language specific methods
*/
class LangUtils{

static arrayWithout(array, key){
Expand Down
Loading

0 comments on commit f067536

Please sign in to comment.