Browse Source

first auth version

Ata 3 years ago
parent
commit
b55bf98f82
58 changed files with 17471 additions and 0 deletions
  1. 1 0
      final-modul-react/.eslintcache
  2. 23 0
      final-modul-react/.gitignore
  3. 70 0
      final-modul-react/README.md
  4. 16540 0
      final-modul-react/package-lock.json
  5. 44 0
      final-modul-react/package.json
  6. 29 0
      final-modul-react/public/index.html
  7. 3 0
      final-modul-react/src/App.css
  8. 31 0
      final-modul-react/src/App.js
  9. 18 0
      final-modul-react/src/api/auth.js
  10. 38 0
      final-modul-react/src/api/common.js
  11. 6 0
      final-modul-react/src/api/index.js
  12. 22 0
      final-modul-react/src/api/users.js
  13. 19 0
      final-modul-react/src/components/Button/Button.jsx
  14. 2 0
      final-modul-react/src/components/Button/index.js
  15. 0 0
      final-modul-react/src/components/Button/style.css
  16. 24 0
      final-modul-react/src/components/Input/Input.jsx
  17. 2 0
      final-modul-react/src/components/Input/index.js
  18. 14 0
      final-modul-react/src/components/Label/Label.jsx
  19. 2 0
      final-modul-react/src/components/Label/index.js
  20. 0 0
      final-modul-react/src/components/Label/style.css
  21. 2 0
      final-modul-react/src/components/withAuthWrapper/index.js
  22. 30 0
      final-modul-react/src/components/withAuthWrapper/style.css
  23. 31 0
      final-modul-react/src/components/withAuthWrapper/withAuthWrapper.jsx
  24. 5 0
      final-modul-react/src/constants/messages.js
  25. 19 0
      final-modul-react/src/constants/users.js
  26. 15 0
      final-modul-react/src/container/Auth/Auth.jsx
  27. 2 0
      final-modul-react/src/container/Auth/index.js
  28. 30 0
      final-modul-react/src/container/Auth/style.css
  29. 23 0
      final-modul-react/src/container/Dashboard/Dashboard.jsx
  30. 2 0
      final-modul-react/src/container/Dashboard/index.js
  31. 0 0
      final-modul-react/src/container/Dashboard/style.css
  32. 32 0
      final-modul-react/src/container/Header/Header.jsx
  33. 2 0
      final-modul-react/src/container/Header/index.js
  34. 18 0
      final-modul-react/src/container/Header/style.css
  35. 17 0
      final-modul-react/src/container/HomePage/HomePage.jsx
  36. 2 0
      final-modul-react/src/container/HomePage/index.js
  37. 0 0
      final-modul-react/src/container/HomePage/style.css
  38. 63 0
      final-modul-react/src/container/Login/Login.jsx
  39. 2 0
      final-modul-react/src/container/Login/index.js
  40. 25 0
      final-modul-react/src/container/Login/style.css
  41. 58 0
      final-modul-react/src/container/Registration/Registration.jsx
  42. 2 0
      final-modul-react/src/container/Registration/index.js
  43. 0 0
      final-modul-react/src/container/Registration/style.css
  44. 16 0
      final-modul-react/src/container/Search/Search.jsx
  45. 2 0
      final-modul-react/src/container/Search/index.js
  46. 7 0
      final-modul-react/src/container/Search/style.css
  47. 1 0
      final-modul-react/src/img/exit.svg
  48. BIN
      final-modul-react/src/img/instagram.png
  49. BIN
      final-modul-react/src/img/road.jpg
  50. 25 0
      final-modul-react/src/index.css
  51. 14 0
      final-modul-react/src/index.js
  52. 33 0
      final-modul-react/src/store/auth/reducer.js
  53. 13 0
      final-modul-react/src/store/auth/thunks.js
  54. 21 0
      final-modul-react/src/store/index.js
  55. 22 0
      final-modul-react/src/store/regist/reducer.js
  56. 13 0
      final-modul-react/src/store/regist/thunks.js
  57. 16 0
      final-modul-react/src/store/thunks.js
  58. 20 0
      final-modul-react/src/store/ui/reducer.js

File diff suppressed because it is too large
+ 1 - 0
final-modul-react/.eslintcache


+ 23 - 0
final-modul-react/.gitignore

@@ -0,0 +1,23 @@
+# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
+
+# dependencies
+/node_modules
+/.pnp
+.pnp.js
+
+# testing
+/coverage
+
+# production
+/build
+
+# misc
+.DS_Store
+.env.local
+.env.development.local
+.env.test.local
+.env.production.local
+
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*

+ 70 - 0
final-modul-react/README.md

@@ -0,0 +1,70 @@
+# Getting Started with Create React App
+
+This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
+
+## Available Scripts
+
+In the project directory, you can run:
+
+### `npm start`
+
+Runs the app in the development mode.\
+Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
+
+The page will reload if you make edits.\
+You will also see any lint errors in the console.
+
+### `npm test`
+
+Launches the test runner in the interactive watch mode.\
+See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
+
+### `npm run build`
+
+Builds the app for production to the `build` folder.\
+It correctly bundles React in production mode and optimizes the build for the best performance.
+
+The build is minified and the filenames include the hashes.\
+Your app is ready to be deployed!
+
+See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
+
+### `npm run eject`
+
+**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
+
+If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
+
+Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
+
+You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
+
+## Learn More
+
+You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
+
+To learn React, check out the [React documentation](https://reactjs.org/).
+
+### Code Splitting
+
+This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
+
+### Analyzing the Bundle Size
+
+This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
+
+### Making a Progressive Web App
+
+This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
+
+### Advanced Configuration
+
+This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
+
+### Deployment
+
+This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
+
+### `npm run build` fails to minify
+
+This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)

File diff suppressed because it is too large
+ 16540 - 0
final-modul-react/package-lock.json


+ 44 - 0
final-modul-react/package.json

@@ -0,0 +1,44 @@
+{
+  "name": "final-modul-react",
+  "version": "0.1.0",
+  "private": true,
+  "dependencies": {
+    "@testing-library/jest-dom": "^5.11.9",
+    "@testing-library/react": "^11.2.3",
+    "@testing-library/user-event": "^12.6.0",
+    "axios": "^0.21.1",
+    "react": "^17.0.1",
+    "react-dom": "^17.0.1",
+    "react-redux": "7.2.2",
+    "react-router-dom": "^5.2.0",
+    "react-scripts": "4.0.1",
+    "redux": "4.0.5",
+    "redux-devtools-extension": "^2.13.8",
+    "redux-thunk": "^2.3.0",
+    "web-vitals": "^0.2.4"
+  },
+  "scripts": {
+    "start": "react-scripts start",
+    "build": "react-scripts build",
+    "test": "react-scripts test",
+    "eject": "react-scripts eject"
+  },
+  "eslintConfig": {
+    "extends": [
+      "react-app",
+      "react-app/jest"
+    ]
+  },
+  "browserslist": {
+    "production": [
+      ">0.2%",
+      "not dead",
+      "not op_mini all"
+    ],
+    "development": [
+      "last 1 chrome version",
+      "last 1 firefox version",
+      "last 1 safari version"
+    ]
+  }
+}

+ 29 - 0
final-modul-react/public/index.html

@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8" />
+    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
+    <meta name="viewport" content="width=device-width, initial-scale=1" />
+    <meta name="theme-color" content="#000000" />
+    <meta
+      name="description"
+      content="Web site created using create-react-app"
+    />
+    
+    <title>React App</title>
+  </head>
+  <body>
+    <noscript>You need to enable JavaScript to run this app.</noscript>
+    <div id="root"></div>
+    <!--
+      This HTML file is a template.
+      If you open it directly in the browser, you will see an empty page.
+
+      You can add webfonts, meta tags, or analytics to this file.
+      The build step will place the bundled scripts into the <body> tag.
+
+      To begin the development, run `npm start` or `yarn start`.
+      To create a production bundle, use `npm run build` or `yarn build`.
+    -->
+  </body>
+</html>

+ 3 - 0
final-modul-react/src/App.css

@@ -0,0 +1,3 @@
+.app {
+  flex: 1 0 auto;
+}

+ 31 - 0
final-modul-react/src/App.js

@@ -0,0 +1,31 @@
+import './App.css';
+import store from './store';
+import {Provider} from 'react-redux';
+import HomePage from './container/HomePage';
+import {BrowserRouter as Router, Redirect, Route, Switch} from 'react-router-dom';
+import Auth from './container/Auth/Auth';
+import Login from './container/Login';
+import Registration from './container/Registration';
+
+
+const App = () => {
+
+
+  return (
+    <Provider store={store}>
+    <Router>
+   
+
+    
+            <Route exact path='/' component={HomePage}/>
+            <Route exact path='/auth' component={Auth}/> 
+            <Route exact path='/auth/login' component={Login}/> 
+            <Route exact path='/auth/registration' component={Registration}/> 
+  
+   
+    </Router>
+    </Provider>
+  );
+}
+
+export default App;

+ 18 - 0
final-modul-react/src/api/auth.js

@@ -0,0 +1,18 @@
+import api from './common';
+
+class Auth {
+    constructor(){
+        this.api = api.api;
+    }
+
+    registration(body){
+        
+        return this.api.post('/auth/registration', body)
+    }
+
+    login(body){
+        return this.api.post('/auth/login', body);
+    }
+}
+
+export default new Auth();

+ 38 - 0
final-modul-react/src/api/common.js

@@ -0,0 +1,38 @@
+import axios from 'axios';
+import store from '../store';
+
+class Fetch {
+    constructor(){
+        this.api = axios.create({
+            baseURL: 'https://hipstagram-api.herokuapp.com'
+        })
+        this._initInterceptors();
+    }
+
+    _initInterceptors(){
+        this.api.interceptors.request.use(function (config) {
+            const {token} = store.getState().auth;
+            config.headers = {
+                ...config.headers,
+                'Content-Type': 'application/json',
+                'Authorization': token,
+            }
+            return config;
+          }, function (error) {
+            // Do something with request error
+            return Promise.reject(error);
+          });
+
+        this.api.interceptors.response.use(function (response) {
+            return response.data;
+            }, function (error) {
+                if (error.response.status === 401) {
+                    store.dispatch({type: 'LOGOUT'})
+                }
+            return Promise.reject(error);
+        });
+        
+    }
+}
+
+export default new Fetch();

+ 6 - 0
final-modul-react/src/api/index.js

@@ -0,0 +1,6 @@
+import authFetch from './auth';
+import usersFetch from './users';
+
+export const authApi = authFetch;
+export const usersApi = usersFetch;
+

+ 22 - 0
final-modul-react/src/api/users.js

@@ -0,0 +1,22 @@
+import api from './common';
+
+class Users {
+    constructor(){
+        this.api = api.api;
+    }
+
+    getCurrentUser(){
+        
+        return this.api.get('/users/current');
+    }
+
+    getAllUsers(){
+        return this.api.get('/users');
+    }
+
+    deleteUser(id) {
+        return this.api.delete('/users/'+id)
+    }
+}
+
+export default new Users();

+ 19 - 0
final-modul-react/src/components/Button/Button.jsx

@@ -0,0 +1,19 @@
+import React from 'react';
+import './style.css'
+
+const Button = ({
+   btnId,
+    onClick,
+    children,
+    className
+
+})=> {
+    return <button
+    name={btnId} className={className}
+               onClick={(e) => onClick && onClick(e)}>
+                   {children}
+            </button>
+   
+}
+
+export default Button;

+ 2 - 0
final-modul-react/src/components/Button/index.js

@@ -0,0 +1,2 @@
+import Button from './Button'
+export default Button

+ 0 - 0
final-modul-react/src/components/Button/style.css


+ 24 - 0
final-modul-react/src/components/Input/Input.jsx

@@ -0,0 +1,24 @@
+
+import React from "react";
+const Input =({
+  value,
+  name,
+  placeholder,
+  onChange,
+id,
+type
+
+}) => { 
+    
+      return (
+       
+     
+        <input value={value} name={name} id={id}  placeholder={ placeholder} type={type}
+                onChange={(e) => onChange && onChange(e)}
+         />
+    
+      );
+    }
+  
+ 
+export default Input

+ 2 - 0
final-modul-react/src/components/Input/index.js

@@ -0,0 +1,2 @@
+import Input from './Input'
+export default Input;

+ 14 - 0
final-modul-react/src/components/Label/Label.jsx

@@ -0,0 +1,14 @@
+import './style.css';
+import React from "react";
+const Label =({
+  htmlFor, children
+  
+}) => { 
+    
+      return (
+      <label  htmlFor={htmlFor}>{children}</label>
+      );
+    }
+  
+ 
+export default Label

+ 2 - 0
final-modul-react/src/components/Label/index.js

@@ -0,0 +1,2 @@
+import Label from './Label'
+export default Label;

+ 0 - 0
final-modul-react/src/components/Label/style.css


+ 2 - 0
final-modul-react/src/components/withAuthWrapper/index.js

@@ -0,0 +1,2 @@
+import withAuthWrapper from  './withAuthWrapper.jsx';
+export default withAuthWrapper;

+ 30 - 0
final-modul-react/src/components/withAuthWrapper/style.css

@@ -0,0 +1,30 @@
+.auth {
+    height: 100%;
+    display: flex;
+    flex-direction: column;
+    align-items: center;
+    background-image: url(../../img/road.jpg);
+    background-repeat: no-repeat;
+    background-size: cover;
+    background-position: center;
+  }
+  .hipsta-title {
+    display: flex;
+    justify-content: center;
+    align-items: center;
+    margin: 30px auto;
+  }
+  .hipsta-icon {
+    width: 100px;
+    height: 100px;
+    background-image: url('../../img/instagram.png');
+    background-position: center;
+    background-repeat: no-repeat;
+    background-size: cover;
+    margin-right: 30px;
+  }
+
+  h1 {
+    font-size: 60px;
+    color: rgb(0, 0, 94);
+  }

+ 31 - 0
final-modul-react/src/components/withAuthWrapper/withAuthWrapper.jsx

@@ -0,0 +1,31 @@
+import './style.css';
+import React, { Component } from 'react';
+
+
+
+function withAuthWrapper (ChildComponent)  {
+
+    
+    return class Container extends Component{
+        render(){
+            return (
+        
+       
+           
+                <div className="auth">
+                     <div className="hipsta-title">
+                       <div className="hipsta-icon"></div>
+                        <h1>HIPSTAGRAM</h1>
+                    
+                     </div>
+                    <ChildComponent/>
+                 </div>
+     
+         );
+        }
+        
+        
+    } 
+}
+
+export default withAuthWrapper;

+ 5 - 0
final-modul-react/src/constants/messages.js

@@ -0,0 +1,5 @@
+export const alertConstants = {
+    SUCCESS: 'ALERT_SUCCESS',
+    ERROR: 'ALERT_ERROR',
+    CLEAR: 'ALERT_CLEAR'
+};

+ 19 - 0
final-modul-react/src/constants/users.js

@@ -0,0 +1,19 @@
+export const userConstants = {
+    REGISTER_REQUEST: 'REGISTER_REQUEST',
+    REGISTER_SUCCESS: 'REGISTER_SUCCESS',
+    REGISTER_FAILURE: 'REGISTER_FAILURE',
+
+    LOGIN_REQUEST: 'LOGIN_REQUEST',
+    LOGIN_SUCCESS: 'LOGIN_SUCCESS',
+    LOGIN_FAILURE: 'LOGIN_FAILURE',
+
+    LOGOUT: 'LOGOUT',
+
+    GETALL_REQUEST: 'USERS_GETALL_REQUEST',
+    GETALL_SUCCESS: 'USERS_GETALL_SUCCESS',
+    GETALL_FAILURE: 'USERS_GETALL_FAILURE',
+
+    DELETE_REQUEST: 'USERS_DELETE_REQUEST',
+    DELETE_SUCCESS: 'USERS_DELETE_SUCCESS',
+    DELETE_FAILURE: 'USERS_DELETE_FAILURE'    
+};

+ 15 - 0
final-modul-react/src/container/Auth/Auth.jsx

@@ -0,0 +1,15 @@
+import './style.css';
+import React from 'react';
+import { useSelector } from 'react-redux';
+import { Redirect} from 'react-router-dom'
+
+
+const Auth = () => {
+ const  isRegist = useSelector(store => store.reg.isRegist)
+    debugger;
+    return (
+        isRegist ? <Redirect to="/auth/login" /> : <Redirect to="/auth/registration" />
+    )
+}
+
+export default Auth;

+ 2 - 0
final-modul-react/src/container/Auth/index.js

@@ -0,0 +1,2 @@
+import Auth from  './Auth.jsx';
+export default Auth;

+ 30 - 0
final-modul-react/src/container/Auth/style.css

@@ -0,0 +1,30 @@
+.auth {
+    height: 100%;
+    display: flex;
+    flex-direction: column;
+    align-items: center;
+    background-image: url(../../img/road.jpg);
+    background-repeat: no-repeat;
+    background-size: cover;
+    background-position: center;
+  }
+  .hipsta-title {
+    display: flex;
+    justify-content: center;
+    align-items: center;
+    margin: 30px auto;
+  }
+  .hipsta-icon {
+    width: 100px;
+    height: 100px;
+    background-image: url('../../img/instagram.png');
+    background-position: center;
+    background-repeat: no-repeat;
+    background-size: cover;
+    margin-right: 30px;
+  }
+
+  h1 {
+    font-size: 60px;
+    color: rgb(0, 0, 94);
+  }

+ 23 - 0
final-modul-react/src/container/Dashboard/Dashboard.jsx

@@ -0,0 +1,23 @@
+import './style.css';
+import React from 'react';
+import Header from '../Header';
+
+
+
+
+const Dashboard = ({children}) => {
+    
+    
+    return (
+        <>
+        <div>
+            <Header/>
+            {children}
+            <main></main>
+        </div>
+        
+        </>
+    );
+}
+
+export default Dashboard;

+ 2 - 0
final-modul-react/src/container/Dashboard/index.js

@@ -0,0 +1,2 @@
+import Dashboard from  './Dashboard.jsx';
+export default Dashboard;

+ 0 - 0
final-modul-react/src/container/Dashboard/style.css


+ 32 - 0
final-modul-react/src/container/Header/Header.jsx

@@ -0,0 +1,32 @@
+import './style.css';
+import React from 'react';
+import Search from '../Search';
+import {connect} from 'react-redux';
+import {Link} from 'react-router-dom';
+
+const mapDispatchToProps = dispatch => {
+    return {
+    
+        logOut: () => dispatch({type: 'LOGOUT'}),
+      
+    }
+}
+
+
+
+const Header = ({logOut}) => {
+    const handleLogOut = () => {
+        logOut()
+    }
+    
+    return (
+        <>
+         <header>
+             <Search/>
+             <Link to='/auth/login' className='log-out-btn' onClick={handleLogOut}/>
+         </header>
+        </>
+    );
+}
+
+export default connect(null, mapDispatchToProps) (Header);

+ 2 - 0
final-modul-react/src/container/Header/index.js

@@ -0,0 +1,2 @@
+import Header from  './Header.jsx';
+export default Header;

+ 18 - 0
final-modul-react/src/container/Header/style.css

@@ -0,0 +1,18 @@
+header {
+    display: flex;
+    justify-content: space-between;
+    align-items: center;
+    background-color: rgb(0, 153, 255);
+    padding: 20px;
+}
+
+.log-out-btn {
+    border: none;
+    background-color:  rgb(0, 153, 255);;
+    background-image: url('../../img/exit.svg');
+    margin: 0;
+    padding: 0;
+    width: 60px;
+    height: 60px;
+}
+

+ 17 - 0
final-modul-react/src/container/HomePage/HomePage.jsx

@@ -0,0 +1,17 @@
+import './style.css';
+import React from 'react';
+import { useSelector } from 'react-redux';
+import Dashboard from '../Dashboard';
+import { Redirect} from 'react-router-dom'
+
+      
+
+const HomePage = () => {
+    const isAuth = useSelector(store => store.auth.isAuth);
+debugger;
+    return (
+        isAuth ?  <Dashboard /> : <Redirect to="/auth" />
+    );
+}
+
+export default HomePage ;

+ 2 - 0
final-modul-react/src/container/HomePage/index.js

@@ -0,0 +1,2 @@
+import HomePage from  './HomePage.jsx';
+export default HomePage;

+ 0 - 0
final-modul-react/src/container/HomePage/style.css


+ 63 - 0
final-modul-react/src/container/Login/Login.jsx

@@ -0,0 +1,63 @@
+import './style.css';
+import React from 'react';
+import {connect} from 'react-redux';
+import {authApi, usersApi} from '../../api'; 
+import {Link, withRouter } from 'react-router-dom';
+import withAuthWrapper from '../../components/withAuthWrapper';
+
+
+const mapDispatchToProps = dispatch => {
+    return {
+        loginDispatch: token => dispatch({type: 'LOGIN', payload: token}),
+        initDispatch: currentUser => dispatch({type: 'INIT', payload: currentUser}),
+        startLoader: () => dispatch({type: 'LOADER_START'}),
+        stopLoader: () => dispatch({type: 'LOADER_STOP'}),
+    }
+}
+
+const Login = ({loginDispatch, initDispatch, startLoader, stopLoader, history}) => {
+    const handleSubmit = async (e) => {
+        startLoader()
+        e.preventDefault();
+        const {login, password} = e.target.elements;
+        const body = {
+            login: login.value,
+            password: password.value,
+        }
+
+        try {
+            const {access_token} = await authApi.login(body);
+            loginDispatch(access_token);
+            const currentUser = await usersApi.getCurrentUser();
+            initDispatch(currentUser)
+
+        } catch(err) {
+          
+            console.log(err)
+            return (
+            
+                <div> You are {err}. Go to <Link to='auth/registration'>Sign Up</Link></div>
+            )
+
+        } finally  {
+            stopLoader()
+            console.log('*******************')
+            history.push('/')
+
+        }
+
+    }
+    
+    return (
+        
+        <form onSubmit={handleSubmit}>
+            <h3>Sign In</h3>
+            <input type="text" placeholder="Enter login" name="login"/>
+            <input type="text" placeholder="Enter password" name="password"/>
+            <button type="submit">Sign in</button>
+            <p>If You don't have an account you can <Link to='/auth/registration'>Sign Up</Link> </p>
+        </form>
+    );
+}
+
+export default withAuthWrapper(connect(null, mapDispatchToProps)(withRouter(Login)));

+ 2 - 0
final-modul-react/src/container/Login/index.js

@@ -0,0 +1,2 @@
+import Login from  './Login.jsx';
+export default Login;

+ 25 - 0
final-modul-react/src/container/Login/style.css

@@ -0,0 +1,25 @@
+form {
+    display: flex;
+    flex-direction: column;
+    padding: 30px;
+    align-items: center;
+    justify-content: center;
+    background-color: rgb(213, 223, 231);
+    opacity: 0.8;
+    width: 70%;
+    height: 70%;
+    margin: auto;
+}
+
+input {
+    margin-top: 30px;
+    padding: 20px;
+    width: 70%;
+    border: 2px solid rgb(70, 68, 68);
+}
+
+button {
+    margin-top: 30px;
+    padding: 10px;
+    width: 100px;
+}

+ 58 - 0
final-modul-react/src/container/Registration/Registration.jsx

@@ -0,0 +1,58 @@
+import './style.css';
+import React from 'react';
+import { connect } from 'react-redux';
+import {authApi} from '../../api'; 
+import {Link, withRouter} from 'react-router-dom';
+import withAuthWrapper from '../../components/withAuthWrapper';
+
+
+const mapDispatchToProps = dispatch => {
+    return {
+    
+        regist: id => dispatch({type: 'REGIST', payload: id}),
+      
+    }
+}
+
+const mapStateToProps = ({reg}) => {
+    return {reg}
+  }
+const Registration = ({ regist, history}) => {
+    const handleReg =(e)=>{
+        e.preventDefault()
+    const {login, email, password} = e.target.elements;
+    const body = {
+        login: login.value,
+        email: email.value,
+        password: password.value
+    }
+   debugger;
+    authApi.registration(body)
+    .then(res=> {
+        console.log(res.id);
+        debugger;
+        regist(res.id)
+        history.push('/auth/login')
+    })
+       
+    .catch(e=> console.log(e))
+
+    
+    }
+    
+    
+    return (
+    <form onSubmit={handleReg}>
+         <h3>Sign Up</h3>
+        <input name="login" type="text" placeholder="login"/>
+        <input  name="email" type="text" placeholder="email"/>
+        <input name="password" type="text" placeholder="password"/>
+        
+        <button type="submit">Sign up</button>
+
+        <p>If You have an account you can <Link to='/auth/login'>Sign In</Link> </p>
+    </form>
+    );
+}
+const withRegistration = withAuthWrapper(Registration)
+export default  withAuthWrapper(connect(mapStateToProps, mapDispatchToProps)(withRouter(Registration)));

+ 2 - 0
final-modul-react/src/container/Registration/index.js

@@ -0,0 +1,2 @@
+import Registration from  './Registration.jsx';
+export default Registration;

+ 0 - 0
final-modul-react/src/container/Registration/style.css


+ 16 - 0
final-modul-react/src/container/Search/Search.jsx

@@ -0,0 +1,16 @@
+import './style.css';
+import Input from '../../components/Input'
+
+
+
+
+
+const Search =({valueInput}) => {
+
+  return (
+    <Input placeholder="Search for users"  value={valueInput}/>
+
+  )
+}
+
+export default Search

+ 2 - 0
final-modul-react/src/container/Search/index.js

@@ -0,0 +1,2 @@
+import Search from './Search'
+export default Search;

+ 7 - 0
final-modul-react/src/container/Search/style.css

@@ -0,0 +1,7 @@
+input {
+    width: 300px;
+    padding: 5px;
+    max-height: 70px;
+    margin: 0;
+    border: 1px solid  gray;
+}

File diff suppressed because it is too large
+ 1 - 0
final-modul-react/src/img/exit.svg


BIN
final-modul-react/src/img/instagram.png


BIN
final-modul-react/src/img/road.jpg


+ 25 - 0
final-modul-react/src/index.css

@@ -0,0 +1,25 @@
+html{
+  height: 100%;
+}
+
+body {
+  max-width: 1300px;
+  margin: 0 auto;
+  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
+    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
+    sans-serif;
+  -webkit-font-smoothing: antialiased;
+  -moz-osx-font-smoothing: grayscale;
+  display: flex;
+  flex-direction: column;
+  height: 100%;
+ 
+}
+
+code {
+  font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
+    monospace;
+}
+#root {
+  height: 100%;
+}

+ 14 - 0
final-modul-react/src/index.js

@@ -0,0 +1,14 @@
+import React from 'react';
+import ReactDOM from 'react-dom';
+import './index.css';
+import App from './App';
+
+
+ReactDOM.render(
+  <React.StrictMode>
+    <App />
+  </React.StrictMode>,
+  document.getElementById('root')
+);
+
+

+ 33 - 0
final-modul-react/src/store/auth/reducer.js

@@ -0,0 +1,33 @@
+const initialState = {
+    isAuth: localStorage.getItem('token')? true : false,
+    token: localStorage.getItem('token'),
+    currentUser: null
+}
+
+export const authReducer = (state=initialState, action) => {
+    switch (action.type) {
+        case 'INIT':
+            return {
+                ...state,
+                isAuth: true,
+                currentUser: action.payload
+            }    
+        case 'LOGIN':
+            localStorage.setItem('token', action.payload)
+            return {
+                ...state,
+                isAuth: true,
+                token: action.payload
+            }
+        case 'LOGOUT':
+            localStorage.removeItem('token');
+            return {
+                ...state,
+                isAuth: false,
+                token: null,
+                currentUser: null
+            }        
+        default:
+            return state    
+    }
+}

+ 13 - 0
final-modul-react/src/store/auth/thunks.js

@@ -0,0 +1,13 @@
+import {usersApi} from '../../api'
+
+
+export const getCurrentUserThunk = () => {
+    return async (dispatch, getState) => {
+        try {
+            const currentUser = await usersApi.getCurrentUser();
+            dispatch({type: 'INIT', payload: currentUser})
+        } catch(e) {
+            console.log(e)
+        }
+    }
+}

+ 21 - 0
final-modul-react/src/store/index.js

@@ -0,0 +1,21 @@
+import {createStore, combineReducers, applyMiddleware} from 'redux';
+import { composeWithDevTools } from 'redux-devtools-extension';
+import thunk from 'redux-thunk';
+import { regReducer } from "./regist/reducer";
+import {authReducer} from './auth/reducer';
+import {uiReducer} from './ui/reducer';
+import { initThunk } from './thunks';
+
+const rootReducer = combineReducers({
+    auth: authReducer,
+    ui: uiReducer,
+    reg: regReducer,
+})
+
+const middlewares = applyMiddleware(thunk)
+
+const store = createStore(rootReducer, composeWithDevTools(middlewares))
+
+store.dispatch(initThunk());
+
+export default store;

+ 22 - 0
final-modul-react/src/store/regist/reducer.js

@@ -0,0 +1,22 @@
+
+
+const initialState = {
+    isRegist: localStorage.getItem('id') ? true : false,
+    id: localStorage.getItem('id') || null,
+    
+}
+
+export const regReducer = (state=initialState, action) => {
+    switch (action.type) {
+        case 'REGIST':
+            localStorage.setItem('id', action.payload)
+            return {
+                ...state,
+                isRegist: true,
+                id: action.payload
+            }    
+        
+        default:
+            return state    
+    }
+}

+ 13 - 0
final-modul-react/src/store/regist/thunks.js

@@ -0,0 +1,13 @@
+import {usersApi} from '../../api'
+
+
+export const getCurrentUserThunk = () => {
+    return async (dispatch, getState) => {
+        try {
+            const currentUser = await usersApi.getCurrentUser();
+            dispatch({type: 'REGIST', payload: currentUser.id})
+        } catch(e) {
+            console.log(e)
+        }
+    }
+}

+ 16 - 0
final-modul-react/src/store/thunks.js

@@ -0,0 +1,16 @@
+import { getCurrentUserThunk } from "./auth/thunks";
+//import { getAllUsersThunk } from "./users/thunks";
+
+export const initThunk = () => {
+    return async dispatch => {
+        try {
+            dispatch({type: 'LOADER_START'});
+            await dispatch(getCurrentUserThunk())
+            //await dispatch(getAllUsersThunk())
+        } catch(e) {
+            console.log(e)
+        } finally {
+            dispatch({type: 'LOADER_STOP'})
+        }
+    }
+}

+ 20 - 0
final-modul-react/src/store/ui/reducer.js

@@ -0,0 +1,20 @@
+const initialState = {
+    isLoader: false
+}
+
+export const uiReducer = (state=initialState, action) => {
+    switch (action.type) {
+        case 'LOADER_START':
+            return {
+                ...state,
+                isLoader: true,
+            } 
+        case 'LOADER_STOP':
+            return {
+                ...state,
+                isLoader: false,
+            }                  
+        default:
+            return state    
+    }
+}