|
@@ -1,4 +1,4 @@
|
|
|
-import React, { useState } from "react";
|
|
|
+import React, { useState, Component } from "react";
|
|
|
import { Link } from "react-router-dom";
|
|
|
import { connect } from "react-redux";
|
|
|
import {
|
|
@@ -12,6 +12,7 @@ import jwtDecode from "jwt-decode";
|
|
|
import { actionLogin } from "./actionLogin/actionLogin";
|
|
|
import history from "../history";
|
|
|
import { actionChatGroup } from "../myProfile/chatGroups/actionChatGroup/actionChatGroup";
|
|
|
+import MyProfile from "../myProfile/myProfile";
|
|
|
import "./signIn.css";
|
|
|
|
|
|
const loginEye = () => {
|
|
@@ -33,7 +34,7 @@ const loginEye = () => {
|
|
|
const LoginForm = ({ onLogin, backError, state }) => {
|
|
|
const [login, setLogin] = useState("");
|
|
|
const [password, setPassword] = useState("");
|
|
|
-
|
|
|
+
|
|
|
const way = (obj, resolverName, a) => {
|
|
|
const stateObj = state[obj];
|
|
|
for (var keys in stateObj) {
|
|
@@ -41,8 +42,10 @@ const LoginForm = ({ onLogin, backError, state }) => {
|
|
|
if (keyData === "data") {
|
|
|
const allObj = stateObj[keys][keyData][resolverName];
|
|
|
if (allObj) {
|
|
|
- const x = jwtDecode(allObj);
|
|
|
- // return x.sub.email;
|
|
|
+ var x = jwtDecode(allObj);
|
|
|
+ localStorage.setItem("id", x.sub.id);
|
|
|
+ localStorage.setItem("email", x.sub.email);
|
|
|
+ localStorage.setItem("login", x.sub.login);
|
|
|
} else {
|
|
|
return (
|
|
|
<div className="error">
|
|
@@ -54,7 +57,7 @@ const LoginForm = ({ onLogin, backError, state }) => {
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
-
|
|
|
+// console.log(localStorage.getItem("id"));
|
|
|
const buttonEnter = (e) => {
|
|
|
if (e.key === "Enter") onLogin(login, password);
|
|
|
};
|
|
@@ -96,7 +99,7 @@ const LoginForm = ({ onLogin, backError, state }) => {
|
|
|
<EyeOutlined />
|
|
|
</div>
|
|
|
</div>
|
|
|
-
|
|
|
+
|
|
|
{way("login", "getLogin")}
|
|
|
|
|
|
<button
|
|
@@ -116,13 +119,126 @@ const LoginForm = ({ onLogin, backError, state }) => {
|
|
|
);
|
|
|
};
|
|
|
|
|
|
+// class LoginForm extends Component {
|
|
|
+// constructor(props) {
|
|
|
+// super(props);
|
|
|
+// this.state = { login: "", password: "" };
|
|
|
+// // console.log(this.props);
|
|
|
+// }
|
|
|
+
|
|
|
+// way (obj, resolverName, a) {
|
|
|
+// const stateObj = this.props.state[obj];
|
|
|
+// for (var keys in stateObj) {
|
|
|
+// for (var keyData in stateObj[keys]) {
|
|
|
+// if (keyData === "data") {
|
|
|
+// const allObj = stateObj[keys][keyData][resolverName];
|
|
|
+// if (allObj) {
|
|
|
+// var x = jwtDecode(allObj);
|
|
|
+// // return x.sub.email;
|
|
|
+// // console.log(x);
|
|
|
+// } else {
|
|
|
+// return (
|
|
|
+// <div className="error">
|
|
|
+// <p>Неверный логин или пароль, попробуйте заново.</p>
|
|
|
+// </div>
|
|
|
+// );
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// };
|
|
|
+
|
|
|
+// way1 (obj, resolverName, a) {
|
|
|
+// const stateObj = this.props.state[obj];
|
|
|
+// for (var keys in stateObj) {
|
|
|
+// for (var keyData in stateObj[keys]) {
|
|
|
+// if (keyData === "data") {
|
|
|
+// const allObj = stateObj[keys][keyData][resolverName];
|
|
|
+// if (allObj) {
|
|
|
+// var x = jwtDecode(allObj);
|
|
|
+// return x.sub.email;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// };
|
|
|
+
|
|
|
+// componentDidMount() {
|
|
|
+// this.props.chatGroup("2");
|
|
|
+// // this.props.message();
|
|
|
+// }
|
|
|
+
|
|
|
+// // buttonEnter (e) {
|
|
|
+// // if (e.key === "Enter") this.props.onLogin(login, password);
|
|
|
+// // };
|
|
|
+
|
|
|
+// // const handleClick = () => history.push("/my_profile");
|
|
|
+
|
|
|
+// render(){
|
|
|
+// return (
|
|
|
+// <div className="login">
|
|
|
+// <div className="login-form"
|
|
|
+// // onKeyPress={buttonEnter}
|
|
|
+// >
|
|
|
+// <div className="login-title">
|
|
|
+// <h2>Войти в аккаунт</h2>
|
|
|
+// <p>Пожалуйста, войдите в свой аккаунт</p>
|
|
|
+// </div>
|
|
|
+
|
|
|
+// <div className="login-icon icon">
|
|
|
+// <UserOutlined />
|
|
|
+// <input
|
|
|
+// id="login"
|
|
|
+// value={this.state.login}
|
|
|
+// placeholder="Логин"
|
|
|
+// type="text"
|
|
|
+// onChange={(e) => this.setState({ login: e.target.value })}
|
|
|
+// />
|
|
|
+// </div>
|
|
|
+
|
|
|
+// <div className="password-icon icon">
|
|
|
+// <LockOutlined />
|
|
|
+// <input
|
|
|
+// id="password"
|
|
|
+// value={this.state.password}
|
|
|
+// placeholder="Пароль"
|
|
|
+// type="password"
|
|
|
+// onChange={(e) => this.setState({ password: e.target.value })}
|
|
|
+// />
|
|
|
+// <div className="not-see" onClick={loginEye}>
|
|
|
+// <EyeInvisibleOutlined />
|
|
|
+// </div>
|
|
|
+// <div className="see" onClick={loginEye}>
|
|
|
+// <EyeOutlined />
|
|
|
+// </div>
|
|
|
+// </div>
|
|
|
+
|
|
|
+// {this.way("login", "getLogin")}
|
|
|
+
|
|
|
+// <button
|
|
|
+// className="login-button"
|
|
|
+// onClick={() => this.props.onLogin(this.state.login, this.state.password)}
|
|
|
+// disabled={!this.state.login || !this.state.password}
|
|
|
+// >
|
|
|
+// Войти
|
|
|
+// </button>
|
|
|
+
|
|
|
+// <div className="register-put-password">
|
|
|
+// <Link to="/sign_up">Зарегестрироваться</Link>
|
|
|
+// <Link to="/put_password">Забыли пароль?</Link>
|
|
|
+// </div>
|
|
|
+// </div>
|
|
|
+// </div>
|
|
|
+// )}
|
|
|
+// };
|
|
|
+
|
|
|
const Login = (props) => <ConnectedLoginForm />;
|
|
|
|
|
|
const ConnectedLoginForm = connect(
|
|
|
(state) => {
|
|
|
return { state };
|
|
|
},
|
|
|
- { onLogin: actionLogin }
|
|
|
+ { onLogin: actionLogin, chatGroup: actionChatGroup }
|
|
|
)(LoginForm);
|
|
|
|
|
|
export default Login;
|