diff --git a/HELP.md b/HELP.md index dcf43f10..2b3a2785 100644 --- a/HELP.md +++ b/HELP.md @@ -238,6 +238,7 @@ Right mouse click button shows context menu with items: - Copy - Paste - (Un)Select All +- Log Out (available when the `authorization` is enabled) ### Hot keys |Key |Operation diff --git a/css/icons.css b/css/icons.css index af28a464..953ca20a 100644 --- a/css/icons.css +++ b/css/icons.css @@ -122,3 +122,8 @@ font-family : 'Fontello'; content : '\e819 '; } + +.icon-log-out::before { + font-family : 'Fontello'; + content : '\e81a '; +} diff --git a/font/fontello.eot b/font/fontello.eot index 12f282a7..65c4d297 100644 Binary files a/font/fontello.eot and b/font/fontello.eot differ diff --git a/font/fontello.json b/font/fontello.json index ed5497ce..7271a684 100644 --- a/font/fontello.json +++ b/font/fontello.json @@ -217,6 +217,12 @@ "css": "upload", "code": 59417, "src": "fontawesome" + }, + { + "uid": "2d76f2c8d13be40694ecadfea7fb83c3", + "css": "logout", + "code": 59418, + "src": "entypo" } ] } diff --git a/font/fontello.svg b/font/fontello.svg index 3b768ad4..77aea151 100644 --- a/font/fontello.svg +++ b/font/fontello.svg @@ -1,37 +1,38 @@ -Copyright (C) 2014 by original authors @ fontello.com +Copyright (C) 2015 by original authors @ fontello.com - - + + - - - - + + + + - - + + - - + + - - - + + + - - - - + + + + - - - + + + + \ No newline at end of file diff --git a/font/fontello.ttf b/font/fontello.ttf index ba06184f..1562b480 100644 Binary files a/font/fontello.ttf and b/font/fontello.ttf differ diff --git a/font/fontello.woff b/font/fontello.woff index 262eddc9..6c5abc6e 100644 Binary files a/font/fontello.woff and b/font/fontello.woff differ diff --git a/font/fontello.woff2 b/font/fontello.woff2 index 33adea46..63a86e3e 100644 Binary files a/font/fontello.woff2 and b/font/fontello.woff2 differ diff --git a/img/screen/menu.png b/img/screen/menu.png index 2841d40c..02338afd 100644 Binary files a/img/screen/menu.png and b/img/screen/menu.png differ diff --git a/lib/client.js b/lib/client.js index e556fd6f..698748ac 100644 --- a/lib/client.js +++ b/lib/client.js @@ -212,6 +212,15 @@ var Util, DOM, CloudFunc, join; } }; + this.logOut = function() { + DOM.load.ajax({ + url: '/logout', + error: function() { + document.location.reload(); + } + }); + }; + function initModules(callback) { Util.exec.if(CloudCmd.Key, function() { Key = new CloudCmd.Key(); diff --git a/lib/client/load.js b/lib/client/load.js index 8e0ebb29..d63e09d2 100644 --- a/lib/client/load.js +++ b/lib/client/load.js @@ -167,10 +167,16 @@ var Util, DOM; isArray = Util.type.array(p.data), isArrayBuf = Util.type(p.data) === 'arraybuffer', type = p.type || p.method || 'GET', + headers = p.headers || {}, xhr = new XMLHttpRequest(); xhr.open(type, p.url, true); + Object.keys(headers).forEach(function(name) { + var value = headers[name]; + xhr.setRequestHeader(name, value); + }); + if (p.responseType) xhr.responseType = p.responseType; diff --git a/lib/client/menu.js b/lib/client/menu.js index 1a86ce2e..6bd70c84 100644 --- a/lib/client/menu.js +++ b/lib/client/menu.js @@ -74,11 +74,11 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO; MenuContext.show(x, y); MenuContextFile.show(x, y); } else { - loadFileMenuData(function(menuDataFile) { + loadFileMenuData(function(isAuth, menuDataFile) { var is, menu, NOT_FILE = true, fm = DOM.getFM(), - menuData = getMenuData(), + menuData = getMenuData(isAuth), options = getOptions(NOT_FILE), optionsFile = getOptions(); @@ -102,6 +102,17 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO; } } + function isAuth(callback) { + DOM.Files.get('config', function(error, config) { + var is = config.auth; + + if (error) + DOM.alert(error); + + callback(is); + }); + } + function getOptions(notFile) { var name, func, options; @@ -123,7 +134,7 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO; return options; } - function getMenuData() { + function getMenuData(isAuth) { var menu = { 'Paste' : Buffer.paste, 'New' : { @@ -134,38 +145,43 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO; '(Un)Select All': DOM.toggleAllSelectedFiles }; + if (isAuth) + menu['Log Out'] = CloudCmd.logOut; + return menu; } function loadFileMenuData(callback) { - getUploadTo(function(menuUpload) { - var show = function(name) { - CloudCmd[name].show(); - }, - menuData = getMenuData(), - menu = { - 'View' : Util.exec.with(show, 'View'), - 'Edit' : Util.exec.with(show, 'Edit'), - 'Rename' : function() { - setTimeout(DOM.renameCurrent, 100); + isAuth(function(is) { + getUploadTo(function(menuUpload) { + var show = function(name) { + CloudCmd[name].show(); }, - 'Delete' : DOM.promptDelete, - 'Pack' : getActiveFunc(DOM.pack), - 'Unpack' : getActiveFunc(DOM.unpack), - 'Upload' : function() { - CloudCmd.Upload.show(); - }, - 'Upload To' : {}, - 'Download' : download, - 'Cut' : Buffer.cut, - 'Copy' : Buffer.copy, - }; - - menu['Upload To'] = menuUpload; - - Util.copyObj(menu, menuData); - - Util.exec(callback, menu); + menuData = getMenuData(is), + menu = { + 'View' : Util.exec.with(show, 'View'), + 'Edit' : Util.exec.with(show, 'Edit'), + 'Rename' : function() { + setTimeout(DOM.renameCurrent, 100); + }, + 'Delete' : DOM.promptDelete, + 'Pack' : getActiveFunc(DOM.pack), + 'Unpack' : getActiveFunc(DOM.unpack), + 'Upload' : function() { + CloudCmd.Upload.show(); + }, + 'Upload To' : {}, + 'Download' : download, + 'Cut' : Buffer.cut, + 'Copy' : Buffer.copy, + }; + + menu['Upload To'] = menuUpload; + + Util.copyObj(menu, menuData); + + callback(is, menu); + }); }); } diff --git a/lib/cloudcmd.js b/lib/cloudcmd.js index 229b7330..60e9c0c6 100644 --- a/lib/cloudcmd.js +++ b/lib/cloudcmd.js @@ -103,6 +103,7 @@ }), funcs = [ + logout, setUrl(prefix), authFunc, config(), @@ -153,6 +154,13 @@ return funcs; } + function logout(req, res, next) { + if (req.url === '/logout') + res.sendStatus(401); + else + next(); + } + function setUrl(prefix) { return function(req, res, next) { var is = !req.url.indexOf(prefix);