diff --git a/backend/models/userModel.js b/backend/models/userModel.js index c895f0586a2933116e2676ef430d47c47f62de82..43af5a62f309dbaddcf73ab7cd1174e6d2b58757 100644 --- a/backend/models/userModel.js +++ b/backend/models/userModel.js @@ -3,7 +3,8 @@ const bcrypt = require('bcrypt'); const UserSchema = new mongoose.Schema({ username:String, - password: String + password: String, + physio: Boolean }) //Here we'll do the encryption diff --git a/backend/routes/authRoutes.js b/backend/routes/authRoutes.js index d34fc2ff9b90265655a73260ef7adc5ce5f731af..152945a2b5d7102ad6beb2223d989312d6e6744f 100644 --- a/backend/routes/authRoutes.js +++ b/backend/routes/authRoutes.js @@ -22,6 +22,7 @@ router.post('/signup', (req, res)=>{ const username = req.body.username; const password = req.body.password; + const physio = req.body.physio; userFromDb.findOne({'username':username}, function(err, result){ if(err){ console.log("Error with the database");}; @@ -30,7 +31,7 @@ router.post('/signup', (req, res)=>{ return res.status(422).send('Invalid username') } else{ - const user = new userFromDb({username:username, password:password}); + const user = new userFromDb({username:username, password:password, physio:physio}); user.save(); res.status(200).send('User registered'); } @@ -54,7 +55,8 @@ router.post('/signin', (req, res)=>{ if (err) throw err; //console.log(password, isMatch); if (isMatch){ - res.status(200).send('Login successful'); + res.status(200).send('ok'); + console.log(result.physio); }else{ return res.status(422).send('Invalid username or password'); } diff --git a/mobile/App.js b/mobile/App.js index f1ae1a9d78d06db8e53679d4b39cbe0cb3bc00d8..fa926072a6b7839258da4d6fdb6e94a45969c22f 100644 --- a/mobile/App.js +++ b/mobile/App.js @@ -19,6 +19,15 @@ function HomeTabs() { ); } +function PhysioTabs(){ + return ( + <Tab.Navigator> + <Tab.Screen name="Home" component={HomeScreen} /> + <Tab.Screen name="Chat" component={ChatScreen} /> + </Tab.Navigator> + ); +} + class App extends React.Component { //In the render here we define the application Screen routes @@ -42,6 +51,10 @@ class App extends React.Component { name="Registration" component={RegistrationScreen} /> + <Stack.Screen + name="test" + component={PhysioTabs} + /> </Stack.Navigator> </NavigationContainer> ); diff --git a/mobile/Screens/loginScreen.js b/mobile/Screens/loginScreen.js index a93bbc2e1b79d74e048255835868cc66fc88b6ed..9d465efbb627c1d9021281d115abbdd4b3a04baa 100644 --- a/mobile/Screens/loginScreen.js +++ b/mobile/Screens/loginScreen.js @@ -12,6 +12,7 @@ class LoginScreen extends Component { submitLogin() { + const bool = true; //here we're going to post the username and password inserted in the //login page, in particulare this is a post request to the /signin route //in the server that will response with status:200 if the credentials are in the @@ -32,7 +33,12 @@ class LoginScreen extends Component { } else { alert('Succesful login') - this.props.navigation.navigate('Chat') + if (bool){ + this.props.navigation.navigate('test') + } + else{ + this.props.navigation.navigate('Chat') + } } }) //here we set again username and password as blank diff --git a/mobile/Screens/registrationScreen.js b/mobile/Screens/registrationScreen.js index 637d4fc9661acb4f6a7f9edaab886912cddcdf4e..f5a805d308608edbf5b5babed82e0410c4f3c4c8 100644 --- a/mobile/Screens/registrationScreen.js +++ b/mobile/Screens/registrationScreen.js @@ -1,12 +1,13 @@ import React, {Component} from 'react'; -import { StyleSheet, Text, View, Button, TextInput } from 'react-native'; +import { StyleSheet, Text, View, Button, TextInput, Switch } from 'react-native'; class RegistrationScreen extends Component { constructor(props) { super(props); this.state = { username: "", - password: "" + password: "", + physio: false }; } @@ -21,7 +22,8 @@ class RegistrationScreen extends Component { }, body: JSON.stringify({ username : this.state.username, - password : this.state.password + password : this.state.password, + physio : this.state.physio }), }) .then(res =>{ @@ -36,6 +38,7 @@ class RegistrationScreen extends Component { this.setState({ username: "" }); this.setState({ password: "" }); + this.setState({ physio: false}); } render() { @@ -65,7 +68,15 @@ class RegistrationScreen extends Component { this.setState({ password }); }} /> - + <Switch + trackColor={{ false: "#767577", true: "#81b0ff" }} + thumbColor={this.state.physio ? "#f5dd4b" : "#f4f3f4"} + ios_backgroundColor="#3e3e3e" + onValueChange={physio => { + this.setState({ physio }) + }} + value={this.state.physio} + /> <Button title="Register" onPress={() => diff --git a/mobile/package-lock.json b/mobile/package-lock.json index 1d51cdb8a0c3f096867a497cfb1628c4d399fbb2..1c7af3651b85b4095173a356e47eead1feb15859 100644 --- a/mobile/package-lock.json +++ b/mobile/package-lock.json @@ -1393,6 +1393,11 @@ "fastq": "^1.6.0" } }, + "@react-native-community/checkbox": { + "version": "0.5.9", + "resolved": "https://registry.npmjs.org/@react-native-community/checkbox/-/checkbox-0.5.9.tgz", + "integrity": "sha512-2y/MW8zwXgzRN6fApZbYov3xKkR4vyWSOPo69OWSfa5emTbtKpSl7BY9xlKgu2pzGlLg5EyE8yogp0U7vFk+sQ==" + }, "@react-native-community/cli-debugger-ui": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/@react-native-community/cli-debugger-ui/-/cli-debugger-ui-5.0.1.tgz", diff --git a/mobile/package.json b/mobile/package.json index 842d4a440ffa507652a427070d20ae0f2a16682f..a76da0542b90e89b2adf150a0a59a0373e81a5d6 100644 --- a/mobile/package.json +++ b/mobile/package.json @@ -10,6 +10,7 @@ "eject": "expo eject" }, "dependencies": { + "@react-native-community/checkbox": "^0.5.9", "@react-navigation/bottom-tabs": "^6.0.9", "@react-navigation/drawer": "^6.1.8", "@react-navigation/native": "^6.0.6",