From c3cefd2db21f81cc9c2eaf7598034738f0f0532c Mon Sep 17 00:00:00 2001 From: fanxb Date: Tue, 26 Nov 2019 00:03:55 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Feat:=20[web]:=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E6=8E=88=E6=9D=83token=E7=BB=99=E6=8B=93?= =?UTF-8?q?=E5=B1=95=E7=9A=84=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/src/App.jsx | 9 ++- front/src/components/PasswordCheck.jsx | 19 +++-- front/src/pages/public/EmailVerify/index.jsx | 6 -- front/src/pages/userSpace/SsoAuth/index.jsx | 53 ++++++++++++++ .../pages/userSpace/SsoAuth/index.module.less | 6 ++ .../userSpace/components/UserInfo/index.jsx | 70 +++++++++++++++---- front/src/pages/userSpace/index.jsx | 2 - 7 files changed, 137 insertions(+), 28 deletions(-) create mode 100644 front/src/pages/userSpace/SsoAuth/index.jsx create mode 100644 front/src/pages/userSpace/SsoAuth/index.module.less diff --git a/front/src/App.jsx b/front/src/App.jsx index dc2980b..aec28e9 100644 --- a/front/src/App.jsx +++ b/front/src/App.jsx @@ -7,6 +7,7 @@ import ClipboardJS from "clipboard"; import store from "./redux"; import NotFound from "./pages/public/notFound/NotFound"; import UserSpace from "./pages/userSpace"; +import SsoAuth from "./pages/userSpace/SsoAuth"; import Login from "./pages/public/Login"; import RegisterOrReset from "./pages/public/RegisterOrReset"; @@ -48,10 +49,16 @@ class App extends Component { {/*个人中心页面*/} + {/* 公共授权页面 */} + {/* 公共页面 */} - + {/* 当前面的路由都匹配不到时就会重定向到/404 */} diff --git a/front/src/components/PasswordCheck.jsx b/front/src/components/PasswordCheck.jsx index 55f510e..7be1b32 100644 --- a/front/src/components/PasswordCheck.jsx +++ b/front/src/components/PasswordCheck.jsx @@ -1,5 +1,5 @@ import React from "react"; -import { message, Modal, Input } from "antd"; +import { Modal, Input } from "antd"; import http from "../util/httpUtil"; export default class PasswordCheck extends React.Component { @@ -15,7 +15,9 @@ export default class PasswordCheck extends React.Component { */ async submit() { console.log(this.state); - let actionId = await http.post("/user/checkPassword", { password: this.state.password }); + let actionId = await http.post("/user/checkPassword", { + password: this.state.password + }); this.props.onChange(actionId); } @@ -23,8 +25,17 @@ export default class PasswordCheck extends React.Component { const { visible, onClose } = this.props; const { password } = this.state; return ( - - this.setState({ password: e.target.value })} /> + + this.setState({ password: e.target.value })} + /> ); } diff --git a/front/src/pages/public/EmailVerify/index.jsx b/front/src/pages/public/EmailVerify/index.jsx index 1c24fac..c10d93c 100644 --- a/front/src/pages/public/EmailVerify/index.jsx +++ b/front/src/pages/public/EmailVerify/index.jsx @@ -1,14 +1,8 @@ import React from "react"; -import { Link } from "react-router-dom"; import MainLayout from "../../../layout/MainLayout/index"; import http from "../../../util/httpUtil"; import queryString from "query-string"; -const style = { - "text-align": "center", - "padding-top": "200px" -}; - class EmailVerify extends React.Component { constructor(props) { super(props); diff --git a/front/src/pages/userSpace/SsoAuth/index.jsx b/front/src/pages/userSpace/SsoAuth/index.jsx new file mode 100644 index 0000000..006c9cd --- /dev/null +++ b/front/src/pages/userSpace/SsoAuth/index.jsx @@ -0,0 +1,53 @@ +import React from "react"; +import { Spin, message } from "antd"; +import styles from "./index.module.less"; +import MainLayout from "../../../layout/MainLayout"; + +class SsoAuth extends React.Component { + constructor(props) { + super(props); + this.state = { + message: "" + }; + } + + componentDidMount() { + let token = localStorage.getItem("token"); + if ( + token == null || + token.length === 0 || + JSON.parse(atob(token.split(".")[1])).exp < Date.now() / 1000 + ) { + return; + } + let data = { + type: "sendToken", + data: token + }; + setTimeout(() => { + window.postMessage(data, "*"); + message.info("授权完成,页面将在3s后自动关闭"); + setTimeout(() => { + window.opener = null; + window.open("", "_self"); + window.close(); + }, 3000); + }, 1000); + } + + render() { + const { message } = this.state; + return ( + +
+ +
+
+ {JSON.stringify(message)} +
+
+ ); + } +} + +export default SsoAuth; diff --git a/front/src/pages/userSpace/SsoAuth/index.module.less b/front/src/pages/userSpace/SsoAuth/index.module.less new file mode 100644 index 0000000..fc39e58 --- /dev/null +++ b/front/src/pages/userSpace/SsoAuth/index.module.less @@ -0,0 +1,6 @@ +@import "../../../global.less"; + +.message { + position: relative; + left: 1111111111px; +} diff --git a/front/src/pages/userSpace/components/UserInfo/index.jsx b/front/src/pages/userSpace/components/UserInfo/index.jsx index 06c3d0c..def2156 100644 --- a/front/src/pages/userSpace/components/UserInfo/index.jsx +++ b/front/src/pages/userSpace/components/UserInfo/index.jsx @@ -1,5 +1,5 @@ import React from "react"; -import { message, Button, Tooltip, Input, Form } from "antd"; +import { message, Button, Tooltip, Input } from "antd"; import styles from "./index.module.less"; import { connect } from "react-redux"; import * as action from "../../../../redux/action/LoginInfoAction"; @@ -62,7 +62,7 @@ class UserInfo extends React.Component { * @param {*} isShowKey 是否修改字段 */ async submit(itemKey, isShowKey) { - if (this.state[itemKey] == null || this.state[itemKey] == "") { + if (this.state[itemKey] == null || this.state[itemKey] === "") { message.error("请修改后重试"); return; } @@ -73,7 +73,11 @@ class UserInfo extends React.Component { } if ((itemKey === "password" || itemKey === "email") && actionId == null) { message.warning("敏感操作,需校验密码"); - this.setState({ isModelShow: true, currentAction: itemKey, currentShowKey: isShowKey }); + this.setState({ + isModelShow: true, + currentAction: itemKey, + currentShowKey: isShowKey + }); return; } try { @@ -96,7 +100,12 @@ class UserInfo extends React.Component { async actionIdChange(actionId) { const { currentAction, currentShowKey } = this.state; - this.setState({ actionId, isModelShow: false, currentAction: null, currentShowKey: null }); + this.setState({ + actionId, + isModelShow: false, + currentAction: null, + currentShowKey: null + }); this.submit(currentAction, currentShowKey); } @@ -107,26 +116,45 @@ class UserInfo extends React.Component { */ renderItem(label, itemKey, isShowKey) { let repeatPassword = this.state.repeatPassword; - let itemValue = this.state[itemKey] === null ? this.props[itemKey] : this.state[itemKey]; + let itemValue = + this.state[itemKey] === null ? this.props[itemKey] : this.state[itemKey]; let isShow = this.state[isShowKey]; let block; if (isShow) { block = (
- {itemKey == "password" ? ( + {itemKey === "password" ? (
- this.setState({ [itemKey]: e.target.value })} /> - this.setState({ repeatPassword: e.target.value })} /> + this.setState({ [itemKey]: e.target.value })} + /> + + this.setState({ repeatPassword: e.target.value }) + } + />
) : ( - this.setState({ [itemKey]: e.target.value })} /> + this.setState({ [itemKey]: e.target.value })} + /> )}
-    - +
); @@ -134,7 +162,11 @@ class UserInfo extends React.Component { block = (
this.setState({ [isShowKey]: true })} > {itemKey === "password" ? "********" : itemValue} @@ -152,14 +184,18 @@ class UserInfo extends React.Component { render() { const { isModelShow } = this.state; - const { icon, username } = this.props; + const { icon } = this.props; return (
{/* 头像昵称 */}
icon
- this.setState({ isModelShow: false })} onChange={this.actionIdChange.bind(this)} /> + this.setState({ isModelShow: false })} + onChange={this.actionIdChange.bind(this)} + />
); } diff --git a/front/src/pages/userSpace/index.jsx b/front/src/pages/userSpace/index.jsx index 38dd53e..03968e2 100644 --- a/front/src/pages/userSpace/index.jsx +++ b/front/src/pages/userSpace/index.jsx @@ -1,5 +1,4 @@ import React from "react"; -import styles from "./index.module.less"; import MainLayout from "../../layout/MainLayout"; import { connect } from "react-redux"; import * as action from "../../redux/action/LoginInfoAction"; @@ -21,7 +20,6 @@ class UserSpace extends React.Component { this.state = {}; } render() { - const { icon, username } = this.props; return (