Commit 05f04b42 by zhanghaozhe

微信登录无痕验证

parent 4279404f
import React, {Component} from 'react'
import React, { Component } from 'react'
import Routes from './router'
import cookie from 'js-cookie'
import {connect} from 'react-redux'
import {setCurrentUser, startFetchUser, endFetchUser} from '@/store/userAction'
import { connect } from 'react-redux'
import { setCurrentUser, startFetchUser, endFetchUser } from '@/store/userAction'
import {
updateCaptchaState,
closeCaptchaModal,
showCaptchaModal,
validationPassed,
startFetchValidationState,
endFetchValidationState,
} from '@/store/no-trace-validation/reducer'
import {initialState} from '@/store/userReducer'
import {withRouter} from 'react-router-dom'
import {compose} from 'redux'
import {getParam, http, browser, loadScript, getTimestamp} from '@/utils'
import {Toast} from 'antd-mobile'
import {addDays} from 'date-fns'
import { initialState } from '@/store/userReducer'
import { withRouter } from 'react-router-dom'
import { compose } from 'redux'
import { getParam, http, browser, loadScript, getTimestamp } from '@/utils'
import { Toast } from 'antd-mobile'
import { addDays } from 'date-fns'
import stringify from 'json-stringify-safe'
//拦截ajax请求,返回mock数据
......@@ -118,18 +116,21 @@ class App extends Component {
componentDidUpdate(prevProps, prevState) {
this.setPreviousLocation()
if (!this.props.user.hasError && getParam('redirect')) {
const {user, noTraceValidation: {isShowCaptcha}} = this.props
if (!user.hasError && getParam('redirect')) {
window.location.href = decodeURIComponent(getParam('redirect'))
}
const {noTraceValidation: {isShowCaptcha}} = this.props
if (prevProps.noTraceValidation.isShowCaptcha !== isShowCaptcha && isShowCaptcha) {
typeof nvcReset === 'function' && nvcReset()
typeof getNC === 'function' && getNC().then(() => {
_nvc_nc.reset()
})
}
if (prevProps.user.isFetching !== user.isFetching && !user.isFetching) {
document.body.style.pointerEvents = 'auto'
}
}
// 获取宝箱阶段
......@@ -208,6 +209,7 @@ class App extends Component {
}
getUser = () => {
document.body.style.pointerEvents = 'none'
//获取用户信息
this.props.startFetchUser()
......@@ -215,7 +217,6 @@ class App extends Component {
let code = getParam('code')
let oid = getParam('oid')
if (code && !oid) {
this.props.startFetchValidationState()
http.get(`${API['passport-api']}/m/wx_loginInfo/code/${code}?redirect=${encodeURIComponent(window.location.href)}`)
.then(res => {
let data = res.data
......@@ -224,7 +225,6 @@ class App extends Component {
this.props.updateCaptchaState({
isNeedValidation: true,
})
this.props.startFetchValidationState()
this.setState({
mkey: data.data.mkey,
});
......@@ -232,7 +232,7 @@ class App extends Component {
} else {
this.props.updateCaptchaState({
isNeedValidation: false,
isFetching: false
isFetching: false,
})
if (data.data['is_bind_mobile']) {
window.location.assign(data.data.url)
......@@ -243,7 +243,7 @@ class App extends Component {
} else {
this.props.updateCaptchaState({
isNeedValidation: false,
isFetching: false
isFetching: false,
})
Toast.info(data.msg)
this.props.setCurrentUser(initialState)
......@@ -319,7 +319,6 @@ class App extends Component {
this.handleLoginResponse(data)
} else if (errno === 5002) {
this.props.showCaptchaModal()
this.props.endFetchValidationState()
typeof nvcReset === 'function' && nvcReset()
typeof getNC === 'function' && getNC().then(() => {
_nvc_nc.reset()
......@@ -328,7 +327,6 @@ class App extends Component {
Toast.info(msg)
}
this.props.endFetchUser()
this.props.endFetchValidationState()
})
}
......@@ -470,8 +468,6 @@ export default compose(
showCaptchaModal,
validationPassed,
endFetchUser,
startFetchValidationState,
endFetchValidationState,
}),
withRouter,
)(App)
......@@ -96,9 +96,6 @@ class Invitation extends Component {
joinTeam = data => {
const {user, history, noTraceValidation, showCaptchaModal} = this.props
if (noTraceValidation.isFetching) {
return
}
if (noTraceValidation.isNeedValidation) {
!noTraceValidation.isShowCaptcha && showCaptchaModal()
return
......
......@@ -27,20 +27,9 @@ export const validationPassed = () => {
}
}
const START_FETCHING = 'START_FETCHING'
export const startFetchValidationState = () => ({
type: START_FETCHING,
})
const END_FETCHING = 'END_FETCHING'
export const endFetchValidationState = () => ({
type: END_FETCHING,
})
const initialState = {
isShowCaptcha: false,
isNeedValidation: false,
isFetching: false,
}
export default function noTraceValidation(state = initialState, action) {
......@@ -60,22 +49,12 @@ export default function noTraceValidation(state = initialState, action) {
...state,
...{isShowCaptcha: false},
}
case START_FETCHING:
return {
...state,
isFetching: true,
}
case VALIDATION_PASSED:
return {
isNeedValidation: false,
isShowCaptcha: false,
isFetching: false,
}
case END_FETCHING:
return {
...state,
isFetching: false,
}
default:
return state
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment