mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 02:24:16 +00:00
yCore 8.4@Scoped Update
This commit is contained in:
parent
ed38aa12f2
commit
76e5c4f801
22
mock/user.js
22
mock/user.js
@ -1,31 +1,9 @@
|
||||
import { Mock, Constant, qs, randomAvatar } from './_utils'
|
||||
import bcrypt from 'bcryptjs';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import keys from '../config/keys.js';
|
||||
|
||||
const { ApiPrefix } = Constant
|
||||
const queryArray = (array, key, keyAlias = 'key') => {
|
||||
if (!(array instanceof Array)) {
|
||||
return null
|
||||
}
|
||||
let data
|
||||
|
||||
for (let item of array) {
|
||||
if (item[keyAlias] === key) {
|
||||
data = item
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (data) {
|
||||
return data
|
||||
}
|
||||
return null
|
||||
}
|
||||
const NOTFOUND = {
|
||||
message: 'API Route Not Found',
|
||||
documentation_url: 'http://localhost:8000/request',
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
[`POST ${ApiPrefix}/user/login`](req, res) {
|
||||
|
@ -1,3 +1,6 @@
|
||||
// List of modules uploaded to yCore
|
||||
export * from './libs/comty_ng/pre.js';
|
||||
export * from './libs/yulio_id/pre.js';
|
||||
export * from './libs/ycore_styles/pre.js';
|
||||
export * from './libs/ycore_styles/pre.js';
|
||||
export * from './libs/ycore_sdcp/pre.js';
|
||||
export * from './libs/control_bar/pre.js'
|
@ -84,13 +84,12 @@ export function GetFeedPosts(callback) {
|
||||
redirect: 'follow'
|
||||
};
|
||||
const objUrl = `${ycore.endpoints.get_userPostFeed}${ycore.GetUserToken.decrypted().UserToken}`
|
||||
console.log(objUrl)
|
||||
fetch(objUrl, requestOptions)
|
||||
.then(response => response.text())
|
||||
.then(result => {
|
||||
return callback( null, result)
|
||||
})
|
||||
.catch(error => console.log('error', error))
|
||||
.catch(error => console.log('Load Post error => ', error))
|
||||
}
|
||||
|
||||
export const get_app_session = {
|
||||
@ -143,4 +142,25 @@ export const get_app_session = {
|
||||
})
|
||||
.catch(error => console.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.DevOptions.ShowFunctionsLogs? console.log('Recived', global, 'sending to ', urlOBJ) : null
|
||||
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.DevOptions.ShowFunctionsLogs? console.log(response) : null
|
||||
});
|
||||
}
|
10
src/@ycore/libs/control_bar/pre.js
Normal file
10
src/@ycore/libs/control_bar/pre.js
Normal file
@ -0,0 +1,10 @@
|
||||
import {SetControls, CloseControls} from "../../../components/Layout/Control"
|
||||
|
||||
export const ControlBar = {
|
||||
set: (e) => {
|
||||
SetControls(e)
|
||||
},
|
||||
close: () => {
|
||||
CloseControls()
|
||||
}
|
||||
}
|
80
src/@ycore/libs/ycore_sdcp/pre.js
Normal file
80
src/@ycore/libs/ycore_sdcp/pre.js
Normal file
@ -0,0 +1,80 @@
|
||||
import * as ycore from 'ycore'
|
||||
|
||||
export const asyncSDCP = {
|
||||
setSDCP: function (value) {
|
||||
return Promise.resolve().then(function () {
|
||||
sessionStorage.setItem('SDCP', value);
|
||||
});
|
||||
},
|
||||
getSDCP: function () {
|
||||
return sessionStorage.getItem('SDCP');
|
||||
}
|
||||
};
|
||||
export function InitSDCP(values, done) {
|
||||
const prefix = '[InitSDCP]';
|
||||
let payload = {};
|
||||
if (!values) {
|
||||
const message = 'Missing payload! Exception while request data...';
|
||||
ycore.DevOptions.ShowFunctionsLogs? console.log(prefix, message) : null
|
||||
return;
|
||||
}
|
||||
payload.UserToken = values.UserToken;
|
||||
payload.UserID = values.UserID;
|
||||
if (payload) {
|
||||
ycore.GetUserData(payload, (err, response) =>
|
||||
{
|
||||
let cooked = JSON.parse(response)['user_data']
|
||||
let Ensamblator = btoa(JSON.stringify(cooked))
|
||||
ycore.asyncSDCP.setSDCP(Ensamblator).then(() => {
|
||||
ycore.DevOptions.ShowFunctionsLogs? console.log(prefix, ' SDCP Setup done') : null
|
||||
return done(true)
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
export function UpdateSDCP() {
|
||||
const prefix = '[UpdateSDCP]';
|
||||
ycore.GetUserData(null, (err, response) => {
|
||||
let cooked = JSON.parse(response)['user_data']
|
||||
let Lsdcp = [atob(sessionStorage.getItem('SDCP'))];
|
||||
let Nsdcp = [JSON.stringify(cooked)]
|
||||
const e1 = btoa(Lsdcp)
|
||||
const e2 = btoa(Nsdcp)
|
||||
const n = e1.localeCompare(e2)
|
||||
if (!e2) {
|
||||
console.log(prefix, 'API Returned empty response! We recommend to logout')
|
||||
return
|
||||
}
|
||||
if (e1 == e2) {
|
||||
console.log(prefix, 'SDCP Equality')
|
||||
}else{
|
||||
ycore.DevOptions.ShowFunctionsLogs? console.log(prefix, 'SDCP Update detected ! => ', n) : null
|
||||
ycore.DevOptions.ShowFunctionsLogs? console.debug(`Compare versions => NEW ${[e1]} || OLD ${[e2]} `) : null
|
||||
ycore.asyncSDCP.setSDCP(e2)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
export function SDCP() {
|
||||
const prefix = '[SDCPCooker]';
|
||||
let SDCPContainer = sessionStorage.getItem('SDCP')
|
||||
if (SDCPContainer) {
|
||||
try {
|
||||
atob(SDCPContainer);
|
||||
} catch (err) {
|
||||
console.error(prefix, err)
|
||||
ycore.router.push({pathname: '/login',})
|
||||
return null
|
||||
}
|
||||
try {
|
||||
let decodedSDCP = atob(SDCPContainer);
|
||||
let parsedSDCP = JSON.parse(decodedSDCP);
|
||||
return parsedSDCP;
|
||||
} catch (err) {
|
||||
console.error(prefix, err)
|
||||
ycore.router.push({pathname: '/login',})
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,218 @@
|
||||
export function init(){
|
||||
console.log('Init pass!! yulioid')
|
||||
import * as ycore from 'ycore'
|
||||
import * as antd from 'antd'
|
||||
import Cookies from "ts-cookies";
|
||||
import keys from '../../../../config/keys.js';
|
||||
|
||||
var jquery = require("jquery");
|
||||
var jwt = require("jsonwebtoken")
|
||||
|
||||
function __API__User (payload){
|
||||
var ExpireTime = '1556952'
|
||||
const now = new Date()
|
||||
now.setDate(now.getDate() + 1)
|
||||
const { UserID, UserToken } = payload
|
||||
const frame = { UserID, UserToken, deadline: now.getTime()}
|
||||
console.debug(frame)
|
||||
jwt.sign(
|
||||
frame,
|
||||
keys.secretOrKey,
|
||||
{ expiresIn: ExpireTime },
|
||||
(err, token) => {
|
||||
Cookies.set('token', token)
|
||||
ycore.RefreshONCE()
|
||||
}
|
||||
)
|
||||
}
|
||||
export function ValidLoginSession(){
|
||||
const prefix = '[YID Session]';
|
||||
let final = false;
|
||||
let ValidCookiesToken = false;
|
||||
let ValidSDCP = false;
|
||||
let TokenContainer = Cookies.get('token');
|
||||
let SDCPContainer = ycore.asyncSDCP.getSDCP();
|
||||
if (TokenContainer) {
|
||||
let TokenContainerDC = jwt.decode(TokenContainer)
|
||||
if (TokenContainerDC){
|
||||
ValidCookiesToken = true
|
||||
}
|
||||
}
|
||||
if (SDCPContainer) {
|
||||
try {
|
||||
atob(SDCPContainer)
|
||||
ValidSDCP = true
|
||||
} catch (error) {
|
||||
return
|
||||
}
|
||||
}
|
||||
if (ValidCookiesToken == true && ValidSDCP == true) {final = true}
|
||||
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
|
||||
return final
|
||||
}
|
||||
export function ValidBackup(){
|
||||
let ValidBackupToken = false;
|
||||
let LastestToken = localStorage.getItem('last_backup');
|
||||
if (LastestToken) {
|
||||
let LastestTokenDC = jwt.decode(LastestToken)
|
||||
if (LastestTokenDC){
|
||||
ValidBackupToken = true
|
||||
}
|
||||
}
|
||||
return ValidBackupToken;
|
||||
}
|
||||
export function MakeBackup(){
|
||||
if (ValidBackup() == false) {
|
||||
ycore.asyncLocalStorage.setItem('last_backup', Cookies.get('token'))
|
||||
return
|
||||
}
|
||||
}
|
||||
export function LogoutCall(){
|
||||
const prefix = ('[YID Session] ')
|
||||
console.log('Logout Called !')
|
||||
let DecodedToken = ycore.GetUserToken.decrypted().UserToken || atob(localStorage.getItem('last_backup'))
|
||||
const urlOBJ = (`${ycore.endpoints.removeToken}${DecodedToken}`)
|
||||
ycore.DevOptions.ShowFunctionsLogs? console.log(prefix, ' Login out with token => ', DecodedToken, urlOBJ) : null
|
||||
const form = new FormData();
|
||||
form.append("server_key", ycore.yConfig.server_key);
|
||||
const settings = {
|
||||
"url": urlOBJ,
|
||||
"method": "POST",
|
||||
"timeout": 0,
|
||||
"processData": false,
|
||||
"mimeType": "multipart/form-data",
|
||||
"contentType": false,
|
||||
"data": form
|
||||
};
|
||||
jquery.ajax(settings)
|
||||
.done((response) => {
|
||||
const api_state = JSON.parse(response)['api_status']
|
||||
console.log(`Exit with => ${api_state}`)
|
||||
if (api_state == '404') {
|
||||
antd.notification.open({
|
||||
placement: 'topLeft',
|
||||
message: 'Unexpectedly failed logout in YulioID™ ',
|
||||
description: 'It seems that your token has been removed unexpectedly and could not log out from YulioID ',
|
||||
icon: <antd.Icon type="warning" style={{ color: 'orange' }} />
|
||||
})
|
||||
console.log("Failed logout with YulioID™", response)
|
||||
}
|
||||
else {
|
||||
console.log("Successful logout with YulioID™", response, urlOBJ)
|
||||
}
|
||||
// Runtime after dispatch API
|
||||
sessionStorage.clear()
|
||||
Cookies.remove('token')
|
||||
ycore.router.push({pathname: '/login',})
|
||||
})
|
||||
}
|
||||
export function GetAuth(EncUsername, EncPassword, callback) {
|
||||
const prefix = '[Auth Server]:';
|
||||
if (!EncUsername || !EncPassword) {
|
||||
const message = 'Missing Data! Process Aborted...';
|
||||
console.log(prefix, message);
|
||||
}
|
||||
const server_key = ycore.yConfig.server_key;
|
||||
let username = atob(EncUsername);
|
||||
let password = atob(EncPassword);
|
||||
const form = new FormData();
|
||||
form.append("server_key", server_key);
|
||||
form.append("username", username);
|
||||
form.append("password", password);
|
||||
const settings = {
|
||||
"url": ycore.endpoints.auth_endpoint,
|
||||
"method": "POST",
|
||||
"timeout": 0,
|
||||
"processData": false,
|
||||
"mimeType": "multipart/form-data",
|
||||
"contentType": false,
|
||||
"data": form
|
||||
};
|
||||
jquery.ajax(settings)
|
||||
.done(function (response) {
|
||||
console.log(prefix, 'Server response... Dispathing data to login API...');
|
||||
var identState = JSON.parse(response)['api_status'];
|
||||
if (identState == 200) {
|
||||
const UserID = JSON.parse(response)['user_id'];
|
||||
const UserToken = JSON.parse(response)['access_token'];
|
||||
let FramePayload = { UserID, UserToken }
|
||||
ycore.DevOptions.ShowFunctionsLogs ? console.log(FramePayload) : null
|
||||
callback(null, '200')
|
||||
ycore.InitSDCP(FramePayload, (done) => done? __API__User(FramePayload) : null )
|
||||
}
|
||||
if (identState == 400) {
|
||||
callback(null, '400')
|
||||
}
|
||||
return;
|
||||
})
|
||||
.fail(function (response) {
|
||||
const exception = new Error("Server failed response . . . :( ");
|
||||
return;
|
||||
})
|
||||
}
|
||||
export const GetUserToken = {
|
||||
decrypted: function () {
|
||||
let final = jwt.decode(Cookies.get('token')) || jwt.decode(localStorage.getItem('last_backup'));
|
||||
const FC = jwt.decode(Cookies.get('token'))
|
||||
const FB = jwt.decode(localStorage.getItem('last_backup'))
|
||||
if (!FC && !FB) {
|
||||
final = false
|
||||
return final
|
||||
}
|
||||
if (!FC) {
|
||||
final = FB
|
||||
}
|
||||
if (!FB) {
|
||||
final = FC
|
||||
}
|
||||
console.log(final)
|
||||
return final
|
||||
},
|
||||
raw: function () {
|
||||
return Cookies.get('token') || localStorage.getItem('last_backup');
|
||||
},
|
||||
}
|
||||
export function GetUserData (values, callback) {
|
||||
const prefix = '[YID SDCP]';
|
||||
const offlineAPI = ycore.GetUserToken.decrypted();
|
||||
const globalValue = values || {UserToken: offlineAPI.UserToken, UserID: offlineAPI.UserID};
|
||||
const usertoken = globalValue.UserToken
|
||||
const userid = globalValue.UserID
|
||||
if (!globalValue) {
|
||||
const message = 'Missing payload! Exception while request data... Maybe the user is not login';
|
||||
ycore.DevOptions.ShowFunctionsLogs? console.log(prefix, message) : null
|
||||
return;
|
||||
}
|
||||
const ApiPayload = new FormData();
|
||||
ApiPayload.append("server_key", ycore.yConfig.server_key);
|
||||
ApiPayload.append("fetch", 'user_data');
|
||||
ApiPayload.append("user_id", userid);
|
||||
const urlOBJ = (`${ycore.endpoints.get_userData_endpoint}${usertoken}`)
|
||||
const settings = {
|
||||
"url": urlOBJ,
|
||||
"method": "POST",
|
||||
"timeout": 0,
|
||||
"processData": false,
|
||||
"mimeType": "multipart/form-data",
|
||||
"contentType": false,
|
||||
"data": ApiPayload
|
||||
}
|
||||
jquery.ajax(settings)
|
||||
.done(
|
||||
function (response) {
|
||||
let resString = JSON.stringify(response);
|
||||
let resParsed = JSON.parse(resString);
|
||||
callback(null, resParsed)
|
||||
}
|
||||
)
|
||||
.fail(
|
||||
function (response) {
|
||||
ycore.DevOptions.ShowFunctionsLogs ? console.log(prefix, 'Server failure!', response) : null
|
||||
callback(true, response )
|
||||
}
|
||||
)
|
||||
}
|
@ -1,27 +1,17 @@
|
||||
import { cloneDeep, isString, flow, curry } from 'lodash';
|
||||
import umiRouter from 'umi/router';
|
||||
import Cookies from "ts-cookies";
|
||||
import axios from "axios";
|
||||
import {SetControls, CloseControls} from ".././components/Layout/Control"
|
||||
import {secretOrKey} from "../../config/keys.js"
|
||||
import * as antd from "antd"
|
||||
|
||||
import * as lib from'./libs.js'
|
||||
import './libs.js'
|
||||
export * from "./libs.js"
|
||||
|
||||
var react = require("react");
|
||||
var package_json = require("../../package.json");
|
||||
var jquery = require("jquery");
|
||||
var config = require("config");
|
||||
var utils = require("utils");
|
||||
var { router } = require("utils")
|
||||
var jwt = require("jsonwebtoken")
|
||||
|
||||
export var { router } = require("utils")
|
||||
export var endpoints = config.Endpoints;
|
||||
export var DevOptions = config.DevOptions;
|
||||
export var yConfig = config.yConfig;
|
||||
|
||||
|
||||
export function booleanFix(e){
|
||||
if(e == 1){
|
||||
return true
|
||||
@ -53,28 +43,6 @@ export function notifyProccess(cust){
|
||||
placement: 'bottomLeft'
|
||||
})
|
||||
}
|
||||
export function InitSocket(id, params){
|
||||
console.log('Starting socket with _id: ', id)
|
||||
const defaultParams = {fullscreen: true, collapse: true}
|
||||
let globalParm;
|
||||
|
||||
if (!params) {
|
||||
globalParm = defaultParams;
|
||||
}else{
|
||||
globalParm = params;
|
||||
}
|
||||
|
||||
if (id) {
|
||||
console.log(globalParm)
|
||||
globalParm.fullscreen? requestFullscreen() : null;
|
||||
globalParm.collapse? null : null;
|
||||
Cookies.set('inApp', true)
|
||||
router.push({pathname: `/socket/${id}`,})
|
||||
}
|
||||
else{
|
||||
console.error('Failure starting the app... Invalid or Missing ID')
|
||||
}
|
||||
}
|
||||
export function requestFullscreen(){
|
||||
var elem = document.documentElement;
|
||||
if (elem.requestFullscreen) {
|
||||
@ -111,368 +79,6 @@ export const asyncSessionStorage = {
|
||||
});
|
||||
}
|
||||
};
|
||||
export const asyncSDCP = {
|
||||
setSDCP: function (value) {
|
||||
return Promise.resolve().then(function () {
|
||||
sessionStorage.setItem('SDCP', value);
|
||||
});
|
||||
},
|
||||
getSDCP: function () {
|
||||
return sessionStorage.getItem('SDCP');
|
||||
}
|
||||
};
|
||||
export const ControlBar = {
|
||||
set: (e) => {
|
||||
SetControls(e)
|
||||
},
|
||||
close: () => {
|
||||
CloseControls()
|
||||
}
|
||||
}
|
||||
export function SyncSocketAccount(title, socket, logo) {
|
||||
DevOptions.ShowFunctionsLogs? console.log('Initialising auth for ', title) : null
|
||||
const signkey = secretOrKey;
|
||||
const ExpireTime = '300';
|
||||
const key = {title, socket, logo}
|
||||
const ckey = jwt.sign(
|
||||
key,
|
||||
signkey,
|
||||
{ expiresIn: ExpireTime },
|
||||
)
|
||||
DevOptions.ShowFunctionsLogs? console.log(key, jwt.decode(ckey)) : null
|
||||
asyncLocalStorage.setItem('AUTHRES', ckey).then(
|
||||
window.open('/ec/authorize', title, "height=589,width=511")
|
||||
)
|
||||
}
|
||||
export function GetAuthSocket(sc, values) {
|
||||
const prefix = '[YID Sync]'
|
||||
if (!sc) {
|
||||
DevOptions.ShowFunctionsLogs? console.warn(prefix, 'Socket API missing!') : null
|
||||
return
|
||||
}
|
||||
const PayloadData = new FormData();
|
||||
PayloadData.append("server_key", yConfig.server_key);
|
||||
}
|
||||
export function ValidLoginSession(){
|
||||
const prefix = '[YID Session]';
|
||||
let final = false;
|
||||
let ValidCookiesToken = false;
|
||||
let ValidSDCP = false;
|
||||
let TokenContainer = Cookies.get('token');
|
||||
let SDCPContainer = asyncSDCP.getSDCP();
|
||||
if (TokenContainer) {
|
||||
let TokenContainerDC = jwt.decode(TokenContainer)
|
||||
if (TokenContainerDC){
|
||||
ValidCookiesToken = true
|
||||
}
|
||||
}
|
||||
if (SDCPContainer) {
|
||||
try {
|
||||
atob(SDCPContainer)
|
||||
ValidSDCP = true
|
||||
} catch (error) {
|
||||
return
|
||||
}
|
||||
}
|
||||
if (ValidCookiesToken == true && ValidSDCP == true) {final = true}
|
||||
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
|
||||
return final
|
||||
}
|
||||
export function ValidBackup(){
|
||||
const prefix = '[YID SessionState]';
|
||||
let ValidBackupToken = false;
|
||||
let LastestToken = localStorage.getItem('last_backup');
|
||||
if (LastestToken) {
|
||||
let LastestTokenDC = jwt.decode(LastestToken)
|
||||
if (LastestTokenDC){
|
||||
ValidBackupToken = true
|
||||
}
|
||||
}
|
||||
return ValidBackupToken;
|
||||
}
|
||||
export function MakeBackup(){
|
||||
if (ValidBackup() == false) {
|
||||
asyncLocalStorage.setItem('last_backup', Cookies.get('token'))
|
||||
return
|
||||
}
|
||||
}
|
||||
export function LogoutCall(){
|
||||
const prefix = ('[YID Session] ')
|
||||
console.log('Logout Called !')
|
||||
let DecodedToken = GetUserToken.decrypted().userToken
|
||||
if (DecodedToken == false) {
|
||||
antd.notification.open({
|
||||
placement: 'topLeft',
|
||||
message: 'Unexpectedly failed logout in YulioID™ ',
|
||||
description: 'It seems that your token has been removed unexpectedly and could not log out from YulioID ',
|
||||
icon: <antd.Icon type="warning" style={{ color: 'orange' }} />
|
||||
})
|
||||
router.push({pathname: '/login',})
|
||||
return
|
||||
}
|
||||
const urlOBJ = "" + endpoints.removeToken + DecodedToken;
|
||||
DevOptions.ShowFunctionsLogs? console.log(prefix, ' Login out with token => ', DecodedToken, urlOBJ) : null
|
||||
const form = new FormData();
|
||||
form.append("server_key", yConfig.server_key);
|
||||
const settings = {
|
||||
"url": urlOBJ,
|
||||
"method": "POST",
|
||||
"timeout": 0,
|
||||
"processData": false,
|
||||
"mimeType": "multipart/form-data",
|
||||
"contentType": false,
|
||||
"data": form
|
||||
};
|
||||
jquery.ajax(settings)
|
||||
.done((response) => {
|
||||
const api_state = JSON.parse(response)['api_status']
|
||||
console.log(`Exit with => ${api_state}`)
|
||||
if (api_state == '404') {
|
||||
antd.notification.open({
|
||||
placement: 'topLeft',
|
||||
message: 'Unexpectedly failed logout in YulioID™ ',
|
||||
description: 'It seems that your token has been removed unexpectedly and could not log out from YulioID ',
|
||||
icon: <antd.Icon type="warning" style={{ color: 'orange' }} />
|
||||
})
|
||||
}
|
||||
else {
|
||||
console.log("Successful logout in YulioID™", response, urlOBJ)
|
||||
}
|
||||
// Runtime after dispatch API
|
||||
sessionStorage.clear()
|
||||
Cookies.remove('token')
|
||||
router.push({pathname: '/login',})
|
||||
})
|
||||
}
|
||||
export function GetAuth(EncUsername, EncPassword, callback) {
|
||||
const prefix = '[Auth Server]:';
|
||||
if (!EncUsername || !EncPassword) {
|
||||
const message = 'Missing Data! Process Aborted...';
|
||||
console.log(prefix, message);
|
||||
}
|
||||
const server_key = yConfig.server_key;
|
||||
let username = atob(EncUsername);
|
||||
let password = atob(EncPassword);
|
||||
const form = new FormData();
|
||||
form.append("server_key", server_key);
|
||||
form.append("username", username);
|
||||
form.append("password", password);
|
||||
const settings = {
|
||||
"url": endpoints.auth_endpoint,
|
||||
"method": "POST",
|
||||
"timeout": 0,
|
||||
"processData": false,
|
||||
"mimeType": "multipart/form-data",
|
||||
"contentType": false,
|
||||
"data": form
|
||||
};
|
||||
jquery.ajax(settings)
|
||||
.done(function (response) {
|
||||
console.log(prefix, 'Server response... Dispathing data to login API...');
|
||||
return callback(null, response);
|
||||
})
|
||||
.fail(function (response) {
|
||||
const exception = new Error("Server failed response . . . :( ");
|
||||
return callback(exception, response);
|
||||
})
|
||||
}
|
||||
export const GetUserToken = {
|
||||
decrypted: function () {
|
||||
let final = jwt.decode(Cookies.get('token')) || jwt.decode(localStorage.getItem('last_backup'));
|
||||
const FC = jwt.decode(Cookies.get('token'))
|
||||
const FB = jwt.decode(localStorage.getItem('last_backup'))
|
||||
if (!FC && !FB) {
|
||||
final = false
|
||||
return final
|
||||
}
|
||||
if (!FC) {
|
||||
final = FB
|
||||
}
|
||||
if (!FB) {
|
||||
final = FC
|
||||
}
|
||||
console.log(final)
|
||||
return final
|
||||
},
|
||||
raw: function () {
|
||||
return Cookies.get('token') || localStorage.getItem('last_backup');
|
||||
}
|
||||
}
|
||||
export function GetUserData (values, customPayload, callback) {
|
||||
const prefix = '[YID SDCP]';
|
||||
const request = 'user_data' || customPayload;
|
||||
const globalValue = values || GetUserToken.decrypted();
|
||||
const usertoken = globalValue.UserToken
|
||||
const userid = globalValue.UserID
|
||||
if (!globalValue) {
|
||||
const message = 'Missing payload! Exception while request data... Maybe the user is not login';
|
||||
DevOptions.ShowFunctionsLogs? console.log(prefix, message) : null
|
||||
return;
|
||||
}
|
||||
const ApiPayload = new FormData();
|
||||
ApiPayload.append("server_key", yConfig.server_key);
|
||||
ApiPayload.append("fetch", request);
|
||||
ApiPayload.append("user_id", userid);
|
||||
const uri = endpoints.get_userData_endpoint;
|
||||
const urlOBJ = "" + uri + usertoken;
|
||||
const settings = {
|
||||
"url": urlOBJ,
|
||||
"method": "POST",
|
||||
"timeout": 0,
|
||||
"processData": false,
|
||||
"mimeType": "multipart/form-data",
|
||||
"contentType": false,
|
||||
"data": ApiPayload
|
||||
}
|
||||
jquery.ajax(settings)
|
||||
.done(
|
||||
function (response) {
|
||||
let resString = JSON.stringify(response);
|
||||
let resParsed = JSON.parse(resString);
|
||||
DevOptions.ShowFunctionsLogs ? console.log(prefix, 'Fechted user data...' ) : null
|
||||
callback( resParsed )
|
||||
}
|
||||
)
|
||||
.fail(
|
||||
function (response) {
|
||||
DevOptions.ShowFunctionsLogs ? console.log(prefix, 'Server failure!', response) : null
|
||||
callback( null )
|
||||
}
|
||||
)
|
||||
}
|
||||
export function InitSDCP(values, done) {
|
||||
const prefix = '[InitSDCP]';
|
||||
let payload = {};
|
||||
if (!values) {
|
||||
const message = 'Missing payload! Exception while request data...';
|
||||
DevOptions.ShowFunctionsLogs? console.log(prefix, message) : null
|
||||
return;
|
||||
}
|
||||
payload.UserToken = values.UserToken;
|
||||
payload.UserID = values.UserID;
|
||||
if (payload) {
|
||||
GetUserData(payload, {}, (callback) =>
|
||||
{
|
||||
let cooked = JSON.parse(callback)['user_data']
|
||||
let Ensamblator = btoa(JSON.stringify(cooked))
|
||||
asyncSDCP.setSDCP(Ensamblator).then(() => {
|
||||
DevOptions.ShowFunctionsLogs? console.log(prefix, ' SDCP Setup done') : null
|
||||
return done(true)
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
export function UpdateSDCP() {
|
||||
const prefix = '[UpdateSDCP]';
|
||||
GetUserData(null, null, (callback) => {
|
||||
let cooked = JSON.parse(callback)['user_data']
|
||||
let Lsdcp = [atob(sessionStorage.getItem('SDCP'))];
|
||||
let Nsdcp = [JSON.stringify(cooked)]
|
||||
const e1 = btoa(Lsdcp)
|
||||
const e2 = btoa(Nsdcp)
|
||||
const n = e1.localeCompare(e2)
|
||||
if (e1 == e2) {
|
||||
console.log(prefix, 'SDCP Equality')
|
||||
}else{
|
||||
DevOptions.ShowFunctionsLogs? console.log(prefix, 'SDCP Update detected ! => ', n) : null
|
||||
asyncSDCP.setSDCP(e2)
|
||||
}
|
||||
})
|
||||
}
|
||||
export function SDCP() {
|
||||
const prefix = '[SDCPCooker]';
|
||||
let SDCPContainer = sessionStorage.getItem('SDCP')
|
||||
if (SDCPContainer) {
|
||||
try {
|
||||
let decodedSDCP = atob(SDCPContainer);
|
||||
} catch (err) {
|
||||
console.error(prefix, err)
|
||||
router.push({pathname: '/login',})
|
||||
return null
|
||||
}
|
||||
try {
|
||||
let decodedSDCP = atob(SDCPContainer);
|
||||
let parsedSDCP = JSON.parse(decodedSDCP);
|
||||
return parsedSDCP;
|
||||
} catch (err) {
|
||||
console.error(prefix, err)
|
||||
router.push({pathname: '/login',})
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
export function PushUserData(inputIO1, inputIO2) {
|
||||
var getStoragedToken = Cookies.get('access_token');
|
||||
var _this = this;
|
||||
var yCore_GUDEP = endpoints.update_userData_endpoint;
|
||||
var urlOBJ = "" + yCore_GUDEP + getStoragedToken;
|
||||
DevOptions.ShowFunctionsLogs? console.log('Recived', global, 'sending to ', urlOBJ) : null
|
||||
var form = new FormData();
|
||||
form.append("server_key", 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) {
|
||||
DevOptions.ShowFunctionsLogs? console.log(response) : null
|
||||
});
|
||||
}
|
||||
export function GetGlobalMarketplaceSource() {
|
||||
let global;
|
||||
let TokenContainer = Cookies.get('token') || localStorage.getItem('last_backup');
|
||||
let DecodedToken = jwt.decode(TokenContainer)
|
||||
let usertoken = DecodedToken.UserToken;
|
||||
const uri = endpoints.get_marketplace_global;
|
||||
const urlOBJ = "" + uri + usertoken;
|
||||
(async () => {
|
||||
const response = await axios({
|
||||
url: urlOBJ,
|
||||
method: 'get'
|
||||
})
|
||||
global = response.data
|
||||
console.log(response.data, global)
|
||||
return {global};
|
||||
})()
|
||||
}
|
||||
export function DetectNoNStableBuild(e1) {
|
||||
switch (e1) {
|
||||
case 'TagComponent':
|
||||
if (package_json.DevBuild == true) {
|
||||
return react.createElement(antd.Tag, { color: 'orange' }, " No Stable");
|
||||
}
|
||||
if (package_json.DevBuild == false) {
|
||||
return react.createElement(antd.Tag, { color: 'blue' }, " Stable");
|
||||
}
|
||||
else {
|
||||
return ('No Stable');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (package_json.DevBuild == true) {
|
||||
return ('No Stable');
|
||||
}
|
||||
if (package_json.DevBuild == false) {
|
||||
return ('Stable');
|
||||
}
|
||||
else {
|
||||
return ('No Stable');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
export function RefreshONCE(){
|
||||
window.location.reload();
|
||||
}
|
||||
|
@ -43,8 +43,6 @@ class YulioID extends Component {
|
||||
var EncPassword = btoa(RawPassword);
|
||||
var EncUsername = btoa(RawUsername);
|
||||
|
||||
const OriginalPayload = {EncUsername, EncPassword}
|
||||
|
||||
if (!EncUsername || !EncPassword) {
|
||||
var message = 'Incomplete information!'
|
||||
console.log(prefix, message)
|
||||
@ -57,24 +55,16 @@ class YulioID extends Component {
|
||||
}
|
||||
else {
|
||||
console.log(prefix, 'Initialising login process...')
|
||||
GetAuth(EncUsername, EncPassword, (exception, response) => exception? this.handleResponse(response) : ( this.setState({ AuthResponse: response }), this.handleResponse(response, OriginalPayload) ))
|
||||
GetAuth(EncUsername, EncPassword, (exception, response) => this.handleResponse(response))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
handleResponse = (response) => {
|
||||
var identState = JSON.parse(response)['api_status'];
|
||||
if (identState == 200) {
|
||||
const { dispatch } = this.props;
|
||||
const UserID = JSON.parse(response)['user_id'];
|
||||
const UserToken = JSON.parse(response)['access_token'];
|
||||
let FramePayload = { UserID, UserToken }
|
||||
DevOptions.ShowFunctionsLogs ? console.log(FramePayload) : null
|
||||
if (response == '200') {
|
||||
this.setState({ StateIcon: 'login', StateMessage: 'Wait a sec...', StateException: false })
|
||||
InitSDCP({UserID, UserToken}, (done) => done? dispatch({type: 'login/login', payload: FramePayload}) : null )
|
||||
}
|
||||
if (identState == 400) {
|
||||
if (response == '400') {
|
||||
this.setState({ StateIcon: 'exclamation-circle', StateMessage: 'Invalid credentials', StateException: true })
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user