diff --git a/src/components/index/indexConsole/commands/commands.js b/src/components/index/indexConsole/commands/commands.js index 33fb9ae..a0da69a 100644 --- a/src/components/index/indexConsole/commands/commands.js +++ b/src/components/index/indexConsole/commands/commands.js @@ -5,7 +5,13 @@ import ConsoleLoad from '../consoleLoad' const help = () => { return "register - register user by form \n" + "login - login user by form \n" - + "logout - logout user \n" + + "start - start command \n" + + " -a --app - app flag - start music service app \n" + + "clean - clean screen \n" +} + +const helpUser = () => { + return "logout - logout user \n" + "start - start command \n" + " -a --app - app flag - start music service app \n" + "clean - clean screen \n" @@ -34,6 +40,7 @@ const undefined = (command) => { export default { help, + helpUser, register, startApp, undefined diff --git a/src/components/index/indexConsole/commands/fetchCommands/Login.js b/src/components/index/indexConsole/commands/fetchCommands/Login.js index 183f4e8..ae1ab5f 100644 --- a/src/components/index/indexConsole/commands/fetchCommands/Login.js +++ b/src/components/index/indexConsole/commands/fetchCommands/Login.js @@ -1,50 +1,76 @@ -import React, { useState } from 'react' +import React, { useState, useEffect } from 'react' import { connect } from 'react-redux' import { postAuth } from '../../../../../stores/user/duck/operations' -const Login = ({ user, postAuth }) => { +const Login = ({ user, postAuth, consoleHistory, setConsoleHistory, componentVisible }) => { const loginInput = React.createRef() const passwInput = React.createRef() const [message, setMessage] = useState('') - const login = (event) => { + const login = async (event) => { event.preventDefault() - if ( loginInput.current.value !== '' && - passwInput.current.value !== '') { - postAuth( - loginInput.current.value, - passwInput.current.value - ).then( response => { - setMessage(response['error']) + + let login = loginInput.current.value + let password = passwInput.current.value + + if ( login !== '' && password !== '') { + + postAuth(login, password) + .then( response => { + setMessage( response['error'] ) }) - document.getElementById('passwInput').disbled = true - document.getElementById('passwInput').disabled = true + } else if ( passwInput.current.value === '' ) { document.getElementById('passwInput').focus() } } + useEffect( + () => { + if (message !== '') { + let save = 'login: ' + loginInput.current.value + '\n' + + 'password: ' + hidePassword( passwInput.current.value ) + '\n' + + message + '\n' + + loginInput.current.value = '' + passwInput.current.value = '' + + setConsoleHistory( consoleHistory + save ) + componentVisible( false ) + setMessage('') + } + } + ) + + const hidePassword = (password) => { + let hide = '' + for (let i = 0; i <= password.length; i++) + hide += '*' + return hide + } + return (