login saga[2]
This commit is contained in:
parent
9553ecbcaf
commit
f269a6d36b
|
@ -1,10 +1,9 @@
|
|||
import * as types from './actionsTypes';
|
||||
|
||||
export function loginRequest(email, password) {
|
||||
export function loginRequest(credentials) {
|
||||
return {
|
||||
type: types.LOGIN.REQUEST,
|
||||
email,
|
||||
password
|
||||
credentials
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import { createStore, applyMiddleware } from 'redux';
|
|||
import createSagaMiddleware from 'redux-saga';
|
||||
import logger from 'redux-logger';
|
||||
import rootReducer from '../reducers/rootReducer';
|
||||
import helloSaga from '../sagas/hello';
|
||||
import sagas from '../sagas';
|
||||
|
||||
const sagaMiddleware = createSagaMiddleware();
|
||||
let middleware;
|
||||
|
@ -22,4 +22,4 @@ export default createStore(
|
|||
rootReducer,
|
||||
applyMiddleware(sagaMiddleware)
|
||||
);
|
||||
sagaMiddleware.run(helloSaga);
|
||||
sagaMiddleware.run(sagas);
|
||||
|
|
|
@ -123,6 +123,7 @@ const RocketChat = {
|
|||
},
|
||||
|
||||
loginWithPassword({ username, password, code }, callback) {
|
||||
console.log('AQQQQQ');
|
||||
let params = {};
|
||||
const state = reduxStore.getState();
|
||||
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
import { take, fork } from 'redux-saga/effects';
|
||||
import 'babel-polyfill';
|
||||
import 'regenerator-runtime/runtime';
|
||||
|
||||
|
||||
const foreverAlone = function* foreverAlone() {
|
||||
yield take('FOI');
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
import { take, fork } from 'redux-saga/effects';
|
||||
import hello from './hello';
|
||||
import login from './login';
|
||||
|
||||
const root = function* root() {
|
||||
yield fork(hello);
|
||||
yield fork(login);
|
||||
};
|
||||
// Consider using takeEvery
|
||||
export default root;
|
||||
|
||||
|
||||
//
|
||||
// import { take, fork } from 'redux-saga/effects';
|
||||
// import 'babel-polyfill';
|
||||
// import 'regenerator-runtime/runtime';
|
||||
//
|
||||
//
|
||||
// const foreverAlone = function* foreverAlone() {
|
||||
// yield take('FOI');
|
||||
// console.log('FOIIIIIII');
|
||||
// yield take('voa');
|
||||
// console.log('o');
|
||||
// };
|
||||
//
|
||||
// const root = function* root() {
|
||||
// yield fork(foreverAlone);
|
||||
// };
|
||||
//
|
||||
// export default root;
|
|
@ -1,5 +1,5 @@
|
|||
import React from 'react';
|
||||
import { take, put, call, fork, select } from 'redux-saga/effects';
|
||||
import { take, put, call, fork } from 'redux-saga/effects';
|
||||
import * as types from '../actions/actionsTypes';
|
||||
import { loginSuccess, loginFailure } from '../actions/login';
|
||||
import RocketChat from '../lib/rocketchat';
|
||||
|
@ -8,20 +8,20 @@ function loginCall(...args) {
|
|||
return RocketChat.loginWithPassword(...args);
|
||||
}
|
||||
|
||||
function* watchLoginRequest() {
|
||||
const watchLoginRequest = function* watchLoginRequest() {
|
||||
while (true) {
|
||||
// yield take('METEOR_CONNECTED');
|
||||
const payload = yield take(types.LOGIN.REQUEST);
|
||||
try {
|
||||
const response = yield call(loginCall, payload);
|
||||
yield put(loginSuccess(response));
|
||||
console.log('SAGA LOGIN SUCCESS: ', response);
|
||||
} catch (err) {
|
||||
console.log('SAGA LOGIN ERR: ', err);
|
||||
yield put(loginFailure(err.status));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default function* root() {
|
||||
const root = function* root() {
|
||||
yield fork(watchLoginRequest);
|
||||
}
|
||||
};
|
||||
export default root;
|
||||
|
|
|
@ -3,9 +3,8 @@ import PropTypes from 'prop-types';
|
|||
import { Text, TextInput, StyleSheet } from 'react-native';
|
||||
import { connect } from 'react-redux';
|
||||
import { bindActionCreators } from 'redux';
|
||||
|
||||
import * as actions from '../actions';
|
||||
import RocketChat from '../lib/rocketchat';
|
||||
// import * as actions from '../actions';
|
||||
import * as loginActions from '../actions/login';
|
||||
import KeyboardView from '../components/KeyboardView';
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
|
@ -33,17 +32,10 @@ const styles = StyleSheet.create({
|
|||
}
|
||||
});
|
||||
|
||||
@connect(state => ({
|
||||
server: state.server,
|
||||
Accounts_EmailOrUsernamePlaceholder: state.settings.Accounts_EmailOrUsernamePlaceholder,
|
||||
Accounts_PasswordPlaceholder: state.settings.Accounts_PasswordPlaceholder
|
||||
}), dispatch => ({
|
||||
actions: bindActionCreators(actions, dispatch)
|
||||
}))
|
||||
|
||||
export default class LoginView extends React.Component {
|
||||
class LoginView extends React.Component {
|
||||
static propTypes = {
|
||||
navigator: PropTypes.object.isRequired,
|
||||
loginRequest: PropTypes.func.isRequired,
|
||||
server: PropTypes.string.isRequired,
|
||||
Accounts_EmailOrUsernamePlaceholder: PropTypes.string,
|
||||
Accounts_PasswordPlaceholder: PropTypes.string
|
||||
|
@ -71,32 +63,31 @@ export default class LoginView extends React.Component {
|
|||
subtitle: nextProps.server
|
||||
});
|
||||
}
|
||||
|
||||
submit = () => {
|
||||
this.setState({
|
||||
error: undefined
|
||||
});
|
||||
|
||||
const credentials = {
|
||||
username: this.state.username,
|
||||
password: this.state.password,
|
||||
code: this.state.code
|
||||
};
|
||||
|
||||
RocketChat.loginWithPassword(credentials, (error) => {
|
||||
if (error) {
|
||||
if (error.error === 'totp-required') {
|
||||
this.setState({ totp: true });
|
||||
this.codeInput.focus();
|
||||
} else {
|
||||
this.setState({
|
||||
error: error.reason
|
||||
});
|
||||
}
|
||||
} else {
|
||||
this.props.navigator.dismissModal();
|
||||
}
|
||||
});
|
||||
const { username, password, code } = this.state;
|
||||
this.props.loginRequest({ username, password, code });
|
||||
console.log(this.props.loginRequest.toString());
|
||||
//
|
||||
//
|
||||
// this.setState({
|
||||
// error: undefined
|
||||
// });
|
||||
//
|
||||
//
|
||||
// RocketChat.loginWithPassword(credentials, (error) => {
|
||||
// if (error) {
|
||||
// if (error.error === 'totp-required') {
|
||||
// this.setState({ totp: true });
|
||||
// this.codeInput.focus();
|
||||
// } else {
|
||||
// this.setState({
|
||||
// error: error.reason
|
||||
// });
|
||||
// }
|
||||
// } else {
|
||||
// this.props.navigator.dismissModal();
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
renderTOTP = () => {
|
||||
|
@ -120,6 +111,7 @@ export default class LoginView extends React.Component {
|
|||
render() {
|
||||
return (
|
||||
<KeyboardView style={styles.view} keyboardVerticalOffset={64}>
|
||||
{this.props.login.isFetching && <Text> INDO</Text>}
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
onChangeText={username => this.setState({ username })}
|
||||
|
@ -147,3 +139,18 @@ export default class LoginView extends React.Component {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
server: state.server,
|
||||
Accounts_EmailOrUsernamePlaceholder: state.settings.Accounts_EmailOrUsernamePlaceholder,
|
||||
Accounts_PasswordPlaceholder: state.settings.Accounts_PasswordPlaceholder,
|
||||
login: state.default
|
||||
};
|
||||
}
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return bindActionCreators(loginActions, dispatch);
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(LoginView);
|
||||
|
|
|
@ -1 +1 @@
|
|||
import './app/navigation';
|
||||
import './index.ios';
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
import 'babel-polyfill';
|
||||
import 'regenerator-runtime/runtime';
|
||||
import './app/navigation';
|
||||
|
|
Loading…
Reference in New Issue