diff --git a/package.json b/package.json index 92e78eb7a..3d2d7daf5 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "connect-timeout": "^1.9.0", "connected-react-router": "4.4.1", "core-js": "^3.34.0", + "crypto-js": "^4.2.0", "dompurify": "^2.3.3", "dotenv": "4.0.0", "dotenv-expand": "4.2.0", diff --git a/src/common/Env.js b/src/common/Env.js index 9830d7725..6fcfec767 100644 --- a/src/common/Env.js +++ b/src/common/Env.js @@ -1,3 +1,5 @@ +import CryptoJS from 'crypto-js'; + export function isDev() { return window.location.port === "3007"; } @@ -6,3 +8,12 @@ export function isDev() { export const isMobile = (/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent.toLowerCase())); // const isWeiXin = (/MicroMessenger/i.test(navigator.userAgent.toLowerCase())); + +export function Encrypt(str){ + let result = CryptoJS.AES.encrypt(str,CryptoJS.enc.Utf8.parse('59c96c3572ab8cc1'),{ + iv:CryptoJS.enc.Utf8.parse('59c96c3572ab8cc1'), + mode: CryptoJS.mode.CBC, + padding: CryptoJS.pad.Pkcs7 + }) + return result.toString(); +} diff --git a/src/forge/Team/Setting/TeamSettingCommon.jsx b/src/forge/Team/Setting/TeamSettingCommon.jsx index 2fb769a9f..475b26270 100644 --- a/src/forge/Team/Setting/TeamSettingCommon.jsx +++ b/src/forge/Team/Setting/TeamSettingCommon.jsx @@ -7,6 +7,7 @@ import styled from 'styled-components'; import axios from 'axios'; import Modals from '../Component/Modals'; import AvatarModal from '../../users/Avatar/Index'; +import { Encrypt } from '../../../common/Env'; import { getImageUrl } from 'educoder'; const TextArea = Input.TextArea; @@ -93,7 +94,7 @@ export default Form.create()( function onOk(password){ const url = `/organizations/${organizeDetail.id}.json`; axios.delete(url,{ - params:{ password } + params:{ password:Encrypt(password) } }).then(result=>{ if(result && result.data){ // 删除后跳转到个人中心的组织页面 diff --git a/src/forge/users/Material/Password.jsx b/src/forge/users/Material/Password.jsx index bbb4a30c2..b7aa31028 100644 --- a/src/forge/users/Material/Password.jsx +++ b/src/forge/users/Material/Password.jsx @@ -8,6 +8,7 @@ import { setmiyah } from '../../../common/Component'; import { useEffect } from 'react'; import Phone from './Phone'; import OffAccount from './component/offAccount'; +import { Encrypt } from '../../../common/Env'; export default Form.create()( forwardRef((props)=>{ @@ -108,7 +109,7 @@ export default Form.create()( const map = type === '0' ? passMap : updatePsdMap; if(value){ current_user && Axios.post(`/v1/${current_user.login}/check_password.json`,{ - password: value + password: Encrypt(value) }).then(res=>{ if(res && !res.data.status){ if(type === '0'){ @@ -157,11 +158,11 @@ export default Form.create()( }else{ setEmailValue(undefined); map.email = undefined; + // 防止已经输入过验证码但是还未输入邮箱地址 + setFieldsValue({code:""}) setPassMap(map); callback(res.data.message); } - // 防止已经输入过验证码但是还未输入邮箱地址 - setFieldsValue({code:""}) }) }else{ setEmailValue(undefined); @@ -211,7 +212,7 @@ export default Form.create()( const {code, email, password1} = getFieldsValue(); if(code && email && password1){ current_user && Axios.patch(`/v1/${current_user.login}/update_email.json`,{ - code, email, password: password1 + code, email, password:Encrypt(password1) }).then(res=>{ if(res && !res.data.status){ setPassMap({password: undefined, email: undefined, code: undefined}); @@ -227,10 +228,13 @@ export default Form.create()( } }else{ const values = getFieldsValue(); + const { old_password , password , new_password_repeat } = values; const url = `/accounts/change_password.json`; Axios.post(url,{ login:current_user && current_user.login, - ...values + old_password:Encrypt(old_password), + password:Encrypt(password), + new_password_repeat:Encrypt(new_password_repeat), }).then(result=>{ if(result && result.data){ resetFields(); diff --git a/src/forge/users/Material/Phone.jsx b/src/forge/users/Material/Phone.jsx index 3e9d04fb3..7d2717b04 100644 --- a/src/forge/users/Material/Phone.jsx +++ b/src/forge/users/Material/Phone.jsx @@ -4,6 +4,7 @@ import Modals from '../../Component/PublicModal/Index'; import { AlignCenter } from '../../Component/layout'; import img1 from '../../Images/personalInfo3.png'; import { setmiyah } from '../../../common/Component'; +import { Encrypt } from '../../../common/Env'; import Axios from 'axios'; @@ -21,7 +22,7 @@ export default Form.create()( const map = passMap; if(value){ current_user && value.length > 7 && Axios.post(`/v1/${current_user.login}/check_password.json`,{ - password: value + password: Encrypt(value) }).then(res=>{ if(res && !res.data.status){ map.logpassword = value; @@ -147,7 +148,7 @@ export default Form.create()( const {mescode, phone, logpassword} = getFieldsValue(); if(mescode && phone && logpassword){ current_user && Axios.patch(`/v1/${current_user.login}/update_phone.json`,{ - code:mescode, phone, password:logpassword + code:mescode, phone, password: Encrypt(logpassword) }).then(res=>{ if(res && !res.data.status){ setPassMap({logpassword: undefined, phone: undefined, code: undefined}); diff --git a/src/forge/users/Material/component/offAccount.jsx b/src/forge/users/Material/component/offAccount.jsx index 44acb2e8e..8a4f89c1b 100644 --- a/src/forge/users/Material/component/offAccount.jsx +++ b/src/forge/users/Material/component/offAccount.jsx @@ -1,6 +1,7 @@ import React , { forwardRef, useState } from 'react'; import { Modal , Form , Button , Input } from 'antd'; import Axios from 'axios'; +import { Encrypt } from '../../../../common/Env'; const { TextArea } = Input; export default Form.create()(forwardRef((props)=>{ @@ -12,10 +13,11 @@ export default Form.create()(forwardRef((props)=>{ function onDelete(){ validateFields((error,values)=>{ if(!error && current_user){ + const { password } = values; setLoading(true); const url = `/v1/${current_user.login}.json`; Axios.delete(url,{ - data:{...values} + data:{...values,password:Encrypt(password)} }).then(result=>{ if(result.data && result.data.status === 0){ window.location.href = `/`; diff --git a/src/modules/loginRegister/Login.jsx b/src/modules/loginRegister/Login.jsx index 614a26545..30fcf35ff 100644 --- a/src/modules/loginRegister/Login.jsx +++ b/src/modules/loginRegister/Login.jsx @@ -10,6 +10,7 @@ import axios from 'axios'; import OtherLogin from "./component/otherLogin"; import cookie from 'react-cookies'; import './LoginRegisterPage.scss'; +import { Encrypt } from "../../common/Env"; function Login(props){ const [message,setMessage] = useState(); @@ -18,6 +19,7 @@ function Login(props){ const {getFieldDecorator } = form; const {search} = location; + useEffect(()=>{ //控制密码输入框在DOM不可见value clear(); @@ -40,7 +42,7 @@ function Login(props){ if (!err) { axios.post(`/accounts/login.json`, { login: values.username, - password: values.password, + password: Encrypt(values.password), autologin: values.remember?1:0, }).then((response) => { if (!response.data.login) { diff --git a/src/modules/loginRegister/Register.jsx b/src/modules/loginRegister/Register.jsx index e1b77da91..e9ba19a62 100644 --- a/src/modules/loginRegister/Register.jsx +++ b/src/modules/loginRegister/Register.jsx @@ -5,6 +5,7 @@ import axios from 'axios'; import { setmiyah } from 'educoder'; import './LoginRegisterPage.scss'; import OtherLogin from "./component/otherLogin"; +import { Encrypt } from "../../common/Env"; function Register(props){ const {form, mygetHelmetapi} = props; @@ -47,8 +48,8 @@ function Register(props){ values.agreement && axios.post(`/accounts/register.json`, { login: values.email, namespace: values.register_username.trim(), - password: values.register_psd, - password_confirmation: values.psdComfirm, + password: Encrypt(values.register_psd), + password_confirmation: Encrypt(values.psdComfirm), code: values.captcha }).then((response)=>{ if(response.data && response.data.status === -6){ diff --git a/src/modules/loginRegister/ResetPassword.jsx b/src/modules/loginRegister/ResetPassword.jsx index 82cb1c97e..1ffda9d4d 100644 --- a/src/modules/loginRegister/ResetPassword.jsx +++ b/src/modules/loginRegister/ResetPassword.jsx @@ -33,8 +33,8 @@ function ResetPassword(props) { if (!err) { axios.post(`/accounts/reset_password.json`, { login: values.email, - password: values.psd, - password_confirmation: values.psdComfirm, + password: Encrypt(values.psd), + password_confirmation: Encrypt(values.psdComfirm), code: values.captcha, }).then((response) => { if (response.data.status === 0) { diff --git a/src/modules/user/FindPasswordComponent.js b/src/modules/user/FindPasswordComponent.js index c753c66e8..0669386ee 100644 --- a/src/modules/user/FindPasswordComponent.js +++ b/src/modules/user/FindPasswordComponent.js @@ -6,7 +6,7 @@ import {setmiyah} from 'educoder'; import CheckInputysl1 from './CheckInputysl'; import CheckInputysl2 from './CheckInputysl'; import {Tabs, Input, Checkbox, Button, notification} from 'antd'; - +import { Encrypt } from '../../common/Env'; import ReadPassword from './ReadPassword'; @@ -262,8 +262,8 @@ class LoginRegisterComponent extends Component { axios.post(url, { login: this.state.login, code: this.state.codes, - new_password: this.state.password, - new_password_confirmation: this.state.passwords, + new_password: Encrypt(this.state.password), + new_password_confirmation: Encrypt(this.state.passwords), }).then((result) => { // console.log(result); //登录成功,会生成session