Skip to content

Commit

Permalink
improve: issue #39 register new user
Browse files Browse the repository at this point in the history
  • Loading branch information
hwt75 committed Jun 12, 2024
1 parent 1a45479 commit ebf0b86
Show file tree
Hide file tree
Showing 18 changed files with 433 additions and 36 deletions.
25 changes: 20 additions & 5 deletions frontend_web/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,30 @@ app.post("/login", async (req, res, next) => {
if (result.ok) {
const userInfo = await result.json();
const isDevEnv = config.default_api_url.match("127.0.0.1:3000") != null
res.cookie("user", userInfo.metadata.id);
res.cookie("user", userInfo.metadata.id, {
maxAge: 60000 * userInfo.metadata.expired_time,
httpOnly: false,
});
res.cookie("access_token", userInfo.metadata.access_token, {
maxAge: 60000 * userInfo.metadata.expired_time,
httpOnly: false,
});
res.cookie("refresh_token", userInfo.metadata.refresh_token);
res.cookie("role", userInfo.metadata.role);
res.cookie("api", isDevEnv ? config.default_api_url : `${config.redirect_url}/api`);
res.cookie("redirect_api", isDevEnv ? `http://${config.default_app_host}:${config.default_app_port}/login` : `${config.redirect_url}/login`);
res.cookie("refresh_token", userInfo.metadata.refresh_token, {
maxAge: 60000 * userInfo.metadata.expired_time,
httpOnly: false,
});
res.cookie("role", userInfo.metadata.role, {
maxAge: 60000 * userInfo.metadata.expired_time,
httpOnly: false,
});
res.cookie("api", isDevEnv ? config.default_api_url : `${config.redirect_url}/api`, {
maxAge: 60000 * userInfo.metadata.expired_time,
httpOnly: false,
});
res.cookie("redirect_api", isDevEnv ? `http://${config.default_app_host}:${config.default_app_port}/login` : `${config.redirect_url}/login`, {
maxAge: 60000 * userInfo.metadata.expired_time,
httpOnly: false,
});
return res.status(200).json("login successfully");
}
return res.status(400).json("login failed");
Expand Down
6 changes: 5 additions & 1 deletion frontend_web/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
refresh_token: "",
user_id: "",
};
console.log(window.location.host);

const access_token = getCookie("access_token");
if (access_token) {
Expand All @@ -70,7 +69,10 @@
role: localStorage.getItem("role"),
api: localStorage.getItem("api"),
};
console.log("hi");

} else {
console.log("hi");
cookieData = {
access_token: "",
refresh_token: "",
Expand All @@ -79,6 +81,8 @@
};
var url = window.location.host;
localStorage.clear();
window.location.href = "http://127.0.0.1:3001/login";

if (url !== "127.0.0.1:3002") {
window.location.href = "/login";
} else {
Expand Down
3 changes: 1 addition & 2 deletions frontend_web/src/layouts/DefaultLayout/DefaultLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import BubbleChat from "../../components/BubbleChat/BubbleChat";
const { Header, Content } = Layout;

const DefaultLayout = ({ children }) => {
const userName = getLocalStorage("username");
return (
<HashRouter>
<Layout style={{ height: "100vh" }}>
<Sidebar />
<Layout>
<Header style={{backgroundColor: "#f5f5f5"}}>
<HeaderUser userName={userName} token />
<HeaderUser />
</Header>
<Layout>
<Content className="main-content">
Expand Down
37 changes: 26 additions & 11 deletions frontend_web/src/layouts/route.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Home from "../pages/Home/home";
import DetailUser from "../pages/Account/Detail";
import NotFound from "../pages/NotFound/notfound";
import { Navigate, Route, Routes as ReactRoutes } from "react-router-dom";
import UserTable from "../pages/User/userTable";
import DeviceTable from "../pages/Device/deviceTable";
Expand All @@ -12,11 +11,14 @@ import {
WechatWorkOutlined,
UsergroupAddOutlined,
DesktopOutlined,
LineChartOutlined
LineChartOutlined,
UserAddOutlined,
UserSwitchOutlined
} from "@ant-design/icons";
import { userRole } from "../constants";
import { context } from "../utils/context";
// import Chat from "../pages/Chat/chat";
import Chat from "../pages/Chat/chat";
import Register from "../pages/Register/register";

export const AdminRouterMappingGroup = {
User: {
Expand All @@ -39,9 +41,15 @@ export const AdminRouterMappingGroup = {
},
AssignmentPatientDoctor: {
key: "/pda",
label: "Thông tin assignment",
label: "Thông tin bác sĩ bệnh nhân",
component: <PdaTable />,
icon: <UnorderedListOutlined />,
icon: <UserSwitchOutlined />,
},
Register: {
key: "/registers",
label: "Người dùng đăng ký mới",
component: <Register />,
icon: <UserAddOutlined />,
}
};

Expand All @@ -64,12 +72,12 @@ export const doctorRouterMappingGroup = {
component: <RecordTable />,
icon: <LineChartOutlined />,
},
// Chat:{
// key:"/chat",
// label: "Chat với bác sĩ",
// component: <Chat />,
// icon: <WechatWorkOutlined />
// }
Chat:{
key:"/chat",
label: "Chat với bệnh nhân",
component: <Chat />,
icon: <WechatWorkOutlined />
}
};

export const patientRouterMappingGroup = {
Expand All @@ -92,6 +100,13 @@ export const patientRouterMappingGroup = {
component: <RecordTable />,
icon: <LineChartOutlined />,
}
,
Chat:{
key:"/chat",
label: "Chat với bác sĩ",
component: <Chat />,
icon: <WechatWorkOutlined />
}
};

export const getRoutesByRole = (role) => {
Expand Down
1 change: 0 additions & 1 deletion frontend_web/src/pages/Account/Detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import "./detail.scss";
import { convertGenderToString, convertRoleToString } from "../../constants";
import { context } from "../../utils/context";

const { Option } = Select;
export default function Detail() {
const dispatch = useDispatch();

Expand Down
10 changes: 10 additions & 0 deletions frontend_web/src/pages/Chat/chat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React, { useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";

const Chat = () => {
return (
<>chat</>
)
}

export default Chat;
Empty file.
8 changes: 4 additions & 4 deletions frontend_web/src/pages/Record/recordTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ const RecordTable = () => {
editFunction={handleEditFunction}
deleteButton
deleteFunction={handleDeleteFunction}
name="Bảng quản lý record"
name="Dữ liệu y tế"
data={dataTable}
column={columns}
updateSelectedData={setSelectedData}
Expand All @@ -262,7 +262,7 @@ const RecordTable = () => {

<ModalControlData
ref={modalUpdateRef}
title="Sửa thông tin record"
title="Sửa thông tin bản ghi"
submitFunction={(data) => handleSubmitEditUser(data)}
/>

Expand All @@ -273,10 +273,10 @@ const RecordTable = () => {
/>

<Modal
title="Download record status"
title="Trạng thái bản ghi"
open={isModalOpen}
onOk={handleOk}
okText="Download"
okText="Tải"
confirmLoading={dataState.loadCheckRecordStatus === loadStatus.Loading}
onCancel={handleCancel}
>
Expand Down
10 changes: 10 additions & 0 deletions frontend_web/src/pages/Register/register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React, { useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";

const Register = () => {
return (
<>Register</>
)
}

export default Register;
Empty file.
12 changes: 4 additions & 8 deletions frontend_web/src/pages/User/userTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import dayjs from "dayjs";
import { UserDetail } from "./userDetail";
import { context } from "../../utils/context";

const UserTable = () => {
const UserTable = (props) => {
const dispatch = useDispatch();
const dataState = useSelector((state) => state.user);
const [dataTable, setDataTable] = useState([]);
Expand Down Expand Up @@ -91,8 +91,6 @@ const UserTable = () => {
</Tag>)
}
}


];

const handleData = (data, type) => {
Expand Down Expand Up @@ -176,19 +174,17 @@ const UserTable = () => {
};

const handleSubmitEditUser = (data) => {
// console.log(data);
const { account_id, devices, role, records, status, ...payload } = { ...data };
console.log(payload);
return dispatch(updateUser(payload));
};

const getTitleTable = () => {
if (context.role === userRole.doctor) {
return "Quản lý bệnh nhân";
return "Thông tin bệnh nhân";
} else if (context.role === userRole.patient) {
return "Bác sĩ điều trị";
} else {
return "Quản lý người dùng";
return "Thông tin người dùng";
}
};
return (
Expand All @@ -209,7 +205,7 @@ const UserTable = () => {
/>
<ModalControlData
ref={modalUpdateRef}
title="Sửa thông tin người dùng"
title= {getTitleTable()}
submitFunction={(data) => handleSubmitEditUser(data)}
/>
<UserDetail ref={drawerRef} />
Expand Down
11 changes: 11 additions & 0 deletions server-web/config/chatgpt_api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Configuration, OpenAIApi } from 'openai';
import dotenv from 'dotenv';
dotenv.config();

const configuration = new Configuration({
apiKey: '',
});

const openai = new OpenAIApi(configuration);

export default openai;
52 changes: 52 additions & 0 deletions server-web/migrations/20240611041406-create-register-table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up (queryInterface, Sequelize) {
await queryInterface.createTable('registers',
{
id: {
type: Sequelize.STRING,
allowNull: false,
primaryKey: true,
},
email:{
type: Sequelize.STRING,
allowNull: false,
},
password:{
type: Sequelize.STRING,
allowNull: false,
},
username: {
type: Sequelize.STRING,
allowNull: false,
},
gender: {
type: Sequelize.INTEGER,
},
birth: {
type: Sequelize.BIGINT,
allowNull: false,
},
phone_number: Sequelize.STRING,
image: Sequelize.STRING,
status: {
type: Sequelize.INTEGER,
allowNull: false,
},
information: Sequelize.STRING,
role: {
type: Sequelize.INTEGER,
allowNull: false,
},
created_at: Sequelize.BIGINT,
updated_at: Sequelize.BIGINT,
}
);
},

async down (queryInterface, Sequelize) {
await queryInterface.dropTable('register');
}
};
47 changes: 47 additions & 0 deletions server-web/models/RegisterModel/RegisterDTO.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const Sequelize = require("sequelize");
const sequelize = require("../../config/sequelize");

const User = sequelize.define(
"registers",
{
id: {
type: Sequelize.STRING,
allowNull: false,
primaryKey: true,
},
email: {
type: Sequelize.STRING,
allowNull: false,
},
password: {
type: Sequelize.STRING,
allowNull: false,
},
username: {
type: Sequelize.STRING,
allowNull: false,
},
gender: {
type: Sequelize.INTEGER,
},
birth: {
type: Sequelize.BIGINT,
allowNull: false,
},
phone_number: Sequelize.STRING,
image: Sequelize.STRING,
status: {
type: Sequelize.INTEGER,
allowNull: false,
},
information: Sequelize.STRING,
role: {
type: Sequelize.INTEGER,
allowNull: false,
},
created_at: Sequelize.BIGINT,
updated_at: Sequelize.BIGINT,
}
);

module.exports = User;
Loading

0 comments on commit ebf0b86

Please sign in to comment.