Setup start of redux login action

This commit is contained in:
Jake Howard 2016-04-28 17:48:07 +01:00
parent 84855e36fd
commit 09e22b6eca
4 changed files with 15 additions and 30 deletions

View file

@ -1,4 +1,4 @@
import endpoints from './endpoints'; import endpoints from '../settings/endpoints';
import request from './request'; import request from './request';
import token from './token'; import token from './token';

View file

@ -2,9 +2,9 @@ import React from 'react-native';
import GlobalStyles from '../../settings/styles'; import GlobalStyles from '../../settings/styles';
import TokenHelp from '../login/token-help'; import TokenHelp from '../login/token-help';
import RouteMaster from './RouteMaster'; import RouteMaster from './RouteMaster';
import { checkToken } from '../../api/CircleCI';
import token from '../../api/token';
import loaderHandler from 'react-native-busy-indicator/LoaderHandler'; import loaderHandler from 'react-native-busy-indicator/LoaderHandler';
import { connect } from 'react-redux';
import { login }from '../../actions';
const dismissKeyboard = require('dismissKeyboard'); const dismissKeyboard = require('dismissKeyboard');
@ -76,7 +76,7 @@ const styles = StyleSheet.create({
} }
}); });
export default class Login extends React.Component { export class Login extends React.Component {
constructor() { constructor() {
super(); super();
this.state = { this.state = {
@ -101,18 +101,12 @@ export default class Login extends React.Component {
this.showTokenHelp = this.showTokenHelp.bind(this); this.showTokenHelp = this.showTokenHelp.bind(this);
this.hideTokenHelp = this.hideTokenHelp.bind(this); this.hideTokenHelp = this.hideTokenHelp.bind(this);
this.showAbout = this.showAbout.bind(this); this.showAbout = this.showAbout.bind(this);
this.proceed = this.proceed.bind(this);
} }
textChanged(CIToken) { textChanged(CIToken) {
this.setState({ token: CIToken }); this.setState({ token: CIToken });
} }
proceed() {
this.hideTokenHelp();
this.props.nav.replace(RouteMaster.get('HOME'));
}
invalidToken() { invalidToken() {
Alert.alert('Invalid', Alert.alert('Invalid',
'Token not accepted!', 'Token not accepted!',
@ -127,17 +121,7 @@ export default class Login extends React.Component {
loaderHandler.hideLoader(); loaderHandler.hideLoader();
return; return;
} }
checkToken(this.state.token).then(function (isValid) { this.props.login(this.state.token);
if (isValid) {
token.set(this.state.token).then(this.proceed);
} else {
this.invalidToken();
this.setState({
token: ''
});
}
loaderHandler.hideLoader();
}.bind(this)).catch(console.log);
} }
showAbout() { showAbout() {
@ -163,14 +147,6 @@ export default class Login extends React.Component {
componentWillMount() { componentWillMount() {
BackAndroid.addEventListener('hardwareBackPress', () => { return true; }); // Disable back button BackAndroid.addEventListener('hardwareBackPress', () => { return true; }); // Disable back button
token.get().then(function (CIToken) {
if (!CIToken) {
return;
}
checkToken(CIToken).then(function (isValid) {
this.proceed();
}.bind(this));
}.bind(this));
} }
componentDidMount() { componentDidMount() {
@ -223,3 +199,11 @@ export default class Login extends React.Component {
); );
} }
}; };
function mapStateToProps(state) {
return {
token: state.user.get('token')
};
}
export default connect(mapStateToProps, { login }) (Login);

View file

@ -4,5 +4,6 @@ export default Map({
PROJECT_DATA: { PROJECT_DATA: {
repository: 'https://github.com/RealOrangeOne/Sphere', repository: 'https://github.com/RealOrangeOne/Sphere',
CI_Badge: 'https://circleci.com/gh/RealOrangeOne/Sphere.svg?style=svg' CI_Badge: 'https://circleci.com/gh/RealOrangeOne/Sphere.svg?style=svg'
} },
STORAGE_KEY: 'SphereStorageKey'
}); });