update user

This commit is contained in:
henrydays 2019-03-12 07:31:41 +00:00
parent 116fc1b3a9
commit 46751679e5
10 changed files with 327 additions and 189 deletions

View File

@ -39,6 +39,7 @@ const SCREEN_HEIGHT = Dimensions.get("window").height;
const SCREEN_WIDTH = Dimensions.get("window").width;
import Swiper from "react-native-swiper";
import resetPassword from "./screens/resetPassword";
var TimerMixin = require("react-timer-mixin");
function handleConnectivityChange() {
@ -46,6 +47,9 @@ function handleConnectivityChange() {
}
class App extends Component {
handleConnectivityChange = isConnected => {
this.setState({ isConnected });
};
@ -142,7 +146,10 @@ class App extends Component {
};
render() {
if (!this.props.logged && this.props.onHold) {
return (
<View style={UtilStyles.containerLoading}>
@ -158,6 +165,7 @@ class App extends Component {
return <Router />;
}
return (
<View style={styles.slide2}>
<Modal isVisible={this.props.UI_loginScannerActive}>
<View style={{ flex: 1, backgroundColor: "white" }}>
@ -253,7 +261,7 @@ class App extends Component {
<View style={styles.textRow}>
<RkText rkType="primary3">Não sabes a password?</RkText>
<RkButton rkType="clear" onPress={this.onSignUpButtonPressed}>
<TouchableOpacity>
<TouchableOpacity onPress={() => <resetPassword></resetPassword>}>
<RkText style={{ color: "red" }} kType="header6">
Recuperar Password
</RkText>
@ -282,7 +290,7 @@ const overlayColor = "rgba(0,0,0,0.30)";
const styles = {
cameraContainer: {
// height: Dimensions.get('window').height ,
height: Dimensions.get('window').height ,
},
passwordInput: {
borderRadius: 90,

View File

@ -36,7 +36,7 @@ import Profile from "./screens/Profile";
import editCalendar from './screens/editCalendar';
import choosePath from './screens/choosePath';
import calendarDetail from './screens/calendarDetail';
import resetPassword from './screens/resetPassword';
const navigationOptions = ({navigation}) => ({
headerLeft: <HeaderBackButton onPress={() => navigation.goBack(null)}/>,
@ -198,6 +198,9 @@ const Stack = createStackNavigator({
screen: calendarDetail,
},
resetPassword:{
screen:resetPassword
}
});

View File

@ -142,7 +142,7 @@ class Calendar extends React.Component {
}
_refresh=()=>{
this.props.getEvents(this.props.user);
this.props.getSessions(this.props.userDetails.token);
//this.props.getSessions(this.props.userDetails.token);
}
render() {
@ -317,8 +317,8 @@ class Calendar extends React.Component {
style={{ backgroundColor: "#F2F2F2" }}
indicatorStyle={{ backgroundColor: "pink" }}
/>
<Button onPress={this._refresh} title="Close" color="#841584"
accessibilityLabel="Learn more about this purple button"/>
<Button onPress={this._refresh} title="Refresh" color="#841584"
/>
</View>

View File

@ -78,9 +78,25 @@ class Profile extends Component {
cityError: false,
cityErrorMessage: '',
oldPass:'',
new1:'',
new2:'',
url:this.props.user.Url,
curso:this.props.user.LastName,
};
}
_press=()=>{
this.props.changePassword(
this.props.userDetails.token,
this.state.oldPass,
this.state.new1,
this.state.new2
)
}
_logout = () => {
this.props.logoutUser();
@ -138,9 +154,9 @@ class Profile extends Component {
saveData() {
const {name, jobs, email, phone, address, city, formValid} = this.state;
const {name, jobs, email, phone, address, city, formValid, url,curso} = this.state;
this._validateData(name, jobs, email, phone, address, city);
// this._validateData(name, jobs, email, phone, address, city,curso);
console.log(formValid);
@ -149,17 +165,16 @@ class Profile extends Component {
this.props.updateUser(this.props.userDetails.token, {
Name: this.state.name,
// LastName: "Último",
Company: jobs,
// Job: jobs,
LastName: curso,
Address: address,
City: city,
// PostalCode: "3000-010",
Mobile: phone,
Avatar: "base64"
Avatar: "base64",
Url:url,
});
this.props.getUserInfo(this.props.userDetails.token);
}
@ -176,17 +191,13 @@ class Profile extends Component {
<View style={styles.container}>
<View style={styles.userBioRowHeader}>
<View style={styles.userBioRowTitle}>
<Text style={{color: '#CC1A17', fontWeight: 'bold', fontSize: 20}}>User Bio</Text>
</View>
<View>
<TouchableOpacity onPress={() => this.saveData()}>
<Icon name="ios-save" size={30}/><Text>Save</Text>
</TouchableOpacity>
<Text style={{color: '#CC1A17', fontWeight: 'bold', fontSize: 20}}>Informações Pessoais</Text>
</View>
</View>
<View style={styles.userBio}>
<View style={styles.userBioRow}>
<Icon name="ios-person" style={styles.userBioLogo} size={25}/>
<Text style={styles.userBioLogo} >Nome</Text>
<TextInput style={styles.userBioText}
onChangeText={(n) => {
@ -196,7 +207,18 @@ class Profile extends Component {
</View>
<Divider style={{backgroundColor: 'black'}}/>
<View style={styles.userBioRow}>
<Icon name="ios-laptop" style={styles.userBioLogo} size={25}/>
<Text style={styles.userBioLogo} >Curso</Text>
<TextInput style={styles.userBioText}
onChangeText={(cu) => {
this.setState({curso: cu})
}}
value={this.state.curso}/>
</View>
<Divider style={{backgroundColor: 'black'}}/>
<View style={styles.userBioRow}>
<Text style={styles.userBioLogo} >Faculdade</Text>
<TextInput style={styles.userBioText}
onChangeText={(job) => {
@ -208,7 +230,7 @@ class Profile extends Component {
<View style={styles.userBioRow}>
<Icon name="ios-phone-portrait" style={styles.userBioLogo} size={25}/>
<Text style={styles.userBioLogo} >Telemóvel</Text>
<TextInput style={styles.userBioText}
onChangeText={(phone) => {
@ -220,7 +242,7 @@ class Profile extends Component {
<View style={styles.userBioRow}>
<Icon name="ios-map" style={styles.userBioLogo} size={25}/>
<Text style={styles.userBioLogo} >Morada</Text>
<TextInput style={styles.userBioText}
onChangeText={(add) => {
@ -232,22 +254,19 @@ class Profile extends Component {
<Divider style={{backgroundColor: 'black'}}/>
<View style={styles.userBioRow}>
<Icon name="ios-map" style={styles.userBioLogo} size={25}/>
<Text style={styles.userBioLogo} >LinkedIn</Text>
<TextInput style={styles.userBioText}
onChangeText={(city) => {
this.setState({city: city})
onChangeText={(u) => {
this.setState({url: u})
}}
value={this.state.city}/>
value={this.state.url}/>
</View>
<Divider style={{backgroundColor: 'black'}}/>
<View style={styles.userBioRow}>
<Icon name="ios-person" style={styles.userBioLogo} size={25}/>
<TouchableOpacity>
<Text style={styles.userCurriculum}>O meu Curriculo</Text>
</TouchableOpacity>
</View>
<Button onPress={() => this.saveData() } title="Guardar Alterações" color="#CC1A17"
/>
</View>
</View>
@ -255,51 +274,77 @@ class Profile extends Component {
<View style={styles.container}>
<View style={styles.userBioRowHeader}>
<View style={styles.userBioRowTitle}>
<Text style={{color: '#CC1A17', fontWeight: 'bold', fontSize: 20}}>Nova Password:</Text>
<Text style={{color: '#CC1A17', fontWeight: 'bold', fontSize: 20}}>Alterar Password</Text>
</View>
</View>
<View style={styles.userBio}>
<View style={styles.userBioRow}>
<Text style={styles.userPassText} size={20}>
Old Password:
</Text>
<View style={styles.userBioRow}>
<TextInput style={styles.userBioText}
placeholder='Antiga Password' secureTextEntry={true}
placeholder='Antiga Password'
onChangeText={(old => {
this.setState({oldPass: old})
})}
value={this.state.oldPass}
maxLength = {20}
secureTextEntry={true}
/>
</View>
<Divider style={{backgroundColor: 'black'}}/>
<View style={styles.userBioRow}>
<Text style={styles.userPassText} size={20}>
Nova Password:
</Text>
<TextInput style={styles.userBioText}
placeholder='Nova Password' secureTextEntry={true}
placeholder='Nova Password'
secureTextEntry={true}
onChangeText={(newz => {
this.setState({new1: newz})
})}
value={this.state.new1}
maxLength = {20}
/>
</View>
<Divider style={{backgroundColor: 'black'}}/>
<View style={styles.userBioRow}>
<Text style={styles.userPassText} size={20}>
Repetir Password:
</Text>
<TextInput style={styles.userBioText}
placeholder='Repetir Password' secureTextEntry={true}
placeholder='Repetir Password'
secureTextEntry={true}
onChangeText={(newzz => {
this.setState({new2: newzz})
})}
value={this.state.new2}
maxLength = {20}
/>
</View>
<Button onPress={this._press} title="Alterar Password" color="#CC1A17"
/>
</View>
</View>
<TouchableOpacity onPress={this._logout} style={{
height: 50,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'black',
marginTop:30
}}>
<Text style={{color: "#fff", fontWeight: 'bold'}}>Logout</Text>
</TouchableOpacity>
</ScrollView>
<TouchableOpacity onPress={this._logout} style={{
height: 50,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#CC1A17'
}}>
<Text style={{color: "#fff", fontWeight: 'bold'}}>Logout</Text>
</TouchableOpacity>
</View>
@ -335,14 +380,14 @@ const styles = StyleSheet.create({
flexDirection: 'row',
justifyContent: 'flex-start',
padding: 10,
borderWidth: 2,
// borderWidth: 2,
alignItems: 'center',
},
userBioText: {
width: SCREEN_WIDTH * 0.40,
flex: 2,
borderWidth: 2,
// borderWidth: 2,
},
userPassText: {
@ -353,8 +398,8 @@ const styles = StyleSheet.create({
},
userBioLogo: {
marginLeft: SCREEN_WIDTH * 0.05,
width: SCREEN_WIDTH * 0.15,
marginLeft: 10,
width:80,
},
bottomLogOut: {

View File

@ -346,7 +346,7 @@ class choosePath extends React.Component {
{!this._verifySession(item[index].Id) && (
<TouchableOpacity
onPress={() => {
this.props.getUserInfo(this.props.userDetails.token)
//this.props.waitChangeGuest()
this.props.signSession(
this.props.user,

View File

@ -0,0 +1,29 @@
import React, {Component} from 'react';
import {
ActivityIndicator,
AsyncStorage,
Button,
StatusBar,
StyleSheet,
View,
} from 'react-native';
import {UtilStyles} from '../assets/styles'
export default class resetPassword extends Component {
constructor() {
super();
this._bootstrapAsync();
}
// Render Loading
render() {
return (
<View style={UtilStyles.containerLoading}>
<Text>Reset Password</Text>
</View>
);
}
}

View File

@ -9,6 +9,7 @@ export const LOGOUT_USER= 'LOGOUT_USER';
export const USER_INFO= 'USER_INFO'
export const HOLD='HOLD'
export const GET_EVENTS='GET_EVENTS'
export const UPDATE_USER='UPDATE_USER'
//API BLUETREND CALENDÁRIO
@ -19,7 +20,6 @@ export const SIGN_SESSION= 'SIGN_SESSION'
export const WAIT_CHANGE='WAIT_CHANGE'
export const REMOVE_SESSION = 'REMOVE_SESSION'
//UI
//LOGIN

View File

@ -21,7 +21,8 @@ import {
SIGN_SESSION,
OPEN_MODAL,
LOADINGLOGIN,
REMOVE_SESSION
REMOVE_SESSION,
UPDATE_USER
} from "./actionTypes"; //Import the actions types constant we defined in our actions
import moment from "moment";
@ -48,6 +49,34 @@ export function waitLogin() {
};
}
export function changePassword(token, old, new1, new2) {
axios.defaults.headers.common = {
Authorization: `bearer ${token.access_token}`
};
axios.defaults.baseURL = "http://enei2019.uingress.com/internal/api";
return dispatch => {
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
});
}
};
}
//faz autenticação com API interna
export function loginInternal(userDetails) {
axios.defaults.baseURL = "http://127.0.0.1:5000";
@ -91,23 +120,29 @@ export function closeModal() {
}
export function updateUser(token, user) {
axios.defaults.baseURL = "http://enei2019.uingress.com/internal/api";
axios.defaults.headers.common = {
Authorization: `bearer ${token.access_token}`
};
return dispatch => {
axios
.post("/Attendee/Edit", user)
.post("/Attendee/Edit", user)
.then(a => {
console.log(a);
alert("guardado com sucesso");
Alert.alert("Sucesso", "As informações pessoais foram guardadas com sucesso.")
console.log(a.data)
dispatch({
type: UPDATE_USER
// guests: response.data
type: UPDATE_USER,
user:a.data
});
})
.catch(b => {
alert("Erro a guardar os dados");
Alert.alert("ERRO!","Ocorreu um erro a guardar os dados pessoais.")
alert(b)
});
};
}
@ -163,7 +198,7 @@ export const connectionState = status => {
return { type: "CHANGE_CONNECTION_STATUS", isConnected: status };
};
export function removeSession(user,token, idSession) {
export function removeSession(user, token, idSession) {
axios.defaults.headers.common = {
Authorization: `bearer ${token.access_token}`
};
@ -179,7 +214,7 @@ export function removeSession(user,token, idSession) {
.post("/Session/RemoveAttendee", obj)
//se não existir erro na chamada...
.then(a => {
console.log(a)
console.log(a);
if (a.data.Success) {
axios
.get("/Attendee/AvailableSessions")
@ -198,7 +233,10 @@ export function removeSession(user,token, idSession) {
cenas.push(result[key]);
}
Alert.alert("Sucesso","A inscrição na sessão foi removida com sucesso!");
Alert.alert(
"Sucesso",
"A inscrição na sessão foi removida com sucesso!"
);
//obter informações pessoais:
axios
@ -225,7 +263,6 @@ export function removeSession(user,token, idSession) {
console.log(error);
});
} else {
alert("Erro a inscrever na palestra");
dispatch({
type: REMOVE_SESSION,
@ -240,7 +277,7 @@ export function removeSession(user,token, idSession) {
}
//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}`
};
@ -274,8 +311,11 @@ export function signSession(user,token, idSession) {
cenas.push(result[key]);
}
Alert.alert("Sucesso","Inscrição na sessão efectuada com sucesso");
Alert.alert(
"Sucesso",
"Inscrição na sessão efectuada com sucesso"
);
//obter informações pessoais:
axios
.get("/Attendee/Detail")
@ -284,24 +324,27 @@ export function signSession(user,token, idSession) {
alert(error);
})
.then(sucess => {
var result = getE(user);
dispatch({
type: SIGN_SESSION,
sessions: response.data,
Blocks: cenas,
changeGuestList: false,
careerPath: careerPath,
user: sucess.data
user: sucess.data,
events: result.a,
day1: result.a,
day2: result.b,
day3: result.c,
day4: result.d
});
getEvents(user);
});
})
.catch(function(error) {
console.log(error);
});
} else {
Alert.alert("ERRO!!",a.data.Error);
Alert.alert("ERRO!!", a.data.Error);
dispatch({
type: SIGN_SESSION,
waitChangeGuest: false
@ -309,8 +352,7 @@ export function signSession(user,token, idSession) {
}
})
.catch(b => {
// alert("Erro a inscrever na palestra");
// alert("Erro a inscrever na palestra");
});
};
}
@ -530,112 +572,112 @@ export function getAvailableSessions(token) {
};
}
function getE(user) {
var cenas = [];
let events = [];
var i = 0;
for (let key in user.Sessions) {
events.push({
key: i++,
time: moment(user.Sessions[key].SessionStart).format("HH:mm"),
timeEnd: moment(user.Sessions[key].SessionEnd).format("HH:mm"),
//lineColor:'#009688',
imageUrl:
"https://d2v9y0dukr6mq2.cloudfront.net/video/thumbnail/Vjkyj2hBg/welcome-white-sign-with-falling-colorful-confetti-animation-on-white-background_sglmmh3qm__F0013.png",
description: user.Sessions[key].Description,
name: user.Sessions[key].Name,
Enrolled: user.Sessions[key].Enrolled,
MaxAttendees: user.Sessions[key].MaxAttendees,
day: moment(user.Sessions[key].SessionStart).format("DD")
});
}
const result = flow(groupBy("day"))(events);
for (let key in result) {
cenas.push(result[key]);
}
var a = [],
b = [],
c = [],
d = [];
for (let key in cenas[0]) {
a.push({
time: cenas[0][key].time,
timeEnd: cenas[0][key].timeEnd,
imageUrl: cenas[0][key].imageUrl,
description: cenas[0][key].description,
name: cenas[0][key].name,
Enrolled: cenas[0][key].Enrolled,
MaxAttendees: cenas[0][key].MaxAttendees,
day: cenas[0][key].day
});
}
for (let key in cenas[1]) {
b.push({
time: cenas[1][key].time,
timeEnd: cenas[1][key].timeEnd,
imageUrl: cenas[1][key].imageUrl,
description: cenas[1][key].description,
name: cenas[1][key].name,
Enrolled: cenas[1][key].Enrolled,
MaxAttendees: cenas[1][key].MaxAttendees,
day: cenas[1][key].day
});
}
for (let key in cenas[2]) {
c.push({
time: cenas[2][key].time,
timeEnd: cenas[2][key].timeEnd,
imageUrl: cenas[2][key].imageUrl,
description: cenas[2][key].description,
name: cenas[2][key].name,
Enrolled: cenas[2][key].Enrolled,
MaxAttendees: cenas[2][key].MaxAttendees,
day: cenas[2][key].day
});
}
for (let key in cenas[3]) {
d.push({
time: cenas[3][key].time,
timeEnd: cenas[3][key].timeEnd,
imageUrl: cenas[3][key].imageUrl,
description: cenas[3][key].description,
name: cenas[3][key].name,
Enrolled: cenas[3][key].Enrolled,
MaxAttendees: cenas[3][key].MaxAttendees,
day: cenas[3][key].day
});
}
a = _.sortBy(a, function(o) {
return o.time;
});
b = _.sortBy(b, function(o) {
return o.time;
});
c = _.sortBy(c, function(o) {
return o.time;
});
d = _.sortBy(d, function(o) {
return o.time;
});
return { a, b, c, d };
}
export function getEvents(user) {
var result = getE(user);
return dispatch => {
let events = [];
console.log("chegou aqui");
var i = 0;
for (let key in user.Sessions) {
events.push({
key: i++,
time: moment(user.Sessions[key].SessionStart).format("HH:mm"),
timeEnd: moment(user.Sessions[key].SessionEnd).format("HH:mm"),
//lineColor:'#009688',
imageUrl:
"https://d2v9y0dukr6mq2.cloudfront.net/video/thumbnail/Vjkyj2hBg/welcome-white-sign-with-falling-colorful-confetti-animation-on-white-background_sglmmh3qm__F0013.png",
description: user.Sessions[key].Description,
name: user.Sessions[key].Name,
Enrolled: user.Sessions[key].Enrolled,
MaxAttendees: user.Sessions[key].MaxAttendees,
day: moment(user.Sessions[key].SessionStart).format("DD")
});
}
const result = flow(groupBy("day"))(events);
var cenas = [];
for (let key in result) {
cenas.push(result[key]);
console.log();
}
console.log(".--------");
console.log(cenas);
console.log(".--------");
var a = [],
b = [],
c = [],
d = [];
for (let key in cenas[0]) {
a.push({
time: cenas[0][key].time,
timeEnd: cenas[0][key].timeEnd,
imageUrl: cenas[0][key].imageUrl,
description: cenas[0][key].description,
name: cenas[0][key].name,
Enrolled: cenas[0][key].Enrolled,
MaxAttendees: cenas[0][key].MaxAttendees,
day: cenas[0][key].day
});
}
for (let key in cenas[1]) {
b.push({
time: cenas[1][key].time,
timeEnd: cenas[1][key].timeEnd,
imageUrl: cenas[1][key].imageUrl,
description: cenas[1][key].description,
name: cenas[1][key].name,
Enrolled: cenas[1][key].Enrolled,
MaxAttendees: cenas[1][key].MaxAttendees,
day: cenas[1][key].day
});
}
for (let key in cenas[2]) {
c.push({
time: cenas[2][key].time,
timeEnd: cenas[2][key].timeEnd,
imageUrl: cenas[2][key].imageUrl,
description: cenas[2][key].description,
name: cenas[2][key].name,
Enrolled: cenas[2][key].Enrolled,
MaxAttendees: cenas[2][key].MaxAttendees,
day: cenas[2][key].day
});
}
for (let key in cenas[3]) {
d.push({
time: cenas[3][key].time,
timeEnd: cenas[3][key].timeEnd,
imageUrl: cenas[3][key].imageUrl,
description: cenas[3][key].description,
name: cenas[3][key].name,
Enrolled: cenas[3][key].Enrolled,
MaxAttendees: cenas[3][key].MaxAttendees,
day: cenas[3][key].day
});
}
a = _.sortBy(a, function(o) {
return o.time;
});
b = _.sortBy(b, function(o) {
return o.time;
});
c = _.sortBy(c, function(o) {
return o.time;
});
d = _.sortBy(d, function(o) {
return o.time;
});
dispatch({
type: GET_EVENTS,
events: a,
day1: a,
day2: b,
day3: c,
day4: d
events: result.a,
day1: result.a,
day2: result.b,
day3: result.c,
day4: result.d
});
};
}

View File

@ -17,7 +17,8 @@ export {checkUser,
closeModal,
loginInternal,
waitLogin,
removeSession
removeSession,
changePassword
} from "./api"

View File

@ -16,7 +16,9 @@ import {
OPEN_MODAL,
CLOSE_MODAL,
LOADINGLOGIN,
REMOVE_SESSION
REMOVE_SESSION,
UPDATE_USER,
} from "../actions/actionTypes"; //Import the actions types constant we defined in our actions
import { REHYDRATE } from "redux-persist";
@ -99,6 +101,9 @@ const apiReducer = (state = apiState, action) => {
isConnected: action.isConnected
});
case UPDATE_USER:
state = Object.assign({}, state, { user:action.user});
return state
case LOADINGLOGIN:
state = Object.assign({}, state, { loadingLogin: true });
@ -201,12 +206,17 @@ const apiReducer = (state = apiState, action) => {
});
}
else{
state = Object.assign({}, state, {
sessions: action.sessions,
Blocks: action.Blocks,
careerPath: action.careerPath,
changingGuest: false,
user: action.user
user: action.user,
a:action.day1,
b:action.day2,
c:action.day3,
d:action.day4
});
}