From 9d95ce0106745649043252cfeac3174acdb3ba93 Mon Sep 17 00:00:00 2001
From: ric <s1094610@studenti.univpm.it>
Date: Mon, 6 Dec 2021 16:30:34 +0100
Subject: [PATCH] updating

---
 backend/models/userModel.js          |  3 ++-
 backend/routes/authRoutes.js         |  6 ++++--
 mobile/App.js                        | 13 +++++++++++++
 mobile/Screens/loginScreen.js        |  8 +++++++-
 mobile/Screens/registrationScreen.js | 19 +++++++++++++++----
 mobile/package-lock.json             |  5 +++++
 mobile/package.json                  |  1 +
 7 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/backend/models/userModel.js b/backend/models/userModel.js
index c895f05..43af5a6 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 d34fc2f..152945a 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 f1ae1a9..fa92607 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 a93bbc2..9d465ef 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 637d4fc..f5a805d 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 1d51cdb..1c7af36 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 842d4a4..a76da05 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",
-- 
GitLab