changing fields in account is done and upd chats retrieval
This commit is contained in:
parent
86db5df813
commit
25c3e16c74
@ -5,7 +5,7 @@ const LOCAL = "http://localhost:8099";
|
|||||||
const DEV = "https://dev.bro-js.ru";
|
const DEV = "https://dev.bro-js.ru";
|
||||||
const SERVER = "";
|
const SERVER = "";
|
||||||
|
|
||||||
export const BASE_API_URL = DEV + getConfigValue("enterfront.api") + "/enterfront";
|
export const BASE_API_URL = LOCAL + getConfigValue("enterfront.api") + "/enterfront";
|
||||||
|
|
||||||
// fetch(`${BASE_API_URL}/books/list`)
|
// fetch(`${BASE_API_URL}/books/list`)
|
||||||
|
|
||||||
|
@ -1,15 +1,46 @@
|
|||||||
import React from 'react';
|
import React, {useState} from 'react';
|
||||||
import { URLs } from "../../__data__/urls";
|
import { URLs } from "../../__data__/urls";
|
||||||
import ActionButton from "./ActionButton.jsx";
|
import ActionButton from "./ActionButton.jsx";
|
||||||
|
import InputField from "../reg/InputField.jsx";
|
||||||
|
|
||||||
const AccountButtons = (props) => {
|
const AccountButtons = (props) => {
|
||||||
|
const [chName, setChName] = useState(false);
|
||||||
|
const [chPassword, setChPassword] = useState(false);
|
||||||
|
|
||||||
|
const [nickname, setNickname] = useState("");
|
||||||
|
const [password, setPassword] = useState("");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="account-buttons">
|
<div className="account-buttons">
|
||||||
{props.registered ? (
|
{props.registered ? (
|
||||||
<>
|
<>
|
||||||
<ActionButton title={"Exit"} action={props.exitHandler}/>
|
<ActionButton title={"Exit"} action={props.exitHandler}/>
|
||||||
<ActionButton title={"Change Name"} action={props.changeNameHandler}/>
|
<ActionButton title={"Change Name"} action={() => setChName(true)}/>
|
||||||
<ActionButton title={"Change Pass"} action={props.changePassHandler}/>
|
{chName ? (
|
||||||
|
<InputField
|
||||||
|
title={""}
|
||||||
|
value={nickname}
|
||||||
|
setValue={setNickname}
|
||||||
|
placeholder='Enter your new nickname'
|
||||||
|
|
||||||
|
submit={nickname}
|
||||||
|
enter={props.changeNameHandler}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
<ActionButton title={"Change Pass"} action={() => setChPassword(true)}/>
|
||||||
|
{chPassword ? (
|
||||||
|
<div>
|
||||||
|
<InputField
|
||||||
|
title={""}
|
||||||
|
value={password}
|
||||||
|
setValue={setPassword}
|
||||||
|
placeholder='Enter your new password'
|
||||||
|
|
||||||
|
submit={password}
|
||||||
|
enter={props.changePassHandler}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
</>
|
</>
|
||||||
) : null}
|
) : null}
|
||||||
<a className="MyButton mclaren-regular" href={URLs.home.url}>Back</a>
|
<a className="MyButton mclaren-regular" href={URLs.home.url}>Back</a>
|
||||||
|
@ -20,6 +20,13 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.search-input div input {
|
||||||
|
background-color: white;
|
||||||
|
color: black;
|
||||||
|
|
||||||
|
border: 3px solid black;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@media only screen and (max-width: 800px) {
|
@media only screen and (max-width: 800px) {
|
||||||
.homeTitle {
|
.homeTitle {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
const InputField = (props) => {
|
const InputField = (props) => {
|
||||||
|
console.log('class:', props.className)
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<p>{props.title}</p>
|
<p>{props.title}</p>
|
||||||
@ -9,6 +10,13 @@ const InputField = (props) => {
|
|||||||
value={props.value}
|
value={props.value}
|
||||||
className="Input"
|
className="Input"
|
||||||
placeholder={(props.placeholder) ? props.placeholder : ''}
|
placeholder={(props.placeholder) ? props.placeholder : ''}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
if (props.submit) {
|
||||||
|
props.enter(props.submit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -19,10 +19,10 @@ const Account = () => {
|
|||||||
const [nickname, setNickname] = useState("");
|
const [nickname, setNickname] = useState("");
|
||||||
const [id, setId] = useState("");
|
const [id, setId] = useState("");
|
||||||
|
|
||||||
async function changeNameHandler () {
|
async function changeNameHandler (newNickname) {
|
||||||
// ...
|
if (!newNickname) return;
|
||||||
|
|
||||||
const {ok, data} = await post('/change/nickname', {id: id, newNickname: "New Name"});
|
const {ok, data} = await post('/change/nickname', {id: id, newNickname: newNickname});
|
||||||
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
displayMessage(data.message, MessageType.ERROR);
|
displayMessage(data.message, MessageType.ERROR);
|
||||||
@ -32,8 +32,17 @@ const Account = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function changePassHandler (){
|
async function changePassHandler (newPass){
|
||||||
// ...
|
if (!newPass) return;
|
||||||
|
|
||||||
|
const {ok, data} = await post('/change/password', {id: id, newPassword: newPass});
|
||||||
|
|
||||||
|
if (!ok) {
|
||||||
|
displayMessage(data.message, MessageType.ERROR);
|
||||||
|
} else {
|
||||||
|
localStorage.setItem("message", "Password was changed");
|
||||||
|
window.location.href = URLs.account.url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getUser() {
|
async function getUser() {
|
||||||
|
@ -35,6 +35,8 @@ const Home = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
displayMessage("Sent", MessageType.INFO);
|
||||||
|
|
||||||
const {ok, data} = await post('/chat/item/' + username + '/' + alias);
|
const {ok, data} = await post('/chat/item/' + username + '/' + alias);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
displayMessage(data.message, MessageType.ERROR);
|
displayMessage(data.message, MessageType.ERROR);
|
||||||
@ -55,12 +57,15 @@ const Home = () => {
|
|||||||
|
|
||||||
<HomeTitle/>
|
<HomeTitle/>
|
||||||
|
|
||||||
<InputField
|
<div className="search-input">
|
||||||
title="Create new chat"
|
<InputField
|
||||||
value={interlocutor}
|
title="Create new chat"
|
||||||
setValue={setInterlocutor}
|
value={interlocutor}
|
||||||
placeholder="Enter the username (id)"
|
setValue={setInterlocutor}
|
||||||
/>
|
placeholder="Enter the username (id)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<Search search={createChat} item={interlocutor}/>
|
<Search search={createChat} item={interlocutor}/>
|
||||||
|
|
||||||
<p>Your chats</p>
|
<p>Your chats</p>
|
||||||
|
@ -34,11 +34,13 @@ authRouter.post('/login', (req, res) => {
|
|||||||
// Invalid identification
|
// Invalid identification
|
||||||
if (!user) {
|
if (!user) {
|
||||||
res.status(401).send({message: 'Invalid credentials (id)'});
|
res.status(401).send({message: 'Invalid credentials (id)'});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invalid authentication
|
// Invalid authentication
|
||||||
if (!password || password !== user.password) {
|
if (!password || password !== user.password) {
|
||||||
res.status(401).send({message: 'Invalid credentials (password)'});
|
res.status(401).send({message: 'Invalid credentials (password)'});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now, authorization
|
// Now, authorization
|
||||||
@ -59,10 +61,12 @@ authRouter.post('/reg', (req, res) => {
|
|||||||
// Invalid identification
|
// Invalid identification
|
||||||
if (user) {
|
if (user) {
|
||||||
res.status(409).send({message: 'Such id already exists'});
|
res.status(409).send({message: 'Such id already exists'});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!name || !password || !nickname) {
|
if (!name || !password || !nickname) {
|
||||||
res.status(401).send({message: 'Empty or invalid fields'});
|
res.status(401).send({message: 'Empty or invalid fields'});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to 'DB'
|
// Add to 'DB'
|
||||||
|
@ -16,6 +16,7 @@ changeRouter.post('/nickname', (req, res) => {
|
|||||||
// Invalid identification
|
// Invalid identification
|
||||||
if (!user) {
|
if (!user) {
|
||||||
res.status(401).send({message: 'Invalid credentials (id)'});
|
res.status(401).send({message: 'Invalid credentials (id)'});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedUser = {
|
const updatedUser = {
|
||||||
@ -42,6 +43,7 @@ changeRouter.post('/password', (req, res) => {
|
|||||||
// Invalid identification
|
// Invalid identification
|
||||||
if (!user) {
|
if (!user) {
|
||||||
res.status(401).send({message: 'Invalid credentials (id)'});
|
res.status(401).send({message: 'Invalid credentials (id)'});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the old one
|
// Delete the old one
|
||||||
|
Loading…
Reference in New Issue
Block a user