{"size": 685, "ext": "js", "max_stars_repo_path": "src/container-page/login/_actions.js", "max_stars_repo_name": "artemdudkin/gtd", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/container-page/login/_actions.js", "max_issues_repo_name": "artemdudkin/gtd", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/container-page/login/_actions.js", "max_forks_repo_name": "artemdudkin/gtd", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.1470588235, "max_line_length": 56, "alphanum_fraction": 0.6277372263}
import api     from '../../api';
import history from '../../module/history';


export const LOGIN_START = "LOGIN_START";
export const LOGIN_OK   = "LOGIN_OK";
export const LOGIN_FAIL = "LOGIN_FAIL";


export const login = ( name, pwd) => {
  return (dispatch, getState) => {

	dispatch({type:LOGIN_START});
	
	api.login({
		name,
		pwd
	})
	  .then(function (response) {
		const data = response.data;
	  	if (data.resultCode == 0) {
			dispatch({type:LOGIN_OK, name:name, role:data.type});
			history.push('/task-list-for-today');
		} else {
			dispatch({type:LOGIN_FAIL, error:data});
		}
	  })
	  .catch(function (error) {
			dispatch({type:LOGIN_FAIL, error:error});
	  });

  };
}
