Skip to content

Commit

Permalink
routing updated
Browse files Browse the repository at this point in the history
  • Loading branch information
campriest committed Jan 7, 2018
1 parent 16ab85e commit d26ff7e
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 28 deletions.
35 changes: 27 additions & 8 deletions Login.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
import React from 'react';
import { StyleSheet, TextInput, Text, View, Button} from 'react-native';
import axios from 'axios';
import { StyleSheet, TextInput, Text, View, Button, TouchableOpacity} from 'react-native';
import querystring from 'querystring';



export default class Login extends React.Component{

constructor(){

super();

this.state = {
username: 'enter username',
password: 'enter password'
}


}


emailInput = () => {
//const emailValue
logIn = (e) => {
axios.post('http:https://192.168.1.2:3000/login', querystring.stringify({
username: this.state.username,
password: this.state.password

//console.log(emailValue);

}))
.then(function(res){

console.log(res);
})
.catch(function(error){

console.log(error);
})

console.log("login button pushed");

}

Expand All @@ -33,15 +51,16 @@ export default class Login extends React.Component{



<TextInput style = {styles.username} onChangeText = {(username) => this.setState({username})} value = {this.state.username}
<TextInput style = {styles.username} clearTextOnFocus = {true} onChangeText = {(username) => this.setState({username})} value = {this.state.username}
/>

<TextInput style = {styles.password} onChangeText = {(password) => this.setState({password})} value = {this.state.password}
<TextInput style = {styles.password} clearTextOnFocus = {true} onChangeText = {(password) => this.setState({password})} value = {this.state.password}
/>

<View style = {styles.buttonStyle} >

<Text style = {styles.buttonText}>Login</Text>
<TouchableOpacity onPress = {this.logIn}>
<Text style = {styles.buttonText}>Login</Text>
</TouchableOpacity>
</View>


Expand Down
35 changes: 27 additions & 8 deletions SignUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export default class Login extends React.Component{
this.state = {
firstName: 'enter name...',
lastName: 'enter last name...',
email: 'email...'
email: 'email...',
password: 'password...'

};

Expand All @@ -26,15 +27,19 @@ export default class Login extends React.Component{
onSignUp = (e) => {


axios.post('http:https://192.168.1.3:3000/insert', {

// firstName: e.state.firstName,
axios.post('http:https://192.168.1.2:3000/insert', querystring.stringify({

firstName: this.state.firstName,
lastName: this.state.lastName,
email: this.state.email,
password: this.state.password


// lastName: e.state.lastName

})


}))
.then(function(res){
console.log(res);
})
Expand Down Expand Up @@ -71,13 +76,16 @@ export default class Login extends React.Component{

<Text style = {styles.title}>Sign Up</Text>

<TextInput style = {styles.inputBoxFirst} onChangeText = {(firstName) => this.setState({firstName})} value = {this.state.firstName}
<TextInput style = {styles.inputBoxFirst} clearTextOnFocus = {true} onChangeText = {(firstName) => this.setState({firstName})} value = {this.state.firstName}
/>

<TextInput style = {styles.inputBoxLast} clearTextOnFocus = {true} onChangeText = {(lastName) => this.setState({lastName})} value = {this.state.lastName}
/>

<TextInput style = {styles.inputBoxLast} onChangeText = {(lastName) => this.setState({lastName})} value = {this.state.lastName}
<TextInput style = {styles.inputBoxEmail} clearTextOnFocus = {true} onChangeText = {(email) => this.setState({email})} value = {this.state.email}
/>

<TextInput style = {styles.inputBoxEmail} onChangeText = {(email) => this.setState({email})} value = {this.state.email}
<TextInput style = {styles.inputBoxPassword} clearTextOnFocus = {true} onChangeText = {(password) => this.setState({password})} value = {this.state.password}
/>


Expand Down Expand Up @@ -142,6 +150,17 @@ const styles = StyleSheet.create({

},

inputBoxPassword: {
marginTop: 20,
height: 20,
width: 200,
borderRadius: 5,
borderWidth: 1,
borderColor: 'rgb(0,0,0)'


},

buttonStyle: {
alignItems: 'center',
justifyContent: 'center',
Expand Down
15 changes: 15 additions & 0 deletions model/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var userSchema = new Schema({

email: String,
username: String,
firstName: String,
lastName: String,
password: String


});

module.exports = mongoose.model('User', userSchema);
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
"body-parser": "^1.18.2",
"expo": "^23.0.4",
"express": "^4.16.2",
"jsonwebtoken": "^8.1.0",
"mongodb": "^3.0.0",
"mongoose": "^4.13.7",
"morgan": "^1.9.0",
"nodemon": "^1.14.7",
"querystring": "^0.2.0",
"react": "16.0.0",
Expand Down
7 changes: 7 additions & 0 deletions server/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {

'secret' : 'test123',
'database' : 'mongodb:https://ccp0501:[email protected]:63826/beer'


}
70 changes: 58 additions & 12 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@ var express = require('express');
var bodyParser = require('body-parser');
var assert = require('assert');
//var MongoClient = require('mongoose').MongoClient;
var user = require('../model/User.js');

const app = express();
var router = express.Router();

var MongoClient = require('mongodb').MongoClient;
var morgan = require('morgan');

var mongoose = require('mongoose');
var User = require('../model/User.js');
var config = require('./config.js');
var jwt = require('jsonwebtoken');

app.use(bodyParser.urlencoded({
extended: true
}));

app.use(bodyParser.json({type: 'applicaiton/json'}));
app.set('tokenSecret', config.secret);
//get info from posts
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json({ type: 'application/json' }));
//logs requests to server
app.use(morgan('dev'));

//app.use('/', router);



var routerSignUp = express.Router();
var routerLoginIn = express.Router();



Expand All @@ -44,29 +52,67 @@ app.get('/', function(req, res){
//
// });

router.get('/', function(req, res){
routerSignUp.get('/', function(req, res){
res.send('Second Page');
console.log('start of the other side');
console.log(req.body);

});

router.post('/', function(req,res){
routerSignUp.post('/', function(req,res){

//res.send("works");
res.json(req.body);
//res.json(req.body);
console.log("from the other side");
console.log("first name: "+ req.body.firstName);
console.log("last name: " + req.body.lastName);
console.log("email: " + req.body.email);


});

app.use('/insert', router);

app.listen(3000,'192.168.1.3', () =>{
routerLoginIn.get('/', function(req, res){

res.send('Login Page');
console.log('Login works');


});

routerLoginIn.post('/',function(req,res){

console.log('login page validation');
console.log(req.body.username)

// User.findOne({
// //Fix to match right signup
// name: req.body.email
//
// }, function(err, user){
//
//
//
//
// })



});



app.use('/insert', routerSignUp);
app.use('/login', routerLoginIn);

app.listen(3000,'192.168.1.2', () =>{
console.log('route working');
});





module.exports = app;


Expand Down

0 comments on commit d26ff7e

Please sign in to comment.