From ee2c9b4b8c25beb2f1c4ef048d6e27f416882954 Mon Sep 17 00:00:00 2001 From: srgooglo <38926803+srgooglo@users.noreply.github.com> Date: Thu, 19 Mar 2020 17:03:24 +0100 Subject: [PATCH] JWT Sign & Expire tokens --- config/app.settings.js | 2 +- src/@ycore/libs/comty_ng/pre.js | 21 -------- src/@ycore/libs/ycore_sdcp/pre.js | 4 -- src/@ycore/libs/yulio_id/pre.js | 72 +++++++++++++--------------- src/components/CustomIcons/index.js | 4 +- src/components/Layout/Secondary.less | 6 +-- src/components/MainFeed/index.js | 1 - src/components/YulioID/index.js | 33 ++++--------- src/layouts/BaseLayout.js | 1 - src/layouts/PrimaryLayout.js | 4 +- src/pages/__m/index.js | 15 +++--- 11 files changed, 57 insertions(+), 106 deletions(-) diff --git a/config/app.settings.js b/config/app.settings.js index 6b442c3d..e9926e04 100755 --- a/config/app.settings.js +++ b/config/app.settings.js @@ -17,7 +17,7 @@ export var DevOptions = { default_collapse_sider: ReturnDevOption('default_collapse_sider'), use_dev_server: ReturnDevOption('use_dev_server'), force_show_postactions: ReturnDevOption('force_show_postactions'), - MaxJWTexpire: '1556952', + MaxJWTexpire: 1556952, //1556952 MaxLengthPosts: '512', CurrentBundle: 'light_ng', // In KB diff --git a/src/@ycore/libs/comty_ng/pre.js b/src/@ycore/libs/comty_ng/pre.js index e2cc675c..ddac4979 100755 --- a/src/@ycore/libs/comty_ng/pre.js +++ b/src/@ycore/libs/comty_ng/pre.js @@ -329,24 +329,3 @@ export const get_app_session = { .catch(error => ycore.yconsole.log('error', error)); } } -export function PushUserData(inputIO1, inputIO2) { - var getStoragedToken = Cookies.get('access_token'); - var yCore_GUDEP = ycore.endpoints.update_userData_endpoint; - var urlOBJ = "" + yCore_GUDEP + getStoragedToken; - ycore.yconsole.log('Recived', global, 'sending to ', urlOBJ) - var form = new FormData(); - form.append("server_key", ycore.yConfig.server_key); - form.append(inputIO1, inputIO2); - var settings = { - "url": urlOBJ, - "method": "POST", - "timeout": 0, - "processData": false, - "mimeType": "multipart/form-data", - "contentType": false, - "data": form - }; - jquery.ajax(settings).done(function (response) { - ycore.yconsole.log(response) - }); -} \ No newline at end of file diff --git a/src/@ycore/libs/ycore_sdcp/pre.js b/src/@ycore/libs/ycore_sdcp/pre.js index 34e970b4..bf39b317 100755 --- a/src/@ycore/libs/ycore_sdcp/pre.js +++ b/src/@ycore/libs/ycore_sdcp/pre.js @@ -22,7 +22,6 @@ export const asyncSDCP = { return callback(null, b) }) } catch (err) { - console.log(err); return false } }, @@ -105,7 +104,6 @@ export const CryptSDCP = { }, valid: () => { const a = ycore.asyncSDCP.get() - console.log(a) return a? true : false } @@ -117,6 +115,4 @@ export function SetupApp(){ if (!resourceLoad) { localStorage.setItem('resource_bundle', 'light_ng') } - - } \ No newline at end of file diff --git a/src/@ycore/libs/yulio_id/pre.js b/src/@ycore/libs/yulio_id/pre.js index 95998cf6..dae2c776 100755 --- a/src/@ycore/libs/yulio_id/pre.js +++ b/src/@ycore/libs/yulio_id/pre.js @@ -12,11 +12,7 @@ export function userData(){ return ycore.handlerYIDT.get() } - - function __API__User (payload, sdcp){ - const now = new Date() - now.setDate(now.getDate() + 1) const { UserID, UserToken } = payload const a = ycore.CryptSDCP.atob_parse(sdcp) @@ -31,26 +27,23 @@ function __API__User (payload, sdcp){ dev, is_pro, username, - deadline: ( ycore.DevOptions.SignForNotExpire? null : now.getTime() ) + exp: ycore.DevOptions.SignForNotExpire? 0 : Math.floor(Date.now() / 1000) + (60 * 60), } ycore.handlerYIDT.set(frame, done => { - ycore.RefreshONCE() + done? ycore.RefreshONCE() : null }) } export const handlerYIDT = { set: (value, callback) => { - const ExpireTime = ycore.DevOptions.MaxJWTexpire jwt.sign( value, keys.secretOrKey, - ycore.DevOptions.SignForNotExpire? { expiresIn: '0' } : { expiresIn: ExpireTime }, (err, token) => { err? null : Cookies.set('cid', token) callback(true) } ) - ycore.yconsole.debug(frame) return true }, getRaw: () => { @@ -86,40 +79,43 @@ export const handlerYIDT = { } export function ValidLoginSession(callback){ - const prefix = '[YID Session]'; - let final = false; - let ValidCookiesToken = false; - let ValidSDCP = false; + let validtoken = false; + + const a = Cookies.get('cid'); + if (a) { + const modExp = ycore.DevOptions.SignForNotExpire; + const ad = jwt.decode(a) - let TokenContainer = Cookies.get('cid'); + let notexp = true; // Sets if this is expired (Default is not expired) + let exists = false; // Sets if this exist - if (TokenContainer) { - let TokenContainerDC = jwt.decode(TokenContainer) - if (TokenContainerDC){ - ValidCookiesToken = true - } + ad? (exists = true) : null + + const tokenExp = (ad.exp * 1000) + const tokenExpLocale = new Date(tokenExp).toLocaleString() + const now = new Date().getTime() + + + ycore.yconsole.log(`TOKEN EXP => ${tokenExp} ${modExp? '( Infinite )' : `( ${tokenExpLocale} )` } || NOW => ${now}`) + + + if (modExp == false) { + if(tokenExp < now) { + ycore.yconsole.log('This token is expired !!!') + notexp = false + } + } + if (notexp && exists) { + validtoken = true + } + + } - if (ycore.CryptSDCP.valid()){ - ValidSDCP = true; - } - - if (ValidCookiesToken == true){ - final = true - } - - const finalvalids = { ValidSDCP, ValidCookiesToken, final } - ycore.DevOptions.ShowFunctionsLogs? ( - console.group(`%c ${prefix} `, 'background: #339edf; color: #fff'), - console.log(`Valid SDCP => ${ValidSDCP}`), - console.log(`Valid Token => ${ValidCookiesToken}`), - console.log(`Session is valid => ${final}`), - console.groupEnd() - ) : null if (callback) { - callback(finalvalids) + callback(validtoken) } - return final + return validtoken } export function ValidBackup(){ let ValidBackupToken = false; @@ -134,7 +130,7 @@ export function ValidBackup(){ } export function MakeBackup(){ if (ValidBackup() == false) { - ycore.asyncLocalStorage.setItem('last_backup', Cookies.get('cid')) + localStorage.setItem('last_backup', Cookies.get('cid')) return } } diff --git a/src/components/CustomIcons/index.js b/src/components/CustomIcons/index.js index 1a32f754..2b41965d 100755 --- a/src/components/CustomIcons/index.js +++ b/src/components/CustomIcons/index.js @@ -1,7 +1,7 @@ const VerifiedBadge = () => () const CommonThings = () => () -const SunSVG = () => () -const MoonSVG = () => () +const SunSVG = () => () +const MoonSVG = () => () const RobotOutlined = () => () const CustomIcons = {VerifiedBadge, CommonThings, SunSVG, MoonSVG, RobotOutlined} diff --git a/src/components/Layout/Secondary.less b/src/components/Layout/Secondary.less index d6612f53..5835a7f8 100755 --- a/src/components/Layout/Secondary.less +++ b/src/components/Layout/Secondary.less @@ -27,7 +27,7 @@ top: 25px; display: flex; position: absolute; - z-index: 1003; + z-index: 202; img { border-radius: 15px; width: 40px; @@ -49,7 +49,7 @@ } } .container{ - z-index: 1000; + z-index: 200; background-color: #201F23; color: @DarkMode-color_container !important; border-radius: 32px 0 0 32px; @@ -74,7 +74,7 @@ } .container_2{ - z-index: 1001; + z-index: 201; background-color: #fff; border-radius: 32px 0 0 32px; diff --git a/src/components/MainFeed/index.js b/src/components/MainFeed/index.js index aa615e00..64d1e5a7 100755 --- a/src/components/MainFeed/index.js +++ b/src/components/MainFeed/index.js @@ -120,7 +120,6 @@ class MainFeed extends React.Component {