|
|
@ -27,7 +27,7 @@ import { |
|
|
|
CarouselItem, |
|
|
|
CarouselItem, |
|
|
|
CarouselControl |
|
|
|
CarouselControl |
|
|
|
} from 'reactstrap'; |
|
|
|
} from 'reactstrap'; |
|
|
|
import { USER_LOGIN, USER_LOGIN_V2, CALERTUSER_SEARCH, MENU_MANAGEMENT, APP_MODE } from '../../../const/ApiConst.js'; |
|
|
|
import { USER_LOGIN, USER_LOGIN_V2, CALERTUSER_SEARCH, MENU_MANAGEMENT, APP_MODE, ROLE_SEARCH } from '../../../const/ApiConst.js'; |
|
|
|
import { appConfig, reloadConstants } from '../../../const/MapConst.js'; |
|
|
|
import { appConfig, reloadConstants } from '../../../const/MapConst.js'; |
|
|
|
import { APP_NAME } from '../../../const/AppConst.js' |
|
|
|
import { APP_NAME } from '../../../const/AppConst.js' |
|
|
|
import moment from "moment" |
|
|
|
import moment from "moment" |
|
|
@ -65,7 +65,8 @@ class Login extends Component { |
|
|
|
emailState: '', |
|
|
|
emailState: '', |
|
|
|
}, |
|
|
|
}, |
|
|
|
loader: false, |
|
|
|
loader: false, |
|
|
|
type: 'password' |
|
|
|
type: 'password', |
|
|
|
|
|
|
|
defaultPage: '' |
|
|
|
} |
|
|
|
} |
|
|
|
this.handleChange = this.handleChange.bind(this); |
|
|
|
this.handleChange = this.handleChange.bind(this); |
|
|
|
this.showHide = this.showHide.bind(this); |
|
|
|
this.showHide = this.showHide.bind(this); |
|
|
@ -97,6 +98,41 @@ class Login extends Component { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getDataRole = async (token, role_id) => { |
|
|
|
|
|
|
|
const config = { |
|
|
|
|
|
|
|
headers: |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Authorization: `Bearer ${token}`, |
|
|
|
|
|
|
|
"Content-type": `application/json` |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const payload = { |
|
|
|
|
|
|
|
"paging": { "start": 0, "length": -1 }, |
|
|
|
|
|
|
|
"columns": [ |
|
|
|
|
|
|
|
{ "name": "id", "logic_operator": "=", "value": `${role_id}`, "operator": "AND" } |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
"joins": [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
"name": "m_menu", |
|
|
|
|
|
|
|
"column_join": "default_page", |
|
|
|
|
|
|
|
"column_results": ["id", "name", "url"], |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
"orders": { "columns": ["id"], "ascending": false } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const result = await axios |
|
|
|
|
|
|
|
.post(ROLE_SEARCH, payload, config) |
|
|
|
|
|
|
|
.then(res => res) |
|
|
|
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (result && result.data && result.data.code == 200) { |
|
|
|
|
|
|
|
let resData = result.data.data |
|
|
|
|
|
|
|
this.setState({defaultPage: resData[0].join_first_url}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getDataMenu = async (token, role_id) => { |
|
|
|
getDataMenu = async (token, role_id) => { |
|
|
|
const config = { |
|
|
|
const config = { |
|
|
|
headers: |
|
|
|
headers: |
|
|
@ -123,6 +159,14 @@ class Login extends Component { |
|
|
|
else { |
|
|
|
else { |
|
|
|
this.props.history.push("/dashboard"); |
|
|
|
this.props.history.push("/dashboard"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (this.state.defaultPage) { |
|
|
|
|
|
|
|
this.props.history.push(this.state.defaultPage); |
|
|
|
|
|
|
|
} else if (role_id == 28) { |
|
|
|
|
|
|
|
this.props.history.push("/dashboard-customer/58/63"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
this.props.history.push("/dashboard"); |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
NotificationManager.error('Login Failed', 'Failed'); |
|
|
|
NotificationManager.error('Login Failed', 'Failed'); |
|
|
|
this.setState({ loader: false }) |
|
|
|
this.setState({ loader: false }) |
|
|
@ -164,6 +208,7 @@ class Login extends Component { |
|
|
|
|
|
|
|
|
|
|
|
if (doLogin && doLogin.data && doLogin.data.code === 200) { |
|
|
|
if (doLogin && doLogin.data && doLogin.data.code === 200) { |
|
|
|
const { access_token, data_user } = doLogin.data.data |
|
|
|
const { access_token, data_user } = doLogin.data.data |
|
|
|
|
|
|
|
this.getDataRole(access_token, data_user.role_id) |
|
|
|
this.getDataMenu(access_token, data_user.role_id) |
|
|
|
this.getDataMenu(access_token, data_user.role_id) |
|
|
|
window.localStorage.setItem('isLogin', true); |
|
|
|
window.localStorage.setItem('isLogin', true); |
|
|
|
window.localStorage.setItem('token', access_token); |
|
|
|
window.localStorage.setItem('token', access_token); |
|
|
|