secure
This commit is contained in:
parent
6214aea437
commit
c476e7bbf5
|
@ -81,7 +81,7 @@ class App extends Component {
|
||||||
logged: false,
|
logged: false,
|
||||||
isModalVisible: false,
|
isModalVisible: false,
|
||||||
state: { text: "" },
|
state: { text: "" },
|
||||||
username: "QR code",
|
username: "QR code ou",
|
||||||
failedAttempt: false,
|
failedAttempt: false,
|
||||||
push: 4,
|
push: 4,
|
||||||
UI_loginScannerActive: false,
|
UI_loginScannerActive: false,
|
||||||
|
@ -105,23 +105,13 @@ class App extends Component {
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
//this.props.hold();
|
//this.props.hold();
|
||||||
this.props.loginInternal();
|
// this.props.loginInternal();
|
||||||
NetInfo.isConnected.addEventListener(
|
|
||||||
"connectionChange",
|
|
||||||
this.handleConnectivityChange
|
|
||||||
);
|
|
||||||
|
|
||||||
this.setState({ isModalVisible: false });
|
this.setState({ isModalVisible: false });
|
||||||
//verifica se o utilizador tem token guardado
|
//verifica se o utilizador tem token guardado
|
||||||
this.props.checkUser(this.props.userDetails);
|
this.props.checkUser(this.props.token);
|
||||||
this.keyboardDidShowListener = Keyboard.addListener(
|
|
||||||
"keyboardDidShow",
|
|
||||||
this._keyboardDidShow
|
|
||||||
);
|
|
||||||
this.keyboardDidHideListener = Keyboard.addListener(
|
|
||||||
"keyboardDidHide",
|
|
||||||
this._keyboardDidHide
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
NetInfo.isConnected.removeEventListener(
|
NetInfo.isConnected.removeEventListener(
|
||||||
|
@ -135,7 +125,7 @@ class App extends Component {
|
||||||
//faz call
|
//faz call
|
||||||
_reset=()=>{
|
_reset=()=>{
|
||||||
//fecha modal
|
//fecha modal
|
||||||
this.props.resetPassword(this.props.userDetails.token,this.state.resetText),
|
this.props.resetPassword(this.props.token,this.state.resetText),
|
||||||
this.setState({modalResetPassword:false})
|
this.setState({modalResetPassword:false})
|
||||||
//faz call
|
//faz call
|
||||||
}
|
}
|
||||||
|
@ -249,7 +239,7 @@ class App extends Component {
|
||||||
style={styles.input}
|
style={styles.input}
|
||||||
placeholder={this.state.username}
|
placeholder={this.state.username}
|
||||||
onChangeText={searchString => {
|
onChangeText={searchString => {
|
||||||
this.setState({ searchString });
|
this.setState({ username:searchString });
|
||||||
}}
|
}}
|
||||||
maxLength={15}
|
maxLength={15}
|
||||||
underlineColorAndroid="transparent"
|
underlineColorAndroid="transparent"
|
||||||
|
|
|
@ -47,7 +47,7 @@ class Calendar extends React.Component {
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.getEvents(this.props.user);
|
this.props.getEvents(this.props.user);
|
||||||
|
|
||||||
this.props.getSessions(this.props.userDetails.token);
|
this.props.getSessions(this.props.token);
|
||||||
}
|
}
|
||||||
|
|
||||||
_openDetails = () => {
|
_openDetails = () => {
|
||||||
|
@ -142,7 +142,7 @@ class Calendar extends React.Component {
|
||||||
}
|
}
|
||||||
_refresh=()=>{
|
_refresh=()=>{
|
||||||
this.props.getEvents(this.props.user);
|
this.props.getEvents(this.props.user);
|
||||||
//this.props.getSessions(this.props.userDetails.token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
|
@ -78,7 +78,7 @@ class Home extends Component {
|
||||||
|
|
||||||
//console.log(this.props.token);
|
//console.log(this.props.token);
|
||||||
|
|
||||||
this.props.getUserInfo(this.props.userDetails.token);
|
this.props.getUserInfo(this.props.token);
|
||||||
|
|
||||||
//console.log('logged:'+this.props.logged);
|
//console.log('logged:'+this.props.logged);
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ class Home extends Component {
|
||||||
//var navigate = this.props.navigation.navigate
|
//var navigate = this.props.navigation.navigate
|
||||||
}
|
}
|
||||||
_update = () => {
|
_update = () => {
|
||||||
this.props.getUserInfo(this.props.userDetails.token);
|
this.props.getUserInfo(this.props.token);
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
|
@ -91,7 +91,7 @@ class Profile extends Component {
|
||||||
|
|
||||||
_press=()=>{
|
_press=()=>{
|
||||||
this.props.changePassword(
|
this.props.changePassword(
|
||||||
this.props.userDetails.token,
|
this.props.token,
|
||||||
this.state.oldPass,
|
this.state.oldPass,
|
||||||
this.state.new1,
|
this.state.new1,
|
||||||
this.state.new2
|
this.state.new2
|
||||||
|
@ -163,7 +163,7 @@ class Profile extends Component {
|
||||||
if (formValid) {
|
if (formValid) {
|
||||||
console.log("data valid");
|
console.log("data valid");
|
||||||
|
|
||||||
this.props.updateUser(this.props.userDetails.token, {
|
this.props.updateUser(this.props.token, {
|
||||||
Name: this.state.name,
|
Name: this.state.name,
|
||||||
Company: jobs,
|
Company: jobs,
|
||||||
LastName: curso,
|
LastName: curso,
|
||||||
|
|
|
@ -77,8 +77,8 @@ class choosePath extends React.Component {
|
||||||
};
|
};
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
// this.props.getEvents(this.props.user);
|
// this.props.getEvents(this.props.user);
|
||||||
this.props.getAvailableGuestlists(this.props.userDetails.token);
|
this.props.getAvailableGuestlists(this.props.token);
|
||||||
this.props.getSessions(this.props.userDetails.token);
|
this.props.getSessions(this.props.token);
|
||||||
this._mount();
|
this._mount();
|
||||||
|
|
||||||
//console.log('didMount');
|
//console.log('didMount');
|
||||||
|
@ -120,10 +120,10 @@ class choosePath extends React.Component {
|
||||||
|
|
||||||
_s() {
|
_s() {
|
||||||
|
|
||||||
this.props.signSession(this.props.userDetails.token, item[index].Id);
|
this.props.signSession(this.props.token, item[index].Id);
|
||||||
}
|
}
|
||||||
getCareerPaths = () => {
|
getCareerPaths = () => {
|
||||||
this.props.getAvailableGuestlists(this.props.userDetails.token);
|
this.props.getAvailableGuestlists(this.props.token);
|
||||||
console.log(this.props.calendar);
|
console.log(this.props.calendar);
|
||||||
};
|
};
|
||||||
_keyExtractor = (item, index) => item.id;
|
_keyExtractor = (item, index) => item.id;
|
||||||
|
@ -265,13 +265,12 @@ class choosePath extends React.Component {
|
||||||
this.props.waitChangeGuest();
|
this.props.waitChangeGuest();
|
||||||
|
|
||||||
this.props.changeGuestList(
|
this.props.changeGuestList(
|
||||||
this.props.userDetails.token,
|
this.props.token,
|
||||||
itemValue
|
itemValue
|
||||||
);
|
);
|
||||||
|
|
||||||
// this.props.waitChangeGuest();
|
// this.props.waitChangeGuest();
|
||||||
// this.props.getAvailableSessions(this.props.userDetails.token);
|
|
||||||
|
|
||||||
// this.props.waitChangeGuest();
|
// this.props.waitChangeGuest();
|
||||||
|
|
||||||
// this.props.getSessionBlocks(this.props.sessions)
|
// this.props.getSessionBlocks(this.props.sessions)
|
||||||
|
@ -328,7 +327,7 @@ class choosePath extends React.Component {
|
||||||
|
|
||||||
this.props.removeSession(
|
this.props.removeSession(
|
||||||
this.props.user,
|
this.props.user,
|
||||||
this.props.userDetails.token,
|
this.props.token,
|
||||||
item[index].Id
|
item[index].Id
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
|
@ -350,7 +349,7 @@ class choosePath extends React.Component {
|
||||||
//this.props.waitChangeGuest()
|
//this.props.waitChangeGuest()
|
||||||
this.props.signSession(
|
this.props.signSession(
|
||||||
this.props.user,
|
this.props.user,
|
||||||
this.props.userDetails.token,
|
this.props.token,
|
||||||
item[index].Id
|
item[index].Id
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -505,7 +504,8 @@ function mapStateToProps(state, props) {
|
||||||
changingGuest: state.apiReducer.changingGuest,
|
changingGuest: state.apiReducer.changingGuest,
|
||||||
sessions: state.apiReducer.sessions,
|
sessions: state.apiReducer.sessions,
|
||||||
Blocks: state.apiReducer.Blocks,
|
Blocks: state.apiReducer.Blocks,
|
||||||
showAlert: state.apiReducer.showAlert
|
showAlert: state.apiReducer.showAlert,
|
||||||
|
token: state.apiReducer.token
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,9 +35,8 @@ import { colors } from "react-native-elements";
|
||||||
|
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
|
|
||||||
axios.defaults.baseURL = "http://enei2019.uingress.com/internal/api";
|
axios.defaults.baseURL = "https://tickets.enei.pt/internal/api";
|
||||||
|
|
||||||
//http://enei2019.uingress.com/internal/api/Attendee/Edit
|
|
||||||
|
|
||||||
const map = require("lodash/fp/map").convert({ cap: false });
|
const map = require("lodash/fp/map").convert({ cap: false });
|
||||||
|
|
||||||
|
@ -49,32 +48,118 @@ export function waitLogin() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function changePassword(token, old, new1, new2) {
|
var checkAndRefresh = function(token) {
|
||||||
axios.defaults.headers.common = {
|
return new Promise(function(resolve, reject) {
|
||||||
Authorization: `bearer ${token.access_token}`
|
//verificar se já expirou a validade do token
|
||||||
};
|
if (token == undefined || token.access_token == undefined) {
|
||||||
axios.defaults.baseURL = "http://enei2019.uingress.com/internal/api";
|
reject("user logged out");
|
||||||
|
console.log("fds");
|
||||||
|
} else if (
|
||||||
|
Math.round(new Date().getTime() / 1000) >= token.expirationDateToken
|
||||||
|
) {
|
||||||
|
console.log("vai renovar");
|
||||||
|
var obj;
|
||||||
|
|
||||||
return dispatch => {
|
var details = {
|
||||||
if (new1 != new2) {
|
refresh_token: token.refresh_token,
|
||||||
Alert.alert("ERRO!", "As passords são diferentes...");
|
grant_type: "refresh_token"
|
||||||
} else {
|
};
|
||||||
axios
|
|
||||||
.post("/User/ChangePassword", {
|
var formBody = [];
|
||||||
OldPassword: old,
|
|
||||||
NewPassword: new1
|
for (var property in details) {
|
||||||
|
var encodedKey = encodeURIComponent(property);
|
||||||
|
|
||||||
|
var encodedValue = encodeURIComponent(details[property]);
|
||||||
|
|
||||||
|
formBody.push(encodedKey + "=" + encodedValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
formBody = formBody.join("&");
|
||||||
|
|
||||||
|
fetch("https://tickets.enei.pt/internal/api/token", {
|
||||||
|
method: "POST",
|
||||||
|
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
|
||||||
|
},
|
||||||
|
|
||||||
|
body: formBody
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
alert("Erro no login!!");
|
||||||
|
|
||||||
|
alert("error");
|
||||||
|
reject("ERRRO");
|
||||||
})
|
})
|
||||||
.then(a => {
|
.then(res => res.json())
|
||||||
Alert.alert("Sucesso!", "Password alterada com sucesso")
|
.then(parsed => {
|
||||||
})
|
if (parsed.error == "invalid_grant") {
|
||||||
.catch(p => {
|
reject("erro");
|
||||||
Alert.alert("ERRO!", "Erro a alterar a password.\nA palavra original é inválida...\nCaso o erro persista verifica a tua conexão à internet e tenta novamente")
|
} else {
|
||||||
|
var obj = {
|
||||||
|
access_token: parsed.access_token,
|
||||||
|
refresh_token: parsed.refresh_token,
|
||||||
|
expirationDateToken:
|
||||||
|
Math.round(new Date().getTime() / 1000) + 3598
|
||||||
|
};
|
||||||
|
resolve(obj);
|
||||||
|
console.log(parsed);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
dispatch({
|
console.log(
|
||||||
type: OPEN_MODAL
|
"Tempo restante token: " +
|
||||||
});
|
Math.round(
|
||||||
|
(token.expirationDateToken -
|
||||||
|
Math.round(new Date().getTime() / 1000)) /
|
||||||
|
60
|
||||||
|
) +
|
||||||
|
" Minutos"
|
||||||
|
);
|
||||||
|
resolve(token);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export function changePassword(token, old, new1, new2) {
|
||||||
|
return dispatch => {
|
||||||
|
axios.defaults.baseURL = "https://tickets.enei.pt/internal/api";
|
||||||
|
checkAndRefresh(token)
|
||||||
|
.then(newToken => {
|
||||||
|
axios.defaults.headers.common = {
|
||||||
|
Authorization: `bearer ${newToken.access_token}`
|
||||||
|
};
|
||||||
|
if (new1 != new2) {
|
||||||
|
Alert.alert("ERRO!", "As passords são diferentes...");
|
||||||
|
} else {
|
||||||
|
axios
|
||||||
|
.post("/User/ChangePassword", {
|
||||||
|
OldPassword: old,
|
||||||
|
NewPassword: new1
|
||||||
|
})
|
||||||
|
.then(a => {
|
||||||
|
Alert.alert("Sucesso!", "Password alterada com sucesso");
|
||||||
|
})
|
||||||
|
.catch(p => {
|
||||||
|
Alert.alert(
|
||||||
|
"ERRO!",
|
||||||
|
"Erro a alterar a password.\nA palavra original é inválida...\nCaso o erro persista verifica a tua conexão à internet e tenta novamente"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: OPEN_MODAL
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
Alert.alert(
|
||||||
|
"Token ERROR!",
|
||||||
|
"Parace que houve um erro com o teu token... Reinicia a App. Caso o problema se mantenha, volta e instalar"
|
||||||
|
);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
//faz autenticação com API interna
|
//faz autenticação com API interna
|
||||||
|
@ -120,29 +205,43 @@ export function closeModal() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateUser(token, user) {
|
export function updateUser(token, user) {
|
||||||
axios.defaults.baseURL = "http://enei2019.uingress.com/internal/api";
|
axios.defaults.baseURL = "https://tickets.enei.pt/internal/api";
|
||||||
axios.defaults.headers.common = {
|
|
||||||
Authorization: `bearer ${token.access_token}`
|
|
||||||
};
|
|
||||||
|
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
axios
|
checkAndRefresh(token)
|
||||||
|
.then(newToken => {
|
||||||
.post("/Attendee/Edit", user)
|
axios.defaults.headers.common = {
|
||||||
|
Authorization: `bearer ${newToken.access_token}`
|
||||||
.then(a => {
|
};
|
||||||
|
axios
|
||||||
Alert.alert("Sucesso", "As informações pessoais foram guardadas com sucesso.")
|
|
||||||
|
.post("/Attendee/Edit", user)
|
||||||
console.log(a.data)
|
|
||||||
dispatch({
|
.then(a => {
|
||||||
type: UPDATE_USER,
|
Alert.alert(
|
||||||
user:a.data
|
"Sucesso",
|
||||||
});
|
"As informações pessoais foram guardadas com sucesso."
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(a.data);
|
||||||
|
dispatch({
|
||||||
|
type: UPDATE_USER,
|
||||||
|
user: a.data
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(b => {
|
||||||
|
Alert.alert(
|
||||||
|
"ERRO!",
|
||||||
|
"Ocorreu um erro a guardar os dados pessoais."
|
||||||
|
);
|
||||||
|
alert(b);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch(b => {
|
.catch(err => {
|
||||||
Alert.alert("ERRO!","Ocorreu um erro a guardar os dados pessoais.")
|
Alert.alert(
|
||||||
alert(b)
|
"Token ERROR!",
|
||||||
|
"Parace que houve um erro com o teu token... Reinicia a App. Caso o problema se mantenha, volta e instalar"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -199,17 +298,20 @@ export const connectionState = status => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export function removeSession(user, token, idSession) {
|
export function removeSession(user, token, idSession) {
|
||||||
axios.defaults.headers.common = {
|
|
||||||
Authorization: `bearer ${token.access_token}`
|
|
||||||
};
|
|
||||||
|
|
||||||
var obj = {
|
var obj = {
|
||||||
IdSession: idSession,
|
IdSession: idSession,
|
||||||
Direction: 0
|
Direction: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
//adiciona participante a uma palestra
|
//adiciona participante a uma palestra
|
||||||
|
checkAndRefresh(token)
|
||||||
|
.then(newToken => {
|
||||||
|
axios.defaults.headers.common = {
|
||||||
|
Authorization: `bearer ${newToken.access_token}`
|
||||||
|
};
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.post("/Session/RemoveAttendee", obj)
|
.post("/Session/RemoveAttendee", obj)
|
||||||
//se não existir erro na chamada...
|
//se não existir erro na chamada...
|
||||||
|
@ -273,14 +375,19 @@ export function removeSession(user, token, idSession) {
|
||||||
.catch(b => {
|
.catch(b => {
|
||||||
alert("Erro a inscrever na palestra");
|
alert("Erro a inscrever na palestra");
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
Alert.alert(
|
||||||
|
"Token ERROR!",
|
||||||
|
"Parace que houve um erro com o teu token... Reinicia a App. Caso o problema se mantenha, volta e instalar"
|
||||||
|
);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
//inscrição em palestra através de ID
|
//inscrição em palestra através de ID
|
||||||
export function signSession(user, token, idSession) {
|
export function signSession(user, token, idSession) {
|
||||||
axios.defaults.headers.common = {
|
|
||||||
Authorization: `bearer ${token.access_token}`
|
|
||||||
};
|
|
||||||
|
|
||||||
var obj = {
|
var obj = {
|
||||||
IdSession: idSession,
|
IdSession: idSession,
|
||||||
|
@ -288,6 +395,13 @@ export function signSession(user, token, idSession) {
|
||||||
};
|
};
|
||||||
|
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
|
|
||||||
|
checkAndRefresh(token)
|
||||||
|
.then(newToken => {
|
||||||
|
axios.defaults.headers.common = {
|
||||||
|
Authorization: `bearer ${newToken.access_token}`
|
||||||
|
};
|
||||||
|
|
||||||
//adiciona participante a uma palestra
|
//adiciona participante a uma palestra
|
||||||
axios
|
axios
|
||||||
.post("/Session/AddAttendee", obj)
|
.post("/Session/AddAttendee", obj)
|
||||||
|
@ -318,7 +432,7 @@ export function signSession(user, token, idSession) {
|
||||||
"Sucesso",
|
"Sucesso",
|
||||||
"Inscrição na sessão efectuada com sucesso"
|
"Inscrição na sessão efectuada com sucesso"
|
||||||
);
|
);
|
||||||
console.log("aqui1")
|
console.log("aqui1");
|
||||||
//obter informações pessoais:
|
//obter informações pessoais:
|
||||||
axios
|
axios
|
||||||
.get("/Attendee/Detail")
|
.get("/Attendee/Detail")
|
||||||
|
@ -327,7 +441,7 @@ export function signSession(user, token, idSession) {
|
||||||
alert(error);
|
alert(error);
|
||||||
})
|
})
|
||||||
.then(sucess => {
|
.then(sucess => {
|
||||||
console.log("aqui2")
|
console.log("aqui2");
|
||||||
var result = getE(user);
|
var result = getE(user);
|
||||||
dispatch({
|
dispatch({
|
||||||
type: SIGN_SESSION,
|
type: SIGN_SESSION,
|
||||||
|
@ -358,16 +472,28 @@ export function signSession(user, token, idSession) {
|
||||||
.catch(b => {
|
.catch(b => {
|
||||||
// alert("Erro a inscrever na palestra");
|
// alert("Erro a inscrever na palestra");
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
Alert.alert(
|
||||||
|
"Token ERROR!",
|
||||||
|
"Parace que houve um erro com o teu token... Reinicia a App. Caso o problema se mantenha, volta e instalar"
|
||||||
|
);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSessions(token) {
|
export function getSessions(token) {
|
||||||
axios.defaults.headers.common = {
|
|
||||||
Authorization: `bearer ${token.access_token}`
|
|
||||||
};
|
|
||||||
|
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
axios.defaults.baseURL = "http://enei2019.uingress.com/internal/api";
|
|
||||||
|
checkAndRefresh(token)
|
||||||
|
.then(newToken => {
|
||||||
|
axios.defaults.headers.common = {
|
||||||
|
Authorization: `bearer ${newToken.access_token}`
|
||||||
|
};
|
||||||
|
|
||||||
|
axios.defaults.baseURL = "https://tickets.enei.pt/internal/api";
|
||||||
|
|
||||||
axios.defaults.headers.common = {
|
axios.defaults.headers.common = {
|
||||||
Authorization: `bearer ${token.access_token}`
|
Authorization: `bearer ${token.access_token}`
|
||||||
|
@ -405,15 +531,26 @@ export function getSessions(token) {
|
||||||
alert("Error a obter sessões disponíveis!!");
|
alert("Error a obter sessões disponíveis!!");
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
Alert.alert(
|
||||||
|
"Token ERROR!",
|
||||||
|
"Parace que houve um erro com o teu token... Reinicia a App. Caso o problema se mantenha, volta e instalar"
|
||||||
|
);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAvailableGuestlists(token) {
|
export function getAvailableGuestlists(token) {
|
||||||
axios.defaults.headers.common = {
|
|
||||||
Authorization: `bearer ${token.access_token}`
|
|
||||||
};
|
|
||||||
|
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
|
|
||||||
|
checkAndRefresh(token)
|
||||||
|
.then(newToken => {
|
||||||
|
axios.defaults.headers.common = {
|
||||||
|
Authorization: `bearer ${newToken.access_token}`
|
||||||
|
};
|
||||||
axios
|
axios
|
||||||
.get("/Attendee/AvailableGuestlists")
|
.get("/Attendee/AvailableGuestlists")
|
||||||
.then(function(response) {
|
.then(function(response) {
|
||||||
|
@ -430,6 +567,12 @@ export function getAvailableGuestlists(token) {
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
// always executed
|
// always executed
|
||||||
|
});})
|
||||||
|
.catch(err => {
|
||||||
|
Alert.alert(
|
||||||
|
"Token ERROR!",
|
||||||
|
"Parace que houve um erro com o teu token... Reinicia a App. Caso o problema se mantenha, volta e instalar"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -444,32 +587,30 @@ export function getAvailableGuestlists(token) {
|
||||||
15 - DS
|
15 - DS
|
||||||
*/
|
*/
|
||||||
export function changeGuestList(token, guestID) {
|
export function changeGuestList(token, guestID) {
|
||||||
//http://enei2019.uingress.com/internal/api/Attendee/ChangeGuestlist/
|
|
||||||
|
|
||||||
axios.defaults.headers.common = {
|
|
||||||
Authorization: `bearer ${token.access_token}`
|
|
||||||
};
|
|
||||||
|
|
||||||
|
axios.defaults.baseURL = "https://tickets.enei.pt/internal/api";
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
|
|
||||||
|
checkAndRefresh(token)
|
||||||
|
.then(newToken => {
|
||||||
|
axios.defaults.headers.common = {
|
||||||
|
Authorization: `bearer ${newToken.access_token}`
|
||||||
|
};
|
||||||
|
|
||||||
var full = `/Attendee/ChangeGuestlist/${guestID}`;
|
var full = `/Attendee/ChangeGuestlist/${guestID}`;
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.get(full)
|
.get(full)
|
||||||
.then(function(response) {
|
.then(function(response) {
|
||||||
|
|
||||||
axios.defaults.baseURL = "http://enei2019.uingress.com/internal/api";
|
|
||||||
|
|
||||||
axios.defaults.headers.common = {
|
|
||||||
Authorization: `bearer ${token.access_token}`
|
|
||||||
};
|
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.get("/Attendee/AvailableSessions")
|
.get("/Attendee/AvailableSessions")
|
||||||
|
|
||||||
.then(function(response) {
|
.then(function(response) {
|
||||||
|
|
||||||
// handle success
|
// handle success
|
||||||
|
|
||||||
//console.log(response);
|
//console.log(response);
|
||||||
|
|
||||||
var cenas = [];
|
var cenas = [];
|
||||||
|
@ -481,14 +622,12 @@ export function changeGuestList(token, guestID) {
|
||||||
)(response.data);
|
)(response.data);
|
||||||
|
|
||||||
for (let key in result) {
|
for (let key in result) {
|
||||||
|
|
||||||
result[key].option = 0;
|
result[key].option = 0;
|
||||||
cenas.push(result[key]);
|
cenas.push(result[key]);
|
||||||
|
|
||||||
}
|
}
|
||||||
console.log("-.-.-..-.-.-.-.-.-.")
|
console.log("-.-.-..-.-.-.-.-.-.");
|
||||||
console.log(cenas);
|
console.log(cenas);
|
||||||
console.log("-.-.-..-.-.-.-.-.-.")
|
console.log("-.-.-..-.-.-.-.-.-.");
|
||||||
dispatch({
|
dispatch({
|
||||||
type: CHANGE_GUEST,
|
type: CHANGE_GUEST,
|
||||||
sessions: response.data,
|
sessions: response.data,
|
||||||
|
@ -511,6 +650,11 @@ export function changeGuestList(token, guestID) {
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
// always executed
|
// always executed
|
||||||
|
});}).catch(err => {
|
||||||
|
Alert.alert(
|
||||||
|
"Token ERROR!",
|
||||||
|
"Parace que houve um erro com o teu token... Reinicia a App. Caso o problema se mantenha, volta e instalar"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -539,15 +683,19 @@ export function getSessionBlocks(sessions) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAvailableSessions(token) {
|
export function getAvailableSessions(token) {
|
||||||
//http://enei2019.uingress.com/internal/api/Attendee/AvailableSessions
|
|
||||||
|
|
||||||
axios.defaults.baseURL = "http://enei2019.uingress.com/internal/api";
|
|
||||||
|
|
||||||
axios.defaults.headers.common = {
|
axios.defaults.baseURL = "https://tickets.enei.pt/internal/api";
|
||||||
Authorization: `bearer ${token.access_token}`
|
|
||||||
};
|
|
||||||
|
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
|
|
||||||
|
checkAndRefresh(token)
|
||||||
|
.then(newToken => {
|
||||||
|
axios.defaults.headers.common = {
|
||||||
|
Authorization: `bearer ${newToken.access_token}`
|
||||||
|
};
|
||||||
axios
|
axios
|
||||||
.get("/Attendee/AvailableSessions")
|
.get("/Attendee/AvailableSessions")
|
||||||
.then(function(response) {
|
.then(function(response) {
|
||||||
|
@ -576,6 +724,12 @@ export function getAvailableSessions(token) {
|
||||||
.catch(function(error) {
|
.catch(function(error) {
|
||||||
alert("Error a obter sessões disponíveis!!");
|
alert("Error a obter sessões disponíveis!!");
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
});})
|
||||||
|
.catch(err => {
|
||||||
|
Alert.alert(
|
||||||
|
"Token ERROR!",
|
||||||
|
"Parace que houve um erro com o teu token... Reinicia a App. Caso o problema se mantenha, volta e instalar"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -690,49 +844,6 @@ export function getEvents(user) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveToken = async token => {
|
|
||||||
try {
|
|
||||||
await AsyncStorage.setItem("refreshToken", token.refreshToken).catch(
|
|
||||||
a => {}
|
|
||||||
);
|
|
||||||
await AsyncStorage.setItem("userToken", token.access_token).catch(a => {});
|
|
||||||
await AsyncStorage.setItem(
|
|
||||||
"expirationDateToken",
|
|
||||||
token.expirationDateToken.toString()
|
|
||||||
).catch(a => {});
|
|
||||||
} catch (error) {
|
|
||||||
// Error retrieving data
|
|
||||||
console.log(error.message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const getToken = async () => {
|
|
||||||
obj = {};
|
|
||||||
try {
|
|
||||||
obj.access_token = (await AsyncStorage.getItem("userToken")) || "none";
|
|
||||||
obj.expirationDateToken =
|
|
||||||
(await AsyncStorage.getItem("expirationDateToken")) || "none";
|
|
||||||
obj.refreshToken = (await AsyncStorage.getItem("refreshToken")) || "none";
|
|
||||||
} catch (error) {
|
|
||||||
// Error retrieving data
|
|
||||||
console.log(error.message);
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
};
|
|
||||||
|
|
||||||
const deleteToken = async () => {
|
|
||||||
try {
|
|
||||||
await AsyncStorage.removeItem("userToken");
|
|
||||||
await AsyncStorage.removeItem("expirationDateToken");
|
|
||||||
await AsyncStorage.removeItem("refreshToken");
|
|
||||||
} catch (error) {
|
|
||||||
// Error retrieving data
|
|
||||||
console.log(error.message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const renewToken = refresh => {};
|
|
||||||
|
|
||||||
export function login(user, pass) {
|
export function login(user, pass) {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
console.log("user: " + user + " password: " + pass);
|
console.log("user: " + user + " password: " + pass);
|
||||||
|
@ -755,7 +866,7 @@ export function login(user, pass) {
|
||||||
|
|
||||||
formBody = formBody.join("&");
|
formBody = formBody.join("&");
|
||||||
|
|
||||||
fetch("http://enei2019.uingress.com/internal/api/token", {
|
fetch("https://tickets.enei.pt/internal/api/token", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -808,7 +919,7 @@ export function login(user, pass) {
|
||||||
var obj = {
|
var obj = {
|
||||||
access_token: parsed.access_token,
|
access_token: parsed.access_token,
|
||||||
expirationDateToken: Math.round(new Date().getTime() / 1000) + 3598,
|
expirationDateToken: Math.round(new Date().getTime() / 1000) + 3598,
|
||||||
refreshToken: parsed.refresh_token,
|
refresh_token: parsed.refresh_token,
|
||||||
valid: true
|
valid: true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -840,288 +951,76 @@ export function hold() {
|
||||||
export function getUserInfo(token) {
|
export function getUserInfo(token) {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
//TODO: verificar validade do token
|
//TODO: verificar validade do token
|
||||||
|
checkAndRefresh(token)
|
||||||
|
.then(newToken => {
|
||||||
|
console.log('Chamada "getUserInfo"');
|
||||||
|
|
||||||
console.log('Chamada "getUserInfo"');
|
var obj = {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${newToken.access_token}`
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var obj = {
|
fetch("https://tickets.enei.pt/internal/api/Attendee/Detail", obj)
|
||||||
method: "GET",
|
.then(function(res) {
|
||||||
headers: {
|
console.log(res);
|
||||||
Authorization: `Bearer ${token.access_token}`
|
let obj = JSON.parse(res._bodyText);
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fetch("http://enei2019.uingress.com/internal/api/Attendee/Detail", obj)
|
dispatch({
|
||||||
.then(function(res) {
|
type: USER_INFO,
|
||||||
console.log(res);
|
user: obj,
|
||||||
let obj = JSON.parse(res._bodyText);
|
onHold: false,
|
||||||
|
logged: true,
|
||||||
dispatch({ type: USER_INFO, user: obj, onHold: false, logged: true });
|
token: newToken
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(function(res) {
|
||||||
|
console.log("erro");
|
||||||
|
// dispatch({ type: USER_INFO,onHold:false});
|
||||||
|
alert("Erro a obter a informação pessoal.");
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch(function(res) {
|
.catch(err => {
|
||||||
console.log("erro");
|
console.log("cenas da vida");
|
||||||
// dispatch({ type: USER_INFO,onHold:false});
|
|
||||||
alert("Erro a obter a informação pessoal.");
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function logoutUser() {
|
export function logoutUser() {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
deleteToken()
|
console.log("token apagado");
|
||||||
.then(a => {
|
dispatch({
|
||||||
console.log("token apagado");
|
type: LOGOUT_USER,
|
||||||
|
loggedIn: false,
|
||||||
|
tokenData: "error",
|
||||||
|
token: false
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function checkUser(token) {
|
||||||
|
return dispatch => {
|
||||||
|
checkAndRefresh(token)
|
||||||
|
.catch(err => {
|
||||||
|
Alert("ERRO a fazer login");
|
||||||
|
console.log(err);
|
||||||
dispatch({
|
dispatch({
|
||||||
type: LOGOUT_USER,
|
type: CHECK_USER,
|
||||||
loggedIn: false,
|
logged: true,
|
||||||
tokenData: "error",
|
onHold: false,
|
||||||
token: false
|
userDetails: u,
|
||||||
|
token: obj
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.then(newToken => {
|
||||||
console.log("errors");
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
function refreshToken() {
|
|
||||||
refresh = a.refreshToken;
|
|
||||||
|
|
||||||
//chamar funçao para renovar
|
|
||||||
console.log("expirou");
|
|
||||||
|
|
||||||
var details = {
|
|
||||||
grant_type: "refresh_token",
|
|
||||||
refresh_token: refresh
|
|
||||||
};
|
|
||||||
|
|
||||||
var formBody = [];
|
|
||||||
|
|
||||||
for (var property in details) {
|
|
||||||
var encodedKey = encodeURIComponent(property);
|
|
||||||
|
|
||||||
var encodedValue = encodeURIComponent(details[property]);
|
|
||||||
|
|
||||||
formBody.push(encodedKey + "=" + encodedValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
formBody = formBody.join("&");
|
|
||||||
|
|
||||||
fetch("http://enei2019.uingress.com/internal/api/token", {
|
|
||||||
method: "POST",
|
|
||||||
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
|
|
||||||
},
|
|
||||||
|
|
||||||
body: formBody
|
|
||||||
})
|
|
||||||
.then(res => res.json())
|
|
||||||
.then(parsed => {
|
|
||||||
console.log(parsed);
|
|
||||||
|
|
||||||
if (parsed.error == "invalid_grant") {
|
|
||||||
console.log(formBody);
|
|
||||||
dispatch({ type: CHECK_USER, token: "", logged: false, onHold: false });
|
|
||||||
} else {
|
|
||||||
var obj = {
|
|
||||||
access_token: parsed.access_token,
|
|
||||||
expirationDateToken: Math.round(new Date().getTime() / 1000) + 3598,
|
|
||||||
refreshToken: parsed.refresh_token,
|
|
||||||
valid: true
|
|
||||||
};
|
|
||||||
|
|
||||||
// deleteToken();
|
|
||||||
saveToken(obj).then(a => {
|
|
||||||
console.log("Token guardado");
|
|
||||||
console.log(obj);
|
|
||||||
dispatch({
|
|
||||||
type: CHECK_USER,
|
|
||||||
token: obj,
|
|
||||||
logged: true,
|
|
||||||
onHold: false
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(a => {
|
|
||||||
console.log("erro na api");
|
|
||||||
dispatch({ type: CHECK_USER, token: "", logged: false, onHold: false });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
refreshLogin = async (user, pass) => {
|
|
||||||
console.log("login");
|
|
||||||
|
|
||||||
console.log("user: " + user + " password: " + pass);
|
|
||||||
|
|
||||||
var details = {
|
|
||||||
username: user,
|
|
||||||
password: pass,
|
|
||||||
grant_type: "password"
|
|
||||||
};
|
|
||||||
|
|
||||||
var formBody = [];
|
|
||||||
|
|
||||||
for (var property in details) {
|
|
||||||
var encodedKey = encodeURIComponent(property);
|
|
||||||
|
|
||||||
var encodedValue = encodeURIComponent(details[property]);
|
|
||||||
|
|
||||||
formBody.push(encodedKey + "=" + encodedValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
formBody = formBody.join("&");
|
|
||||||
|
|
||||||
fetch("http://enei2019.uingress.com/internal/api/token", {
|
|
||||||
method: "POST",
|
|
||||||
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
|
|
||||||
},
|
|
||||||
|
|
||||||
body: formBody
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
console.log(err);
|
|
||||||
|
|
||||||
alert("error");
|
|
||||||
})
|
|
||||||
.then(res => res.json())
|
|
||||||
.then(parsed => {
|
|
||||||
if (
|
|
||||||
parsed.error_description ==
|
|
||||||
"Provided username and password is incorrect"
|
|
||||||
) {
|
|
||||||
console.error("cenas da vida");
|
|
||||||
} else {
|
|
||||||
console.log(parsed);
|
|
||||||
|
|
||||||
var obj = {
|
|
||||||
access_token: parsed.access_token,
|
|
||||||
expirationDateToken: Math.round(new Date().getTime() / 1000) + 3598,
|
|
||||||
refreshToken: parsed.refresh_token,
|
|
||||||
valid: true
|
|
||||||
};
|
|
||||||
|
|
||||||
go();
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
go = t => {
|
|
||||||
dispatch({
|
|
||||||
type: CHECK_USER,
|
|
||||||
logged: true,
|
|
||||||
onHold: false,
|
|
||||||
user: { Name: "Henrique" },
|
|
||||||
token: t
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export function checkUser(userDetails) {
|
|
||||||
var u = userDetails;
|
|
||||||
|
|
||||||
return dispatch => {
|
|
||||||
//verifica se existe utilizador em memória
|
|
||||||
if (
|
|
||||||
userDetails.username != undefined &&
|
|
||||||
userDetails.username != "" &&
|
|
||||||
userDetails.password != undefined &&
|
|
||||||
userDetails.password != ""
|
|
||||||
) {
|
|
||||||
//verifica a validade do token
|
|
||||||
if (
|
|
||||||
Math.round(new Date().getTime() / 1000) >=
|
|
||||||
userDetails.token.expirationDateToken
|
|
||||||
) {
|
|
||||||
var details = {
|
|
||||||
username: userDetails.username,
|
|
||||||
password: userDetails.password,
|
|
||||||
grant_type: "password"
|
|
||||||
};
|
|
||||||
|
|
||||||
var formBody = [];
|
|
||||||
|
|
||||||
for (var property in details) {
|
|
||||||
var encodedKey = encodeURIComponent(property);
|
|
||||||
|
|
||||||
var encodedValue = encodeURIComponent(details[property]);
|
|
||||||
|
|
||||||
formBody.push(encodedKey + "=" + encodedValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
formBody = formBody.join("&");
|
|
||||||
|
|
||||||
fetch("http://enei2019.uingress.com/internal/api/token", {
|
|
||||||
method: "POST",
|
|
||||||
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
|
|
||||||
},
|
|
||||||
body: formBody
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
alert("Erro a validar o utilizador");
|
|
||||||
})
|
|
||||||
.then(res => res.json())
|
|
||||||
.then(parsed => {
|
|
||||||
if (
|
|
||||||
parsed.error_description ==
|
|
||||||
"Provided username and password is incorrect"
|
|
||||||
) {
|
|
||||||
alert("Ups, password ou utilizador errada");
|
|
||||||
} else {
|
|
||||||
console.log(parsed);
|
|
||||||
|
|
||||||
var obj = {
|
|
||||||
access_token: parsed.access_token,
|
|
||||||
expirationDateToken:
|
|
||||||
Math.round(new Date().getTime() / 1000) + 3598,
|
|
||||||
refreshToken: parsed.refresh_token,
|
|
||||||
valid: true
|
|
||||||
};
|
|
||||||
|
|
||||||
dispatch({
|
|
||||||
type: CHECK_USER,
|
|
||||||
logged: true,
|
|
||||||
onHold: false,
|
|
||||||
userDetails: u,
|
|
||||||
token: obj
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.log(
|
|
||||||
"Tempo restante token: " +
|
|
||||||
Math.round(
|
|
||||||
(userDetails.token.expirationDateToken -
|
|
||||||
Math.round(new Date().getTime() / 1000)) /
|
|
||||||
60
|
|
||||||
) +
|
|
||||||
" Minutos"
|
|
||||||
);
|
|
||||||
|
|
||||||
//dispatch home
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: CHECK_USER,
|
type: CHECK_USER,
|
||||||
logged: true,
|
logged: true,
|
||||||
onHold: false,
|
onHold: false,
|
||||||
user: { Name: "Henrique" },
|
user: { Name: "Henrique" },
|
||||||
userDetails: u
|
token: newToken
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
//utilizador não existe em memória
|
|
||||||
else {
|
|
||||||
dispatch({
|
|
||||||
type: CHECK_USER,
|
|
||||||
logged: false,
|
|
||||||
onHold: false,
|
|
||||||
userDetails: u
|
|
||||||
});
|
});
|
||||||
//dispatch menu de login
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,8 @@ let apiState = {
|
||||||
password: "",
|
password: "",
|
||||||
token: {
|
token: {
|
||||||
expirationDateToken: 0,
|
expirationDateToken: 0,
|
||||||
access_token: ""
|
access_token: "",
|
||||||
|
refresh_token:""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
calendar: {},
|
calendar: {},
|
||||||
|
@ -61,22 +62,31 @@ const apiReducer = (state = apiState, action) => {
|
||||||
|
|
||||||
var expirationDateTokenA = 0;
|
var expirationDateTokenA = 0;
|
||||||
var access_tokenA = "";
|
var access_tokenA = "";
|
||||||
|
var refresh_tokenA= "puta";
|
||||||
|
|
||||||
if (action.payload.apiReducer.userDetails.token != undefined) {
|
if (action.payload.apiReducer.token != undefined) {
|
||||||
if (
|
if (
|
||||||
action.payload.apiReducer.userDetails.token.expirationDateToken !=
|
action.payload.apiReducer.token.expirationDateToken !=
|
||||||
undefined
|
undefined
|
||||||
) {
|
) {
|
||||||
expirationDateTokenA =
|
expirationDateTokenA =
|
||||||
action.payload.apiReducer.userDetails.token.expirationDateToken;
|
action.payload.apiReducer.token.expirationDateToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
action.payload.apiReducer.userDetails.token.access_token !=
|
action.payload.apiReducer.token.access_token !=
|
||||||
undefined
|
undefined
|
||||||
) {
|
) {
|
||||||
access_tokenA =
|
access_tokenA =
|
||||||
action.payload.apiReducer.userDetails.token.access_token;
|
action.payload.apiReducer.token.access_token;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
action.payload.apiReducer.token.refresh_token !=
|
||||||
|
undefined
|
||||||
|
) {
|
||||||
|
|
||||||
|
refresh_tokenA =
|
||||||
|
action.payload.apiReducer.token.refresh_token;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,11 +98,13 @@ const apiReducer = (state = apiState, action) => {
|
||||||
userDetails: {
|
userDetails: {
|
||||||
token: {
|
token: {
|
||||||
expirationDateToken: expirationDateTokenA,
|
expirationDateToken: expirationDateTokenA,
|
||||||
access_token: access_tokenA
|
access_token: access_tokenA,
|
||||||
|
refresh_token:refresh_tokenA,
|
||||||
},
|
},
|
||||||
username: action.payload.apiReducer.userDetails.username,
|
username: action.payload.apiReducer.userDetails.username,
|
||||||
password: action.payload.apiReducer.userDetails.password
|
password: action.payload.apiReducer.userDetails.password
|
||||||
}
|
},
|
||||||
|
token:action.payload.apiReducer.token
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,19 +135,19 @@ const apiReducer = (state = apiState, action) => {
|
||||||
password: action.userDetails.password
|
password: action.userDetails.password
|
||||||
},
|
},
|
||||||
loadingLogin: false,
|
loadingLogin: false,
|
||||||
onHold: action.onHold
|
onHold: action.onHold,
|
||||||
|
token:action.token
|
||||||
});
|
});
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
|
|
||||||
case CHECK_USER:
|
case CHECK_USER:
|
||||||
var u = action.userDetails;
|
|
||||||
if (action.token != undefined) u.token = action.token;
|
|
||||||
|
|
||||||
state = Object.assign({}, state, {
|
state = Object.assign({}, state, {
|
||||||
logged: action.logged,
|
logged: action.logged,
|
||||||
onHold: action.onHold,
|
onHold: action.onHold,
|
||||||
userDetails: u
|
// userDetails: u,
|
||||||
|
token:action.token
|
||||||
});
|
});
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
|
@ -144,16 +156,20 @@ const apiReducer = (state = apiState, action) => {
|
||||||
state = Object.assign({}, state, {
|
state = Object.assign({}, state, {
|
||||||
user: {},
|
user: {},
|
||||||
userDetails: {},
|
userDetails: {},
|
||||||
|
token:{},
|
||||||
logged: false
|
logged: false
|
||||||
});
|
});
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
|
|
||||||
case USER_INFO:
|
case USER_INFO:
|
||||||
|
|
||||||
state = Object.assign({}, state, {
|
state = Object.assign({}, state, {
|
||||||
user: action.user,
|
user: action.user,
|
||||||
loggedIn: action.loggedIn,
|
loggedIn: action.loggedIn,
|
||||||
onHold: action.onHold
|
onHold: action.onHold,
|
||||||
|
token: action.token
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
|
|
Loading…
Reference in New Issue