-
Notifications
You must be signed in to change notification settings - Fork 0
авторизация #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
base: master
Are you sure you want to change the base?
авторизация #3
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| .App { | ||
| text-align: center; | ||
| } | ||
|
|
||
| .App-logo { | ||
| animation: App-logo-spin infinite 20s linear; | ||
| height: 80px; | ||
| } | ||
|
|
||
| .App-header { | ||
| background-color: #222; | ||
| height: 150px; | ||
| padding: 20px; | ||
| color: white; | ||
| } | ||
|
|
||
| .App-title { | ||
| font-size: 1.5em; | ||
| } | ||
|
|
||
| .App-intro { | ||
| font-size: large; | ||
| } | ||
|
|
||
| @keyframes App-logo-spin { | ||
| from { transform: rotate(0deg); } | ||
| to { transform: rotate(360deg); } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import React, { Component } from 'react'; | ||
| import logo from './logo.svg'; | ||
| import './App.css'; | ||
| import {In} from './components/sign-in/sign-in'; | ||
| import Up from './components/sign-up/sign-up'; | ||
| import User from './components/user/user'; | ||
| import ReactDOM from 'react-dom'; | ||
| import { | ||
| Link, | ||
| BrowserRouter, | ||
| Route, | ||
| Switch, | ||
| withRouter, | ||
|
|
||
| } from "react-router-dom"; | ||
|
|
||
| class App extends Component { | ||
| render() { | ||
|
|
||
| return ( | ||
| <div> | ||
|
|
||
| <Route path = "/home" component={In}/> | ||
|
Member
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. add , and exact prop to each Route could be more safer decision |
||
| <Route path = "/sign-up" component={Up}/> | ||
| <Route path = "/user" component={User}/> | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export default App; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import React from 'react'; | ||
| import ReactDOM from 'react-dom'; | ||
| import App from './App'; | ||
|
|
||
| it('renders without crashing', () => { | ||
| const div = document.createElement('div'); | ||
| ReactDOM.render(<App />, div); | ||
| ReactDOM.unmountComponentAtNode(div); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| export const incrementCounter = (payload) => { | ||
|
Member
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. why do you need an increment counter? |
||
| return { | ||
| type: 'INCREMENT', | ||
| payload, | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| body { | ||
| margin: 0; | ||
| padding: 0; | ||
| font-family: sans-serif; | ||
| } | ||
| #first { | ||
|
Member
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. it's always better to use classNames over id. Using ids is a pitfall for bugs |
||
| height: 100px; | ||
| width: 100%; | ||
| border: 4px solid black; | ||
| } | ||
| #signIn { | ||
| float: right; | ||
| margin: 20px; | ||
| padding: 20px; | ||
| } | ||
| #logo { | ||
| float: right; | ||
| margin: 20px; | ||
| padding: 20px; | ||
| } | ||
| #up { | ||
| width: 50%; | ||
| border: 4px solid black; | ||
| margin-top: 100px; | ||
| padding: 20px; | ||
| } | ||
| #signUp { | ||
| float: right; | ||
| margin: 20px; | ||
| padding: 20px; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| import React, {Component} from 'react'; | ||
| import { | ||
| Link, | ||
| BrowserRouter, | ||
| Route, | ||
| Switch, | ||
| withRouter, | ||
| browserHistory | ||
| } from "react-router-dom"; | ||
| import {connect} from 'react-redux'; | ||
| import './sign-in.css' | ||
| import {incrementCounter} from '../../actions'; | ||
|
|
||
|
|
||
| let url3 = 'https://flatearth-api.herokuapp.com/api/v1/auth/login' | ||
|
Member
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. url3 is bad name, it could be something like const authURL = ...but from architecture point of view it's still no good to give component knowledge about URL, fetching resources, headers, etc. It should be another file, store in folder and // auth-api.js
const URLprefix = 'https://flatearth-api.herokuapp.com/api/v1/auth/'
const authAPI = {
login(user) {
const {
user,
password
} = user;
const loginURL = `${urlPrefix}/login`;
return fetch(loginURL, {}).then(data => data.json()) // with required headers, meta information, etc
}
}So you just importing such file and you component working with single method. |
||
| let url = 'https://flatearth-api.herokuapp.com/api/v1/auth/secret/' | ||
|
|
||
| var user1 = { | ||
| user:"", | ||
| password:"" | ||
| } | ||
|
|
||
|
|
||
| class Inn extends Component{ | ||
| state = { | ||
| userS: '', | ||
|
Member
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. why do you have usersS it's pretty weird. It adds 1 more "layer" to understanding your code. When I say "1 more layer". I mean - I have to understand what is behind of such suffix, what do you thinking about when add such suffix... I think we need to remove it |
||
| passwordS: '', | ||
| status: [] | ||
| }; | ||
|
|
||
| inputChangeUser = (event)=> { | ||
| this.setState({ | ||
|
Member
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. it's much easier to handle multiple inputs via such pattern please update it |
||
| userS: event.target.value, | ||
| }); | ||
| } | ||
| inputChangePassword = (event)=> { | ||
| this.setState({ | ||
| passwordS: event.target.value, | ||
| }); | ||
| } | ||
| addToUser =()=>{ | ||
| const {emailS,userS,passwordS} = this.state; | ||
|
|
||
| user1.user = userS | ||
|
Member
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. As I understand you made it just for optimization and mutation the same object. It does not really make any big impact on final app performance, but it makes code much harder to understand. In production apps in having an additional class for creating such an object, because of it easier to understand "mental model of application" |
||
| user1.password = passwordS | ||
| fetch( url3 , { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json' | ||
| }, | ||
| body: JSON.stringify(user1) | ||
| }).then(user => { | ||
| return user.json() | ||
| }).then(status => { | ||
| this.setState({status}) | ||
|
|
||
| fetch( url , { | ||
| method: 'GET', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| 'Authorization': `Bearer ${status.message.token}` | ||
| }, | ||
|
|
||
| }).then(user => { | ||
| return user.json() | ||
| }).then(secret => { | ||
| this.setState({secret}) | ||
| const {incrementCounter}=this.props; | ||
| //incrementCounter(status.message.token) | ||
| incrementCounter( secret.message) | ||
| }); | ||
|
|
||
| }); | ||
|
|
||
| } | ||
|
|
||
| render(){ | ||
| const {userS,passwordS,status} = this.state; | ||
|
|
||
|
|
||
| return( | ||
| <div> | ||
| <div id="first"> | ||
| <center> | ||
| <div id="signUp"><Link to ='/sign-up' exact>Sign-Up</Link></div> | ||
| <div id="logo"><img src="" alt="logo" /></div> | ||
| </center> | ||
| </div> | ||
| <center> | ||
| <div id="second"> | ||
| <center> | ||
| <h3>well come flat earch</h3> | ||
| <hr /> | ||
|
|
||
| <b>Username <input type="text" | ||
| value={userS} | ||
| onChange={this.inputChangeUser} | ||
| /></b><br /> | ||
| <b>Password <input type="text" | ||
| value={passwordS} | ||
| onChange={this.inputChangePassword} | ||
| /></b> | ||
| <div id="sigIn"> | ||
| <Link to ='/user' exact><button onClick={this.addToUser}>Войти</button></Link> | ||
|
Member
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. exact attribute(prop) at Link component is wrong place it's do nothing |
||
| <p><input type="checkbox" />запомнить</p> | ||
| </div> | ||
|
|
||
| </center> | ||
| </div> | ||
| </center> | ||
| </div> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| const mapStateToProps = (state) => { | ||
| console.log(state) | ||
| return { | ||
| counter: state.counter, | ||
| redux: 'is a power' | ||
| }; | ||
| }; | ||
|
|
||
| const mapDispatchToProps = { | ||
| incrementCounter, | ||
|
|
||
| }; | ||
|
|
||
| export const In = connect(mapStateToProps, mapDispatchToProps)(Inn); | ||
|
Member
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. name "In" - not really saying a lot about that component. |
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| body { | ||
| margin: 0; | ||
| padding: 0; | ||
| font-family: sans-serif; | ||
| } | ||
| #second { | ||
| width: 50%; | ||
| border: 4px solid black; | ||
| margin-top: 100px; | ||
| } | ||
| #signIn { | ||
| float: right; | ||
| margin: 20px; | ||
| padding: 20px; | ||
| } | ||
| #logo { | ||
| float: right; | ||
| margin: 20px; | ||
| padding: 20px; | ||
| } | ||
| #up { | ||
| width: 50%; | ||
| border: 4px solid black; | ||
| margin-top: 100px; | ||
| padding: 20px; | ||
| } | ||
| #signUp { | ||
| float: right; | ||
| margin: 20px; | ||
| padding: 20px; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import React, {Component} from 'react'; | ||
| import { | ||
| Link, | ||
| BrowserRouter, | ||
| Route, | ||
| Switch, | ||
| withRouter, | ||
|
|
||
|
Member
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 remove blank line |
||
| } from "react-router-dom"; | ||
| import './sign-up.css' | ||
|
|
||
| var user1 = { | ||
|
Member
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. You don't need to use |
||
| email:"", | ||
| user:"", | ||
| password:"" | ||
| } | ||
| let url2 = 'https://flatearth-api.herokuapp.com/api/v1/auth/signup' | ||
|
Member
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. the same about placing the URL link and API service/layer |
||
| class Up extends Component{ | ||
| constructor(props){ | ||
| super(props); | ||
| this.state = { | ||
| emailS: '', | ||
|
Member
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. the same question why do you need 's' suffix at the end |
||
| userS: '', | ||
| passwordS: '', | ||
| }; | ||
| } | ||
|
|
||
|
|
||
| inputChangeEmail = (event)=> { | ||
| this.setState({ | ||
| emailS: event.target.value, | ||
| }); | ||
| } | ||
| inputChangeUser = (event)=> { | ||
| this.setState({ | ||
| userS: event.target.value, | ||
| }); | ||
| } | ||
| inputChangePassword = (event)=> { | ||
| this.setState({ | ||
| passwordS: event.target.value, | ||
| }); | ||
| } | ||
|
|
||
| addToUser =()=>{ | ||
| const {emailS,userS,passwordS} = this.state; | ||
|
|
||
| user1.email = emailS | ||
| user1.user = userS | ||
| user1.password = passwordS | ||
| fetch( url2 , { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json' | ||
| }, | ||
| body: JSON.stringify(user1) | ||
| }).then(user => { | ||
| return user.json() | ||
| }).then(us => { | ||
| console.log(us); | ||
| }); | ||
| console.log(user1); | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| render(){ | ||
| const {emailS,userS,passwordS} = this.state; | ||
|
|
||
|
|
||
| return( | ||
| <div> | ||
| <div id="first"> | ||
| <center> | ||
| <div id="signIn"><Link to ='/home' exact>Sign-In</Link></div> | ||
| <div id="logo"><img src alt="logo" /></div> | ||
| </center> | ||
| </div> | ||
| <center> | ||
| <div id="up"> | ||
| <b>email</b><br /> | ||
| <input type="text" | ||
| value={emailS} | ||
| onChange={this.inputChangeEmail} | ||
| /><br /> | ||
| <b>name</b><br /> | ||
| <input type="text" | ||
| value={userS} | ||
| onChange={this.inputChangeUser} | ||
| /><br /> | ||
| <b>password</b><br /> | ||
| <input type="text" | ||
| value={passwordS} | ||
| onChange={this.inputChangePassword} | ||
| /><br /> | ||
| <button onClick={this.addToUser}>зарегистрировать</button> | ||
| </div> | ||
| </center> | ||
| </div> | ||
| ) | ||
| } | ||
| } | ||
| export default Up; | ||
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.
it seems like you don't use it, so we make remove it