Skip to content

Commit

Permalink
Merge branch 'feature/registerModal' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry-G committed Feb 2, 2018
2 parents 8e01c16 + 45b83cd commit 898026d
Show file tree
Hide file tree
Showing 10 changed files with 308 additions and 191 deletions.
12 changes: 8 additions & 4 deletions application/api/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,20 @@ def userRoute(id):


@users.route('/api/users/authenticate/', methods=httpMethods)
def userAuthenticate(id):
def userAuthenticate():

# convert request data to dictionary
data = toDict(request.data)

success = False # assume the response is unsucessful
message = "" # assume an empty message
status = "" # accepted statues: 'OK', 'DENIED', 'FAILURE', 'WARNING', 'INVALID'
response = {} # assume the response is empty dict() for now
user = {}

# If the reques is GET we assume your trying to login
if request.method == 'GET':
# Verify User
# If the reques is POST we assume your trying to login
if request.method == 'POST':
# Verify User
success = Users.userVerified(data['email'], data['password'])

# if verified then get the user
Expand Down
Binary file modified soen341.db
Binary file not shown.
Binary file modified static/public/favicon.ico
Binary file not shown.
74 changes: 63 additions & 11 deletions static/src/components/body/Body.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { Component } from 'react'
import {Row,Col} from'react-bootstrap'
import { Row, Col, Grid } from 'react-bootstrap'
import Register from './Register'
import Login from './LoginBox/Login'
import { connect } from 'react-redux'
class Body extends Component {

constructor(props) {
Expand All @@ -23,21 +24,72 @@ class Body extends Component {


render() {
let login;
if ((Object.keys(this.props.user).length === 0 && this.props.user.constructor === Object)) {
login = <div className="box-login">
<Login registerModal={this.handleShowRegister} />
</div>
}
return (
<div>
<Row>
<Col xs={12} md={3} mdOffset={9}>
<div className="box-login">
<Login registerModal={this.handleShowRegister}/>
</div>
</Col>
</Row>
<Register
show={this.state.showRegister}
handleClose={this.handleCloseRegister} />
<Grid fluid>
<Row>
<Col xs={12} md={9}><Grid fluid>
<p className="para">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p className="para">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p className="para">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p className="para">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</Grid>
</Col>
<Col xs={12} md={3}>
{login}
</Col>
</Row>
<Register
show={this.state.showRegister}
handleClose={this.handleCloseRegister} />
</Grid>
</div>
)
}
}

function mapStateToProps(state) {
return {
user: state.login.user
}
}

Body = connect(
mapStateToProps,
)(Body);

export default Body;
54 changes: 31 additions & 23 deletions static/src/components/body/LoginBox/Login.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,60 @@
import React, { Component } from 'react'
import { Form, FormGroup, ControlLabel, FormControl } from 'react-bootstrap'
import {login} from '../../../store/auth'
import { connect } from 'react-redux'
import { login } from '../../../store/auth'
class Login extends Component {
constructor(props) {
super(props);
this.handleLogin = this.handleLogin.bind(this)
this.state = {
email: "",
pw: ""
passw: ""
};
}

handleLogin() {
let user ={"id":100, "fname": 'Jon', "lname": 'Mongeau', "email":'[email protected]', "password_hash":'PASSWORD_HASH_HERE', "register_date": '2017-30-01', "engineer": 'software', "display_image": '/path/to/img/1.jpg', "verified": 1 , "ups":0, "downs":0}
login(user)
let user = { email: this.state.email, password: this.state.password }
this.sendLoginInfo(user)
}

async sendLoginInfo(user) {
try {
let myHeaders = new Headers();
myHeaders.append('Content-Type', 'application/json');
let myInit = {
method: 'POST',
body: JSON.stringify(user),
headers: myHeaders
};
let req = new Request("/api/users/authenticate/", myInit)
fetch(req).then(res => (res.json()))
.catch(e => console.error('Error:', e))
.then(response => {
try{
if (response.success) {
login(response.user)
}} catch(e){console.error("Error",e)}
})
} catch (e) { console.error("Error: ", e) }
}

render() {

console.log("user:"+ JSON.stringify(this.props.user))
return (
<Form>
<FormGroup bsSize="sm">
<ControlLabel>E-mail</ControlLabel>{' '}
<FormControl bsSize="sm" type="email" onChange={(e)=>{this.setState({email:e.target.value})}} placeholder="jon.raiz@example.com" />
<FormControl bsSize="sm" type="email" onChange={(e)=>{this.setState({email:e.target.value})}} placeholder="soen341@email.com" />
</FormGroup>{' '}
<FormGroup bsSize="sm">
<ControlLabel>Password</ControlLabel>{' '}
<FormControl bsSize="sm" type="password" onChange={(e)=>{this.setState({pw:e.target.value})}} />
<FormControl bsSize="sm" placeholder="password" type="password" onChange={(e)=>{this.setState({password:e.target.value})}} />
</FormGroup>{' '}
<a onClick={this.handleLogin}>Login </a>
or
<a onClick={this.props.registerModal}> Register</a>
<p><a className="link" onClick={this.handleLogin}>Login</a>
<span> or </span>
<a className="link" onClick={this.props.registerModal}>Register</a>
</p>
</Form>
);
}
}


function mapStateToProps(state) {
return {
user: state.login.user
}
}

Login = connect(
mapStateToProps,
)(Login);

export default Login;
Loading

0 comments on commit 898026d

Please sign in to comment.