|
@@ -5,7 +5,7 @@ import {createStore, combineReducers, applyMiddleware} from 'redux';
|
|
import thunk from 'redux-thunk';
|
|
import thunk from 'redux-thunk';
|
|
import jwt_decode from "jwt-decode"
|
|
import jwt_decode from "jwt-decode"
|
|
import { bindActionCreators } from 'redux';
|
|
import { bindActionCreators } from 'redux';
|
|
-import {actionLogin, authReducer, actionAuthLogout} from "../reducers/";
|
|
|
|
|
|
+import {actionLogin, authReducer, actionAuthLogout, actionReg} from "../reducers/";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -15,21 +15,23 @@ const ButtonLogout = ({onLogout, isLoggedIn}) =>
|
|
|
|
|
|
const CButtonLogout = connect(s => ({isLoggedIn: s.auth.payload}),{onLogout: actionAuthLogout})(ButtonLogout)
|
|
const CButtonLogout = connect(s => ({isLoggedIn: s.auth.payload}),{onLogout: actionAuthLogout})(ButtonLogout)
|
|
|
|
|
|
-const DashboardLink = ({login}) =>{
|
|
|
|
-console.log(login)
|
|
|
|
-return(
|
|
|
|
-<div className = "DashboardLink">{login ? <Link to='/dashboard'>{login}</Link> : <Link to='/login'>Anon</Link>}</div>
|
|
|
|
-)
|
|
|
|
-}
|
|
|
|
-const CDashboardLink = connect(s => ({login: s.auth.payload && s.auth.payload.sub.login, }))(DashboardLink)
|
|
|
|
|
|
+// const DashboardLink = ({login}) =>{
|
|
|
|
+// console.log(login)
|
|
|
|
+// return(
|
|
|
|
+// <div className = "DashboardLink">{login ? <Link to='/dashboard'>{login}</Link> : <Link to='/login'>Anon</Link>}</div>
|
|
|
|
+// )
|
|
|
|
+// }
|
|
|
|
+// const CDashboardLink = connect(s => ({login: s.auth.payload && s.auth.payload.sub.login, }))(DashboardLink)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
-const PasswordConfirm = ({login, isLoggedIn, onLogin = null }) => {
|
|
|
|
|
|
+const PasswordConfirm = ({state, login, isLoggedIn, onLogin = null }) => {
|
|
const [pass1, setPass1] = useState("");
|
|
const [pass1, setPass1] = useState("");
|
|
const [pass2, setPass2] = useState("");
|
|
const [pass2, setPass2] = useState("");
|
|
const history = useHistory();
|
|
const history = useHistory();
|
|
useEffect(() => login ? history.push(`/profile/` + login) : history.push(`/login`),[login])
|
|
useEffect(() => login ? history.push(`/profile/` + login) : history.push(`/login`),[login])
|
|
-
|
|
|
|
|
|
+ console.log(state)
|
|
|
|
|
|
return (
|
|
return (
|
|
<>
|
|
<>
|
|
@@ -60,19 +62,114 @@ const PasswordConfirm = ({login, isLoggedIn, onLogin = null }) => {
|
|
);
|
|
);
|
|
};
|
|
};
|
|
|
|
|
|
-const CFormLogin = connect((s) => ({isLoggedIn: s.auth.payload, login: s.auth.payload && s.auth.payload.sub.login}), {
|
|
|
|
- onLogin:actionLogin})(PasswordConfirm);
|
|
|
|
|
|
|
|
|
|
+const FormReg = ({onReg, onLogin, login, state, isReg}) => {
|
|
|
|
+ const [pass1, setPass1] = useState("");
|
|
|
|
+ const [pass2, setPass2] = useState("");
|
|
|
|
+ const history = useHistory();
|
|
|
|
+ useEffect(() => login ? history.push(`/profile/` + login) : history.push(`/login`),[login])
|
|
|
|
+ console.log(isReg)
|
|
|
|
|
|
|
|
+ return (
|
|
|
|
+ <>
|
|
|
|
+ <div>
|
|
|
|
+ <input
|
|
|
|
+ type="text"
|
|
|
|
+ placeholder = "login"
|
|
|
|
+ onChange={(e) => {
|
|
|
|
+ setPass1(e.target.value);
|
|
|
|
+ }}
|
|
|
|
+ onKeyDown = {(e) => {
|
|
|
|
+ if (e.keyCode == 13 ) {
|
|
|
|
+ onReg(pass1, pass2)
|
|
|
|
+ if(!isReg) {
|
|
|
|
+ onLogin(pass1, pass2)
|
|
|
|
+ } else {
|
|
|
|
+ history.push('/loginError')
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }}
|
|
|
|
+ />
|
|
|
|
+ <input
|
|
|
|
+ type="password"
|
|
|
|
+ placeholder = "password"
|
|
|
|
+ onChange={(e) => {
|
|
|
|
+ setPass2(e.target.value);
|
|
|
|
+ }}
|
|
|
|
+ onKeyDown = {(e) => {
|
|
|
|
+ if (e.keyCode == 13 ) {
|
|
|
|
+ onReg(pass1, pass2)
|
|
|
|
+ debugger
|
|
|
|
+ if(!isReg) {
|
|
|
|
+ onLogin(pass1, pass2)
|
|
|
|
+ } else {
|
|
|
|
+ history.push('/loginError')
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }}
|
|
|
|
+ />
|
|
|
|
+ </div>
|
|
|
|
+ <div>
|
|
|
|
+ <button disabled = {!pass2 || !pass1} onClick={() => {
|
|
|
|
+ onReg(pass1, pass2)
|
|
|
|
+ debugger
|
|
|
|
+ if(!isReg) {
|
|
|
|
+ onLogin(pass1, pass2)
|
|
|
|
+ } else {
|
|
|
|
+ history.push('/loginError')
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }>Запишіть</button>
|
|
|
|
+
|
|
|
|
+ </div>
|
|
|
|
+
|
|
|
|
+ </>
|
|
|
|
+
|
|
|
|
+ )
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+const CFormReg = connect((state) => ({
|
|
|
|
+ state: state,
|
|
|
|
+ login: state.auth.payload && state.auth.payload.sub.login,
|
|
|
|
+ isReg: state.promiseRed && state.promiseRed.registration &&
|
|
|
|
+ state.promiseRed.registration.payload &&
|
|
|
|
+ state.promiseRed.registration.payload.errors
|
|
|
|
+
|
|
|
|
+ }), {
|
|
|
|
+ onReg:actionReg,
|
|
|
|
+ onLogin:actionLogin})(FormReg);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+const CFormLogin = connect((s) => ({state: s, isLoggedIn: s.auth.payload, login: s.auth.payload && s.auth.payload.sub.login}), {
|
|
|
|
+ onLogin:actionLogin})(PasswordConfirm);
|
|
|
|
+
|
|
|
|
+// const LoginError = () => {
|
|
|
|
+// const history = useHistory();
|
|
|
|
+// return(
|
|
|
|
+// <>
|
|
|
|
+// <div>Упс, щось пішло не так. Можливо це ім'я вже зайнято. Спробуйте ще.</div>
|
|
|
|
+// <button onClick = {() => history.push("/login")}>Перейти на сторінку регістрації</button>
|
|
|
|
+// </>
|
|
|
|
+// )}
|
|
|
|
|
|
const LoginForm = ({}) => {
|
|
const LoginForm = ({}) => {
|
|
|
|
|
|
return(
|
|
return(
|
|
- <>
|
|
|
|
- <div className = "loginForm">
|
|
|
|
- {/* <CDashboardLink/> */}
|
|
|
|
- <CFormLogin />
|
|
|
|
|
|
+ <>
|
|
|
|
+ <div className = "loginWrapper">
|
|
|
|
+ <h2>Будь ласка, увійдіть в свій аккаунд</h2>
|
|
|
|
+ <div className = "loginForm">
|
|
|
|
+
|
|
|
|
+ {/* <CDashboardLink/> */}
|
|
|
|
+ <CFormLogin />
|
|
|
|
|
|
|
|
+ </div>
|
|
|
|
+ <h2>Не маєте аккаунта? То не біда, зареєструйтесь</h2>
|
|
|
|
+ <div className = "loginForm">
|
|
|
|
+ <CFormReg/>
|
|
|
|
+ </div>
|
|
</div>
|
|
</div>
|
|
</>
|
|
</>
|
|
)
|
|
)
|