From 8003a7c29035da2f098d609caa2dde9064bef085 Mon Sep 17 00:00:00 2001 From: parkdongsu Date: Wed, 28 Jun 2023 05:03:45 +0000 Subject: [PATCH 1/3] =?UTF-8?q?[Router]=20Login=20=EB=9D=BC=EC=9A=B0?= =?UTF-8?q?=ED=84=B0=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20Login=20Component?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platform/viewer/src/App.js | 18 +++-- platform/viewer/src/Login.js | 149 +++++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+), 6 deletions(-) create mode 100644 platform/viewer/src/Login.js diff --git a/platform/viewer/src/App.js b/platform/viewer/src/App.js index 4e38961d574..c688156abb2 100644 --- a/platform/viewer/src/App.js +++ b/platform/viewer/src/App.js @@ -3,7 +3,7 @@ import { OidcProvider } from 'redux-oidc'; import { I18nextProvider } from 'react-i18next'; import PropTypes from 'prop-types'; import { Provider } from 'react-redux'; -import { BrowserRouter as Router } from 'react-router-dom'; +import { BrowserRouter as Router, Switch, Route } from 'react-router-dom'; import { hot } from 'react-hot-loader/root'; import OHIFCornerstoneExtension from '@ohif/extension-cornerstone'; @@ -48,6 +48,7 @@ import { GenericViewerCommands, MeasurementsPanel } from './appExtensions'; /** Viewer */ import OHIFStandaloneViewer from './OHIFStandaloneViewer'; +import Login from './Login'; /** Store */ import { getActiveContexts } from './store/layout/selectors.js'; @@ -179,7 +180,8 @@ class App extends Component { MeasurementService, LoggerService, } = servicesManager.services; - + console.log('Login') + console.log() if (this._userManager) { return ( @@ -197,9 +199,10 @@ class App extends Component { modal={OHIFModal} service={UIModalService} > - + + } /> + } /> + @@ -229,7 +232,10 @@ class App extends Component { modal={OHIFModal} service={UIModalService} > - + + + + diff --git a/platform/viewer/src/Login.js b/platform/viewer/src/Login.js new file mode 100644 index 00000000000..90b5a428a82 --- /dev/null +++ b/platform/viewer/src/Login.js @@ -0,0 +1,149 @@ +import React, { Component } from 'react'; +import { connect } from 'react-redux'; +import { ViewerbaseDragDropContext } from '@ohif/ui'; +import { withRouter } from 'react-router'; +import { Svg } from '@ohif/ui'; + +class Login extends Component { + + render() { + const handleSubmit = () =>{ + + } + const onSubmit = () =>{ + + } + + const isDirty = undefined + // const register = () =>{ + + // } + + const errors = {'id': 'false'} + // const isSubmitting = 'disabled' + + return ( +
+
+
+
+
+
+

LOGIN

+
+
+
+ + {errors.id && ( + + {errors.id.message} + + )} +
+
+ + {errors.password && ( + + {errors.password.message} + + )} +
+
+
+ + +
+ + Forgot Password? + +
+ +
+ +

+ Don't have an account? + + Sing Up + +

+
+ {/*
+ +
*/} +
+
+
+
+
+
+ ); + } +} + +const mapStateToProps = state => { + return { + user: state.oidc.user, + }; +}; + + +const ConnectedLogin = connect( + mapStateToProps, + null +)(Login); + +export default ViewerbaseDragDropContext( + withRouter(ConnectedLogin) +); + From eb8692212063bb840cf83c961ca6d275fdc215d9 Mon Sep 17 00:00:00 2001 From: BJ Park Date: Wed, 28 Jun 2023 17:04:29 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=EC=88=98=EC=A0=95=20=EC=9A=94=EC=B2=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platform/viewer/src/Login.js | 8 ++--- .../viewer/src/utils/axios/axiosResponse.js | 35 +++++++++++++++++++ .../viewer/src/utils/axios/loginRequest.js | 11 ++++++ 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 platform/viewer/src/utils/axios/axiosResponse.js create mode 100644 platform/viewer/src/utils/axios/loginRequest.js diff --git a/platform/viewer/src/Login.js b/platform/viewer/src/Login.js index 90b5a428a82..aeaf92f120f 100644 --- a/platform/viewer/src/Login.js +++ b/platform/viewer/src/Login.js @@ -2,13 +2,14 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; import { ViewerbaseDragDropContext } from '@ohif/ui'; import { withRouter } from 'react-router'; +import loginRequest from "../utils/axios"; import { Svg } from '@ohif/ui'; class Login extends Component { render() { const handleSubmit = () =>{ - + } const onSubmit = () =>{ @@ -21,8 +22,8 @@ class Login extends Component { const errors = {'id': 'false'} // const isSubmitting = 'disabled' - - return ( + loginRequest.post((`/login`)=>{} ) + return (
@@ -146,4 +147,3 @@ const ConnectedLogin = connect( export default ViewerbaseDragDropContext( withRouter(ConnectedLogin) ); - diff --git a/platform/viewer/src/utils/axios/axiosResponse.js b/platform/viewer/src/utils/axios/axiosResponse.js new file mode 100644 index 00000000000..f66acf084c4 --- /dev/null +++ b/platform/viewer/src/utils/axios/axiosResponse.js @@ -0,0 +1,35 @@ +import axios from "axios"; + +VITE_BACKEND_URL = 'http://grk-backend.medical-lab.co.kr/' +const request = axios.create({ + timeout: 30000, + baseURL: VITE_BACKEND_URL, + responseType: false, + headers: { + "Content-Type": "applicatipn/json", + Authorization: `Bearer ${sessionStorage.getItem("jwt")}`, + }, +}); + +request.interceptors.request.use((config) =>{ + const jwt = sessionStorage.getItem("jwt"); + + if(jwt === null){ + window.location.href = "/login"; + }else{ + config.headers.Authorization = `Bearer ${jwt}`; + } + return config +}); + +request.interceptors.response.use( + (response) => response, + (error) => { + const status = error.response ? error.response.status : null; + if (status === 401){ + window.location.href = "/login" + } + return Promise.reject(error); + } +) +export default request; diff --git a/platform/viewer/src/utils/axios/loginRequest.js b/platform/viewer/src/utils/axios/loginRequest.js new file mode 100644 index 00000000000..07eea2a93f1 --- /dev/null +++ b/platform/viewer/src/utils/axios/loginRequest.js @@ -0,0 +1,11 @@ +import axios from "axios"; + +VITE_BACKEND_URL = 'http://grk-backend.medical-lab.co.kr/' +const loginRequest = axios.create({ + timeout: 8000, + baseURL: VITE_BACKEND_URL, + withCredentials: false, + headers: { "content-type": "application/x-www-form-urlencoded" }, +}); + +export default loginRequest; From 1a3bc75eafd5eba92ab26e5e9de967e4a97af317 Mon Sep 17 00:00:00 2001 From: BJ Park Date: Wed, 28 Jun 2023 19:01:38 +0900 Subject: [PATCH 3/3] =?UTF-8?q?login=20=EA=B8=B0=EB=8A=A5=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platform/viewer/src/Login.js | 40 +++++++++++++++++-- .../viewer/src/utils/axios/axiosResponse.js | 2 +- .../viewer/src/utils/axios/loginRequest.js | 2 +- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/platform/viewer/src/Login.js b/platform/viewer/src/Login.js index aeaf92f120f..a1d73e4824c 100644 --- a/platform/viewer/src/Login.js +++ b/platform/viewer/src/Login.js @@ -2,8 +2,9 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; import { ViewerbaseDragDropContext } from '@ohif/ui'; import { withRouter } from 'react-router'; -import loginRequest from "../utils/axios"; +import loginRequest from "./utils/axios"; import { Svg } from '@ohif/ui'; +import { sessionTerminated } from 'redux-oidc'; class Login extends Component { @@ -11,9 +12,40 @@ class Login extends Component { const handleSubmit = () =>{ } - const onSubmit = () =>{ + const onSubmit = async data =>{ + await new Promise(r => setTimeout(r, 1000)); - } + //console.log(data); + data.id.toUpperCase(); + try{ + const responseToken = loginRequest + .post('/api/v1/token/', { + 'userId': data.id, + 'password': data.password, + }) + const jwtToken = responseToken.data; + console.log(responseToken) + console.log(jwtToken.accessToken) + console.log(jwtToken.refreshToken) + sessionStorage.setItem("jwt", jwtToken) + localStorage.setItem("jwt", jwtToken); //토큰에 저장되어있는 userInfo 저장 + return responseToken; + }catch{ + alert('로그인이 실패했습니다. 정보가 올바른지 다시 확인해주세요'); + } + console.log(responseToken); + if (data.id.toUpperCase() === 'GRK' && data.password === 'qwer1234') { + if (data.saveId) { + localStorage.setItem('saveId', data.id); + } else { + localStorage.removeItem('saveId'); + } + localStorage.setItem('isLogin', 'OK'); + navigate('/project'); + } else { + alert('아이디 비번을 확인하세요'); + } + }; const isDirty = undefined // const register = () =>{ @@ -22,7 +54,7 @@ class Login extends Component { const errors = {'id': 'false'} // const isSubmitting = 'disabled' - loginRequest.post((`/login`)=>{} ) + return (
diff --git a/platform/viewer/src/utils/axios/axiosResponse.js b/platform/viewer/src/utils/axios/axiosResponse.js index f66acf084c4..5f0c90ab086 100644 --- a/platform/viewer/src/utils/axios/axiosResponse.js +++ b/platform/viewer/src/utils/axios/axiosResponse.js @@ -1,6 +1,6 @@ import axios from "axios"; -VITE_BACKEND_URL = 'http://grk-backend.medical-lab.co.kr/' +const VITE_BACKEND_URL = 'http://grk-backend.medical-lab.co.kr/' const request = axios.create({ timeout: 30000, baseURL: VITE_BACKEND_URL, diff --git a/platform/viewer/src/utils/axios/loginRequest.js b/platform/viewer/src/utils/axios/loginRequest.js index 07eea2a93f1..116783e59b4 100644 --- a/platform/viewer/src/utils/axios/loginRequest.js +++ b/platform/viewer/src/utils/axios/loginRequest.js @@ -1,6 +1,6 @@ import axios from "axios"; -VITE_BACKEND_URL = 'http://grk-backend.medical-lab.co.kr/' +const VITE_BACKEND_URL = 'http://grk-backend.medical-lab.co.kr/' const loginRequest = axios.create({ timeout: 8000, baseURL: VITE_BACKEND_URL,