Skip to content

Commit

Permalink
Authentication, App State, and basic App logic
Browse files Browse the repository at this point in the history
I'm implementing a production/development system., implementing an
application state system that simply updates the state when the
application is ready to be reloaded. Started to develop out my
authentication system. Using a localStorage token and UID system for
session control.
  • Loading branch information
cryptictech committed Aug 23, 2018
1 parent 4aaa29c commit f22ec53
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
package-lock.json
package-lock.json
88 changes: 88 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,95 @@ import OptionsPanel from './com_OptionsPanel.js';
import Core from './com_Core.js';
import Footer from './com_Footer.js';

//PRODUCTION BUILD CHECKLIST:
//Fork to staging
//Take out debug code
//Tune production settings
//Fork to production
//Upload changed production files.

class App extends Component {

//constructor: Set default application state.
constructor( props ){
super(props);

this.appstate = {
applicationState : {
state: 'AUTH', //RUNNING, CLOSING
env: {
type: 'DEV', //PRO, BETA
build: '0.1.0.1', //Major release. Minor release. Update. Development build number.
settings: {
authenticated: true //false
}
},
core: 'LOADING', //INV_MAIN, INV_COUNT, ORDER_OUT, ORDER_IN, FORECASTING
optionsPanel: 'CLOSED', //OPEN_APPSETTINGS, OPEN_USERSETTINGS
}
};

this.state = this.appstate;
}

//updateState: Update the state with the current application state so the app will rerender.
updateState () {
this.setState(this.appstate);
}

//componentWillMount: This is here to auth the user and load information on application start, perhaps to process runtime requests too.
componentWillMount(){
//Auth user, load information, redirect if necessary.

switch(this.state.applicationState.state){
case 'AUTH':
//This is where the real magic happens. This is where the application is going to authenticate itself and redirect if not authenticated.
//It will then load the information that it neads.

//Authentication
if(typeof(Storage) !== "undefined"){
if(localStorage.token !== undefined && localStorage.UID !== undefined){
//TODO: Add if statement to be able to turn off authenticated state.
$.ajax({
//TODO: Put in server URL
url: '',
method: 'POST',
data: {
module: 'AUTH_USER',
authToken: localStorage.token,
UID: localStorage.UID
}
}).done(function (){
//Function that is fired when the request comes back.
//TODO: Review Authentication.
//TODO: Load information
}.bind(this));
}else{
//User doesn't have access to this website.
//TODO: Redirect to login application.
if( this.appstate.applicationState.env.type == 'DEV' &&
this.appstate.applicationState.env.settings.authenticated ){
//TODO: Set localStorage state.
}
}
}else{
//No localstorage...
//TODO: Redirect to not supported page.
}

break;
case 'RUNNING':
//Might be cut because I can't think of a reason to calculate anything here right now.
break;
case 'CLOSING':
//Probably will be cut because I can't think of a reason for this to be here right now.
break;
default:
//This shouldn't happen. Notify server, review application variables, correct application, or reload.
break;
}
}

callback = (data) => {
console.log(data);
}
Expand Down

0 comments on commit f22ec53

Please sign in to comment.