JWT Sign & Expire tokens

This commit is contained in:
srgooglo 2020-03-19 17:03:24 +01:00
parent dc35f86753
commit ee2c9b4b8c
11 changed files with 57 additions and 106 deletions

View File

@ -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

View File

@ -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)
});
}

View File

@ -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')
}
}

View File

@ -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;
let TokenContainer = Cookies.get('cid');
const a = Cookies.get('cid');
if (a) {
const modExp = ycore.DevOptions.SignForNotExpire;
const ad = jwt.decode(a)
if (TokenContainer) {
let TokenContainerDC = jwt.decode(TokenContainer)
if (TokenContainerDC){
ValidCookiesToken = true
let notexp = true; // Sets if this is expired (Default is not expired)
let exists = false; // Sets if this exist
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 (ycore.CryptSDCP.valid()){
ValidSDCP = true;
if (notexp && exists) {
validtoken = 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
}
}

View File

@ -1,7 +1,7 @@
const VerifiedBadge = () => (<svg xmlns="http://www.w3.org/2000/svg" fill="#55acee" width="15" height="15" viewBox="0 0 24 24"> <path d="M23 12l-2.44-2.78.34-3.68-3.61-.82-1.89-3.18L12 3 8.6 1.54 6.71 4.72l-3.61.81.34 3.68L1 12l2.44 2.78-.34 3.69 3.61.82 1.89 3.18L12 21l3.4 1.46 1.89-3.18 3.61-.82-.34-3.68L23 12m-13 5l-4-4 1.41-1.41L10 14.17l6.59-6.59L18 9l-8 8z"></path></svg>)
const CommonThings = () => (<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="#ff5991" d="M15,2C16.94,2 18.59,2.7 19.95,4.05C21.3,5.41 22,7.06 22,9C22,10.56 21.5,11.96 20.58,13.2C19.64,14.43 18.44,15.27 16.97,15.7L17,15.38V15C17,12.81 16.23,10.93 14.65,9.35C13.07,7.77 11.19,7 9,7H8.63L8.3,7.03C8.73,5.56 9.57,4.36 10.8,3.42C12.04,2.5 13.44,2 15,2M9,8A7,7 0 0,1 16,15A7,7 0 0,1 9,22A7,7 0 0,1 2,15A7,7 0 0,1 9,8M9,10A5,5 0 0,0 4,15A5,5 0 0,0 9,20A5,5 0 0,0 14,15A5,5 0 0,0 9,10Z"></path></svg>)
const SunSVG = () => (<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 21 21"><g fill="none" fill-rule="evenodd"><path fill="#fff" fill-rule="nonzero" d="M21 10.5l-3 3V18h-4.5l-3 3-3-3H3v-4.5l-3-3 3-3V3h4.5l3-3 3 3H18v4.5z"></path><circle stroke="#000" stroke-width="1.5" cx="10.5" cy="10.5" r="4"></circle></g></svg>)
const MoonSVG = () => (<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 21 21"><g fill="none" fill-rule="evenodd"><circle fill="#fff" cx="10.5" cy="10.5" r="10.5"></circle><path d="M13.396 11c0-3.019-1.832-5.584-4.394-6.566A6.427 6.427 0 0111.304 4C15.002 4 18 7.135 18 11c0 3.866-2.998 7-6.698 7A6.42 6.42 0 019 17.566c2.564-.98 4.396-3.545 4.396-6.566z" fill="#2F2E30" fill-rule="nonzero"></path></g></svg>)
const SunSVG = () => (<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 21 21"><g fill="none" fillRule="evenodd"><path fill="#fff" fillRule="nonzero" d="M21 10.5l-3 3V18h-4.5l-3 3-3-3H3v-4.5l-3-3 3-3V3h4.5l3-3 3 3H18v4.5z"></path><circle stroke="#000" strokeWidth="1.5" cx="10.5" cy="10.5" r="4"></circle></g></svg>)
const MoonSVG = () => (<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 21 21"><g fill="none" fillRule="evenodd"><circle fill="#fff" cx="10.5" cy="10.5" r="10.5"></circle><path d="M13.396 11c0-3.019-1.832-5.584-4.394-6.566A6.427 6.427 0 0111.304 4C15.002 4 18 7.135 18 11c0 3.866-2.998 7-6.698 7A6.42 6.42 0 019 17.566c2.564-.98 4.396-3.545 4.396-6.566z" fill="#2F2E30" fillRule="nonzero"></path></g></svg>)
const RobotOutlined = () => (<svg viewBox="64 64 896 896" focusable="false" class="" data-icon="robot" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M300 328a60 60 0 10120 0 60 60 0 10-120 0zM852 64H172c-17.7 0-32 14.3-32 32v660c0 17.7 14.3 32 32 32h680c17.7 0 32-14.3 32-32V96c0-17.7-14.3-32-32-32zm-32 660H204V128h616v596zM604 328a60 60 0 10120 0 60 60 0 10-120 0zm250.2 556H169.8c-16.5 0-29.8 14.3-29.8 32v36c0 4.4 3.3 8 7.4 8h729.1c4.1 0 7.4-3.6 7.4-8v-36c.1-17.7-13.2-32-29.7-32zM664 508H360c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h304c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8z"></path></svg>)
const CustomIcons = {VerifiedBadge, CommonThings, SunSVG, MoonSVG, RobotOutlined}

View File

@ -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;

View File

@ -120,7 +120,6 @@ class MainFeed extends React.Component {
<div id='mainfeed'>
{invalid?
<antd.Card style={{ borderRadius: "10px", maxWidth: '26.5vw', margin: 'auto', textAlign: 'center' }} >
<h2><Icons.ExclamationCircleOutlined /> Invalid Data </h2>
<span>If this error has occurred several times, try restarting the app</span>
</antd.Card>

View File

@ -1,14 +1,12 @@
import React, { Component } from 'react'
import {GetAuth, InitSDCP, DevOptions, asyncSDCP} from 'ycore';
import PropTypes from 'prop-types';
import { connect } from 'dva';
import { Form, Icon as LegacyIcon } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { Button, Input, Drawer, Collapse } from 'antd';
import styles from './index.less';
import formstyle from './formstyle.less'
import { Button, Input, Drawer } from 'antd';
import * as ycore from 'ycore'
import styles from './index.less';
const FormItem = Form.Item
@connect(({ loading }) => ({ loading }))
@ -23,7 +21,6 @@ class YulioID extends Component {
ShowLoading: false,
Answered: false,
}
this.handleRetry = this.handleRetry.bind(this);
}
// Handlers & others
handleUsername(text) {
@ -32,7 +29,7 @@ class YulioID extends Component {
handlePassword(text) {
this.setState({ RawPassword: text.target.value });
}
handleRetry() {
handleRetry = () => {
this.setState({ShowLoading: false, StateException: false, StateIcon: ''})
}
handleEnter = (e) => {
@ -52,7 +49,7 @@ class YulioID extends Component {
if (EncUsername && EncPassword){
this.setState({ ShowLoading: true, StateMessage: 'Wait a sec...' });
if (DevOptions.InfiniteLogin == true) {
if (ycore.DevOptions.InfiniteLogin == true) {
ycore.yconsole.log(prefix, 'InfiniteLogin is enabled! Disabled getAuth')
}
else {
@ -82,8 +79,6 @@ class YulioID extends Component {
const { visible } = this.props
const { getFieldDecorator } = this.props.form;
const { ShowLoading, StateIcon, StateMessage, StateException } = this.state;
const { Panel } = Collapse;
return (
<div className={styles.loginWrapper}>
@ -98,11 +93,6 @@ class YulioID extends Component {
<div className={styles.preheader}><h6><img src={"https://api.ragestudio.net/id.svg"} /> YulioID&trade;</h6>
<h1>Login</h1></div>
<main className={styles.mainlp}>
{/* <RenderInclude data={include} /> */}
<form className={styles.formlogin}>
{ShowLoading ? (
<div style={{ height: '329px' }}>
@ -111,7 +101,7 @@ class YulioID extends Component {
<div><br/><br/><br/>
<div className={styles.resultbox}>
<h6 > {StateMessage} </h6>
{StateException ? <div className={styles.retryBTN}><Button style={{ width: '270px' }} type='dashed' onClick={this.handleRetry}>Retry</Button></div> : null}
{StateException ? <div className={styles.retryBTN}><Button style={{ width: '270px' }} type='dashed' onClick={() => this.handleRetry()}>Retry</Button></div> : null}
</div>
</div>
</div>
@ -189,11 +179,4 @@ class YulioID extends Component {
}
}
YulioID.propTypes = {
form: PropTypes.object,
dispatch: PropTypes.func,
loading: PropTypes.object,
include: PropTypes.object,
}
export default YulioID

View File

@ -41,7 +41,6 @@ class BaseLayout extends PureComponent {
<Helmet>
<title>{config.siteName}</title>
</Helmet>
<Loader fullScreen spinning={loading.effects['app/query']} />
<Container>{children}</Container>
</Fragment>
)

View File

@ -25,7 +25,7 @@ class PrimaryLayout extends React.Component {
super(props)
window.PrimaryComponent = this;
this.state = {
collapsed: ycore.DevOptions.default_collapse_sider,
collapsed: (ycore.DevOptions.default_collapse_sider? true : false),
isMobile: false,
userData: ''
}
@ -53,7 +53,6 @@ class PrimaryLayout extends React.Component {
store.set('collapsed', !fromStore)
}
isDarkMode = () => {
const {app} = this.props
const { theme } = app
@ -69,7 +68,6 @@ class PrimaryLayout extends React.Component {
const { onCollapseChange } = this
const { theme } = app
const SiderProps = {
theme,
userData,

View File

@ -3,12 +3,10 @@ import React from 'react';
import * as ycore from 'ycore'
import * as antd from 'antd'
import * as Icons from '@ant-design/icons';
import $ from 'jquery'
import Icon from '@ant-design/icons'
import jwt from 'jsonwebtoken'
import styles from './style.less'
import { GridContent } from '@ant-design/pro-layout';
import { json } from 'body-parser';
const UserData = ycore.userData()
@ -40,7 +38,9 @@ export default class __m extends React.Component {
})
}
handleToken(){
this.setState({ s_token: ycore.handlerYIDT.get() })
const a = ycore.handlerYIDT.getRaw()
const b = jwt.decode(a)
this.setState({ s_token: b})
{ycore.ValidLoginSession(res => {
this.setState({s_ses: res})
})}
@ -55,7 +55,7 @@ export default class __m extends React.Component {
render() {
const arrayOfSDCP = Object.entries(UserData).map((e) => ( { [e[0]]: e[1] } ));
const { UserID, UserToken, deadline } = this.state.s_token
const { UserID, UserToken, expiresIn } = this.state.s_token
const { ValidSDCP, ValidCookiesToken, final } = this.state.s_ses
return (
<div className={styles.Wrapper}>
@ -73,9 +73,10 @@ export default class __m extends React.Component {
</antd.Card>
<antd.Card>
<h2><Icons.UserOutlined /> Current Session</h2>
<p> Raw => {JSON.stringify(this.state.s_token)} </p>
<p> UID => {UserID} </p>
<p> Session Token => {UserToken} </p>
<p> Deadline => {deadline} </p>
<p> expiresIn => {expiresIn} </p>
<hr />
<p> ValidSDCP => {JSON.stringify(ValidSDCP)} </p>
<p> ValidCookiesToken => {JSON.stringify(ValidCookiesToken)} </p>