-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from infoshareacademy/FZ12OK-51-Login
Fz12 ok 51 login
- Loading branch information
Showing
12 changed files
with
1,344 additions
and
107 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ | |
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ | ||
--> | ||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> | ||
|
||
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.css" /> | ||
<!-- | ||
Notice the use of %PUBLIC_URL% in the tags above. | ||
It will be replaced with the URL of the `public` folder during the build. | ||
|
@@ -44,5 +46,6 @@ | |
To begin the development, run `npm start` or `yarn start`. | ||
To create a production bundle, use `npm run build` or `yarn build`. | ||
--> | ||
</body> | ||
</html> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
|
||
import React from 'react'; | ||
import { Button, Divider, Grid, Segment, Form, Message } from 'semantic-ui-react' | ||
import firebase from "firebase"; | ||
|
||
export function Login() { | ||
return <Segment > | ||
<Grid columns={2} relaxed='very' stackable> | ||
<Grid.Column verticalAlign='middle'> | ||
<SignIn /> | ||
</Grid.Column> | ||
<Grid.Column verticalAlign='middle'> | ||
<SignUp /> | ||
</Grid.Column> | ||
</Grid> | ||
<Divider vertical>Lub</Divider> | ||
</Segment> | ||
} | ||
|
||
|
||
|
||
export class SignIn extends React.Component { | ||
state = { | ||
email: '', | ||
password: '', | ||
error: null | ||
}; | ||
|
||
handleOnChange = ({ target: { name, value } }) => { | ||
this.setState({ | ||
[name]: value | ||
}) | ||
}; | ||
|
||
handleOnClick = (event) => { | ||
event.preventDefault(); | ||
this.signIn(); | ||
}; | ||
|
||
|
||
signIn = () => { | ||
const { email, password } = this.state; | ||
firebase.auth().signInWithEmailAndPassword(email, password) | ||
.catch(error => { | ||
const errorCode = error.code; | ||
if (errorCode == 'auth/user-disabled') { | ||
this.setState({ error: 'Twoje konto zostało zablokowane.' }); | ||
} | ||
else if (errorCode == 'auth/invalid-email') { | ||
this.setState({ error: 'Nieprawidłowy adres e-mail.' }); | ||
} | ||
else if (errorCode == 'auth/user-not-found') { | ||
this.setState({ error: 'Dla tego adresu e-mail konto nie istnieje.' }); | ||
} | ||
else if (errorCode == 'auth/wrong-password') { | ||
this.setState({ error: 'Błędne hasło.' }); | ||
} | ||
else { | ||
this.setState({ error: 'nieznany błąd' }); | ||
} | ||
}); | ||
}; | ||
|
||
render() { | ||
const { email, password, error } = this.state; | ||
|
||
return (<Form> | ||
<Message | ||
icon='key' | ||
header='Zaloguj się' | ||
content='by używać aplikacji' | ||
/> | ||
<Message | ||
icon='x' | ||
negative | ||
hidden={!error && true} | ||
content={error} | ||
/> | ||
<Form.Input | ||
required | ||
type="email" | ||
fluid icon='user' | ||
iconPosition='left' | ||
placeholder='E-mail' | ||
value={email} | ||
name='email' | ||
onChange={this.handleOnChange} | ||
/> | ||
<Form.Input | ||
required | ||
fluid | ||
icon='lock' | ||
iconPosition='left' | ||
placeholder='Hasło' | ||
type='password' | ||
value={password} | ||
name='password' | ||
onChange={this.handleOnChange} | ||
/> | ||
<Button content='Zaloguj' primary fluid onClick={this.handleOnClick} /> | ||
</Form>) | ||
} | ||
} | ||
|
||
export default class SignUp extends React.Component { | ||
state = { | ||
name: '', | ||
email: '', | ||
password: '', | ||
error: null | ||
}; | ||
|
||
handleOnChange = ({ target: { name, value } }) => { | ||
this.setState({ | ||
[name]: value | ||
}) | ||
}; | ||
|
||
handleOnClick = (event) => { | ||
event.preventDefault(); | ||
this.signUp(); | ||
}; | ||
|
||
signUp = () => { | ||
const { email, password, name } = this.state; | ||
firebase.auth().createUserWithEmailAndPassword(email, password) | ||
.then(() => { | ||
const user = firebase.auth().currentUser | ||
|
||
|
||
if (user) { | ||
console.log(user); | ||
user.updateProfile({ | ||
displayName: name, | ||
}) | ||
.then(s => console.log(s)) | ||
.catch(err => console.log(err)) | ||
} | ||
}) | ||
.catch(error => { | ||
const errorCode = error.code; | ||
if (errorCode == 'auth/weak-password') { | ||
this.setState({ error: 'Zbyt słabe hasło. Hasło musi mieć co najmniej 6 znaków.' }); | ||
} | ||
else if (errorCode == 'auth/invalid-email') { | ||
this.setState({ error: 'Nieprawidłowy adres e-mail.' }); | ||
} | ||
else if (errorCode == 'auth/email-already-in-use') { | ||
this.setState({ error: 'Dla tego adresu e-mail konto już istnieje.' }); | ||
} | ||
else if (errorCode == 'auth/operation-not-allowed') { | ||
this.setState({ error: 'Błąd rejestracji po stronie serwera. Przepraszamy.' }); | ||
} | ||
else { | ||
this.setState({ error: 'nieznany błąd' }); | ||
} | ||
}); | ||
}; | ||
|
||
render() { | ||
const { email, password, error, name } = this.state; | ||
return ( | ||
<Form> | ||
<Message | ||
icon='user plus' | ||
header='Rejestracja' | ||
content='jeśli jeszcze nie masz konta, zarejestruj się.' | ||
/> | ||
<Message | ||
icon='x' | ||
negative | ||
hidden={!error && true} | ||
content={error} | ||
/> | ||
<Form.Input | ||
required | ||
fluid | ||
icon='user' | ||
iconPosition='left' | ||
placeholder='Name' | ||
type="text" | ||
value={name} | ||
name='name' | ||
onChange={this.handleOnChange} | ||
/> | ||
<Form.Input | ||
required | ||
fluid | ||
icon='mail' | ||
iconPosition='left' | ||
placeholder='E-mail' | ||
type="email" | ||
value={email} | ||
name='email' | ||
onChange={this.handleOnChange} | ||
/> | ||
<Form.Input | ||
required | ||
fluid | ||
icon='lock' | ||
iconPosition='left' | ||
placeholder='Hasło' | ||
type='password' | ||
value={password} | ||
name='password' | ||
onChange={this.handleOnChange} | ||
/> | ||
<Button positive content={'Utwórz konto'} fluid onClick={this.handleOnClick} /> | ||
</Form> | ||
|
||
|
||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.