Authored by 于良

代码目录结构调整

... ... @@ -22,7 +22,7 @@ import RNRF, {
Actions
} from 'react-native-router-flux';
import configureStore from './lib/configureStore';
import configureStore from './store/configureStore';
import {
setPlatform,
... ...
... ... @@ -8,22 +8,9 @@ export default keyMirror({
GET_GUIDE_DISPLAY: null,
SET_GUIDE_DISPLAY: null,
/*
SESSION_TOKEN_REQUEST: null,
SESSION_TOKEN_SUCCESS: null,
SESSION_TOKEN_FAILURE: null,
DELETE_TOKEN_REQUEST: null,
DELETE_TOKEN_SUCCESS: null,
ON_LOGIN_STATE_CHANGE: null,
LOGOUT: null,
ON_AUTH_FORM_FIELD_CHANGE: null,
SIGNUP_REQUEST: null,
SIGNUP_SUCCESS: null,
SIGNUP_FAILURE: null,
LOGIN_REQUEST: null,
LOGIN_SUCCESS: null,
LOGIN_FAILURE: null,
... ... @@ -32,15 +19,13 @@ export default keyMirror({
LOGOUT_SUCCESS: null,
LOGOUT_FAILURE: null,
LOGGED_IN: null,
LOGGED_OUT: null,
SET_SESSION_TOKEN: null,
RESET_PASSWORD_REQUEST: null,
RESET_PASSWORD_SUCCESS: null,
RESET_PASSWORD_FAILURE: null,
/*
GET_PROFILE_REQUEST: null,
GET_PROFILE_SUCCESS: null,
GET_PROFILE_FAILURE: null,
... ...
module.exports = {
API: {
baseUrl: '',
clientSecret: '',
},
storeKey: {
SESSION_TOKEN_KEY: 'SESSION_TOKEN_KEY',
GUIDE_STATE_KEY: 'GUIDE_STATE_KEY',
}
}
\ No newline at end of file
... ...
... ... @@ -16,6 +16,7 @@ import {Map} from 'immutable';
* Project actions
*/
import * as guideActions from '../reducers/guide/guideActions';
import * as userActions from '../reducers/user/userActions';
/**
* The components we need from ReactNative
... ... @@ -36,6 +37,7 @@ from 'react-native';
*/
const actions = [
guideActions,
userActions,
];
/**
... ... @@ -86,6 +88,8 @@ class App extends Component {
componentDidMount() {
this.props.actions.getDisplayState();
this.props.actions.login('lily', '111111');
}
render() {
... ...
... ... @@ -17,7 +17,7 @@ const {
SET_PLATFORM,
SET_VERSION,
SHOW_DOT
} = require ('../../lib/constants').default;
} = require('../../constants/actionTypes').default;
/**
* ## Set the platformState
... ...
... ... @@ -18,7 +18,7 @@ const {
SET_PLATFORM,
SET_VERSION,
SHOW_DOT
} = require('../../lib/constants').default;
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
... ...
... ... @@ -14,7 +14,7 @@
const {
GET_GUIDE_DISPLAY,
SET_GUIDE_DISPLAY
} = require ('../../lib/constants').default;
} = require('../../constants/actionTypes').default;
import {Actions} from 'react-native-router-flux';
... ...
... ... @@ -17,7 +17,7 @@ import InitialState from './guideInitialState';
const {
GET_GUIDE_DISPLAY,
SET_GUIDE_DISPLAY
} = require('../../lib/constants').default;
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
... ...
... ... @@ -6,3 +6,74 @@
*/
'use strict';
import {Actions} from 'react-native-router-flux';
import AppAuthToken from '../../services/AppAuthToken';
import UserService from '../../services/UserService';
const {
DELETE_TOKEN_REQUEST,
DELETE_TOKEN_SUCCESS,
LOGIN_REQUEST,
LOGIN_SUCCESS,
LOGIN_FAILURE,
LOGOUT_REQUEST,
LOGOUT_SUCCESS,
LOGOUT_FAILURE,
SET_SESSION_TOKEN,
RESET_PASSWORD_REQUEST,
RESET_PASSWORD_SUCCESS,
RESET_PASSWORD_FAILURE,
} = require('../../constants/actionTypes').default;
export function loginRequest() {
return {
type: LOGIN_REQUEST
};
}
export function loginSuccess(json) {
return {
type: LOGIN_SUCCESS,
payload: json
};
}
export function loginFailure(error) {
return {
type: LOGIN_FAILURE,
payload: error
};
}
export function login(account, password) {
return dispatch => {
dispatch(loginRequest());
return new UserService().login({
account: account,
password: password
})
.then(function (json) {
console.log(json);
return saveSessionToken(json)
.then(function () {
dispatch(loginSuccess(json));
Actions.Tabbar();
});
})
.catch((error) => {
console.error(error);
dispatch(loginFailure(error));
});
};
}
export function saveSessionToken(json) {
return new AppAuthToken().storeSessionToken(json);
}
\ No newline at end of file
... ...
... ... @@ -7,15 +7,29 @@
/**
* ## Import immutable record
*/
import {Record} from 'immutable';
import {List, Record} from 'immutable';
/**
* ## InitialState
*
* shops: List of
* new (Record({
* id: '',
* name: '',
* }))
*
* The fields we're concerned with
*/
let InitialState = Record({
error: null,
isValid: false,
isFetching: false,
profile: new (Record({
account: '',
pid: '',
sessionKey: '',
})),
shops: List(),
});
export default InitialState;
... ...
... ... @@ -11,7 +11,28 @@
*/
import InitialState from './userInitialState';
import Immutable, {List, Record} from 'immutable';
const {
DELETE_TOKEN_REQUEST,
DELETE_TOKEN_SUCCESS,
LOGIN_REQUEST,
LOGIN_SUCCESS,
LOGIN_FAILURE,
LOGOUT_REQUEST,
LOGOUT_SUCCESS,
LOGOUT_FAILURE,
SET_SESSION_TOKEN,
RESET_PASSWORD_REQUEST,
RESET_PASSWORD_SUCCESS,
RESET_PASSWORD_FAILURE,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
... ... @@ -25,9 +46,46 @@ export default function userReducer(state = initialState, action) {
switch (action.type) {
case LOGOUT_REQUEST:
case LOGIN_REQUEST:
case RESET_PASSWORD_REQUEST: {
let nextState = state.set('isFetching', true)
.set('error', null);
return nextState;
}
case LOGIN_SUCCESS: {
const {account, pid, sessionKey, shops} = action.payload;
let ShopRecord = Record({ id: '', name: '' })
let shopsList = Immutable.fromJS(shops, function(key, value) {
return new ShopRecord(value);
});
let nextState = state.set('isFetching', false)
.set('error', null)
.setIn(['profile', 'account'], account)
.setIn(['profile', 'pid'], pid)
.setIn(['profile', 'sessionKey'], sessionKey)
.set('shops', shopsList);
return nextState;
}
case LOGOUT_SUCCESS:
case RESET_PASSWORD_SUCCESS:
return state.set('isFetching', false);
case LOGOUT_FAILURE:
case LOGIN_FAILURE:
case RESET_PASSWORD_FAILURE:
return state.set('isFetching', false)
.set('error', action.payload);
case DELETE_TOKEN_REQUEST:
case DELETE_TOKEN_SUCCESS:
return state;
}
/**
* ## Default
*/
return state;
}
... ...
'use strict';
import store from 'react-native-simple-store';
import CONFIG from '../constants/config';
export default class AppAuthToken {
/**
* ## AppAuthToken
*
* set the key from the config
*/
constructor () {
this.SESSION_TOKEN_KEY = CONFIG.storeKey.SESSION_TOKEN_KEY;
}
/**
* ### storeSessionToken
* Store the session key
*/
storeSessionToken(sessionToken) {
return store.save(this.SESSION_TOKEN_KEY, {
sessionToken: sessionToken
});
}
/**
* ### getSessionToken
*/
getSessionToken() {
return store.get(this.SESSION_TOKEN_KEY);
}
/**
* ### deleteSessionToken
* Deleted during log out
*/
deleteSessionToken() {
return store.delete(this.SESSION_TOKEN_KEY);
}
}
... ...
'use strict';
export default class UserService {
login(account, password) {
return fetch('http://testapi.yoho.cn:28078/gateway?method=app.passport.signin&account=zhiyuan&password=lzy111111');
}
}
\ No newline at end of file
... ...