-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
123 link auth to form #167
base: dev
Are you sure you want to change the base?
Changes from 4 commits
f5b41d2
b5efa72
bb6c719
9d6f633
876ffab
34c9d1f
3d518b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import {setToken} from '../utils/tokens' | ||
import {register as registerApi, signin as signinApi} from '../api/auth' | ||
import {registerApi} from '../api/auth' | ||
import {signin as signinApi} from '../api/auth' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need 2 consecutive blank lines? Your linter should complain about this. |
||
|
||
export const signinPending = _ => { | ||
return { | ||
|
@@ -50,6 +52,7 @@ export const signin = (user) => dispatch => { | |
} | ||
|
||
export const register = (user) => dispatch => { | ||
console.log(user) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remove this console.log |
||
dispatch(registerPending()) | ||
return registerApi(user) | ||
.then(res => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,8 @@ import request from 'superagent' | |
|
||
const url = 'http://localhost:3000/api/v1/auth' | ||
|
||
export function register (user) { | ||
export function registerApi (user) { | ||
console.log('hello') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove console.log |
||
return request | ||
.post(`${url}/register`) | ||
.send(user) | ||
|
@@ -12,5 +13,6 @@ export function register (user) { | |
export const signin = (user) => { | ||
return request | ||
.post(`${url}/signin`) | ||
.send({ user }) | ||
.then(res => res.body) | ||
.send(user) | ||
.then(res => res.body) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,55 @@ | ||
import React from 'react' | ||
import {connect} from 'react-redux' | ||
|
||
class Register extends React.Component { | ||
constructor (props) { | ||
super(props) | ||
this.state = { | ||
import {register, registerError} from '../actions/auth' | ||
|
||
export class Register extends React.Component { | ||
state = { | ||
name: '', | ||
surname: '', | ||
hash: '', | ||
role: '', | ||
cohort: '' | ||
password: '' | ||
// role: '', | ||
// cohort: '' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remove these properties completely instead of commenting them out. |
||
} | ||
|
||
this.handleChange = this.handleChange.bind(this) | ||
this.handleSubmit = this.handleSubmit.bind(this) | ||
} | ||
registering = () => { | ||
const { name, surname, password } = this.state | ||
|
||
handleSubmit (evt) { | ||
this.props.saveItem(this.state) | ||
this.setState(this.state) | ||
evt.preventDefault() | ||
} | ||
if(!name) { | ||
return this.props.dispatch(registerFailure('Must provide name.')) | ||
} | ||
if(!surname) { | ||
return this.props.dispatch(registerFailure('Must provide surname.')) | ||
} | ||
if(!password) { | ||
return this.props.dispatch(registerFailure('Must provide email.')) | ||
} | ||
|
||
this.props.dispatch(register({name, surname, password})) | ||
|
||
handleChange (evt) { | ||
this.setState({ | ||
[evt.target.name]: evt.target.value | ||
name: '', | ||
surname: '', | ||
password: '' | ||
}) | ||
} | ||
|
||
resetForm (evt) { | ||
handleChange = (event) => { | ||
this.setState({ | ||
item: this.state, | ||
invalid: {} | ||
[event.target.name]: event.target.value | ||
}) | ||
evt && evt.preventDefault() | ||
} | ||
|
||
render () { | ||
console.log(this.state) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove console.log |
||
return ( | ||
<form> | ||
<label htmlFor='name'>First name</label> | ||
<br/> | ||
<input type='text' placeholder='First name' name='name' | ||
<input | ||
type='text' | ||
placeholder='First name' | ||
name='name' | ||
className='u-full-width' | ||
value={this.state.name} | ||
onChange={this.handleChange} | ||
|
@@ -49,27 +58,55 @@ class Register extends React.Component { | |
<br/> | ||
<label htmlFor='surname'>Surname</label> | ||
<br/> | ||
<input type='text' placeholder='Last name' name='surname' | ||
<input | ||
type='text' | ||
placeholder='Last name' | ||
name='surname' | ||
className='u-full-width' | ||
value={this.state.name} | ||
value={this.state.surname} | ||
onChange={this.handleChange} | ||
/> | ||
<br/> | ||
<br/> | ||
<label htmlFor='hash'>Hash</label> | ||
<br/> | ||
<input type='password' placeholder='Password' name='password' | ||
<input | ||
type='password' | ||
placeholder='Password' | ||
name='password' | ||
className='u-full-width' | ||
value={this.state.description} | ||
value={this.state.password} | ||
onChange={this.handleChange} | ||
/> | ||
<br/> | ||
<br/> | ||
<label htmlFor='role'>Role</label> | ||
<br/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the |
||
<button | ||
type='submit' | ||
className='button-primary' | ||
value='Add' | ||
onClick={this.registering} | ||
> | ||
Register</button> | ||
</form> | ||
) | ||
} | ||
} | ||
|
||
const mapStateToProps = ({auth}) => { | ||
return { | ||
auth | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want to refactor lines 96-100, you can do it with one line: |
||
|
||
export default connect(mapStateToProps)(Register) | ||
|
||
|
||
{/* <label htmlFor='role'>Role</label> | ||
<br/> | ||
<select placeholder='Are you a student or a teacher?' name='role' | ||
className='u-full-width' | ||
value={this.state.description} | ||
value={this.state.role} | ||
onChange={this.handleChange} | ||
> | ||
<option value="student">Student</option> | ||
|
@@ -78,19 +115,10 @@ class Register extends React.Component { | |
<br/> | ||
<br/> | ||
{/* cohort will be a drop down box */} | ||
<label htmlFor='cohort'>Cohort</label> | ||
{/* <label htmlFor='cohort'>Cohort</label> | ||
<br/> | ||
<input type='text' name='cohort' placeholder='Your cohort' | ||
className='u-full-width' | ||
value={this.state.description} | ||
value={this.state.cohor} | ||
onChange={this.handleChange} | ||
/> | ||
<br/> | ||
<button type='submit' className='button-primary' value='Add' onSubmit={this.handleSubmit} | ||
onClick={this.resetForm}>Register</button> | ||
</form> | ||
) | ||
} | ||
} | ||
|
||
export default Register | ||
/> */} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove all of these comments |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import {getToken} from '../utils/tokens' | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please undo this change. |
||
const initialState = { | ||
error: null, | ||
loggedIn: !!getToken(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ router.post('/register', register, token.issue) | |
router.post('/login', validateLogin, checkUser, token.issue) | ||
|
||
function register (req, res, next) { | ||
console.log(req.body) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please undo this change. |
||
db.registerUser(req.body) | ||
.then(([id]) => { | ||
res.locals.userId = id | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
register
is a better name. Can you rename the function in the../api/auth
file?