Commit 4279404f by zhanghaozhe

无痕验证

parent b8bf2733
import React, { Component } from 'react' import React, {Component} from 'react'
import Routes from './router' import Routes from './router'
import cookie from 'js-cookie' import cookie from 'js-cookie'
import { connect } from 'react-redux' import {connect} from 'react-redux'
import { setCurrentUser, startFetchUser } from '@/store/userAction' import {setCurrentUser, startFetchUser, endFetchUser} from '@/store/userAction'
import { import {
updateCaptchaState, updateCaptchaState,
closeCaptchaModal, closeCaptchaModal,
showCaptchaModal, showCaptchaModal,
validationPassed, validationPassed,
startFetchValidationState,
endFetchValidationState,
} from '@/store/no-trace-validation/reducer' } from '@/store/no-trace-validation/reducer'
import { initialState } from '@/store/userReducer' import {initialState} from '@/store/userReducer'
import { withRouter } from 'react-router-dom' import {withRouter} from 'react-router-dom'
import { compose } from 'redux' import {compose} from 'redux'
import { getParam, http, browser, loadScript, getTimestamp } from '@/utils' import {getParam, http, browser, loadScript, getTimestamp} from '@/utils'
import { Toast } from 'antd-mobile' import {Toast} from 'antd-mobile'
import { addDays } from 'date-fns' import {addDays} from 'date-fns'
import stringify from 'json-stringify-safe' import stringify from 'json-stringify-safe'
//拦截ajax请求,返回mock数据 //拦截ajax请求,返回mock数据
...@@ -189,7 +191,6 @@ class App extends Component { ...@@ -189,7 +191,6 @@ class App extends Component {
} : (location.state = {records: this.records}) } : (location.state = {records: this.records})
} }
utm = () => { utm = () => {
// utm统计 m站全站统计广告投放、以及统计详情页浏览 // utm统计 m站全站统计广告投放、以及统计详情页浏览
let zhihu_cb = getParam('cb') let zhihu_cb = getParam('cb')
...@@ -214,19 +215,25 @@ class App extends Component { ...@@ -214,19 +215,25 @@ class App extends Component {
let code = getParam('code') let code = getParam('code')
let oid = getParam('oid') let oid = getParam('oid')
if (code && !oid) { if (code && !oid) {
this.props.startFetchValidationState()
http.get(`${API['passport-api']}/m/wx_loginInfo/code/${code}?redirect=${encodeURIComponent(window.location.href)}`) http.get(`${API['passport-api']}/m/wx_loginInfo/code/${code}?redirect=${encodeURIComponent(window.location.href)}`)
.then(res => { .then(res => {
let data = res.data let data = res.data
if (data.errno == 200) { if (data.errno == 200) {
if (data.data.is_check) { if (data.data.is_check) {
this.props.updateCaptchaState({ this.props.updateCaptchaState({
isNeedValidation: true isNeedValidation: true,
}) })
this.props.startFetchValidationState()
this.setState({ this.setState({
mkey: data.data.mkey, mkey: data.data.mkey,
}); });
this.setupNoTraceValidate() this.setupNoTraceValidate()
} else { } else {
this.props.updateCaptchaState({
isNeedValidation: false,
isFetching: false
})
if (data.data['is_bind_mobile']) { if (data.data['is_bind_mobile']) {
window.location.assign(data.data.url) window.location.assign(data.data.url)
} else { } else {
...@@ -234,6 +241,10 @@ class App extends Component { ...@@ -234,6 +241,10 @@ class App extends Component {
} }
} }
} else { } else {
this.props.updateCaptchaState({
isNeedValidation: false,
isFetching: false
})
Toast.info(data.msg) Toast.info(data.msg)
this.props.setCurrentUser(initialState) this.props.setCurrentUser(initialState)
} }
...@@ -304,14 +315,11 @@ class App extends Component { ...@@ -304,14 +315,11 @@ class App extends Component {
}).then(res => { }).then(res => {
const {errno, msg, data} = res.data const {errno, msg, data} = res.data
if (errno === 200) { if (errno === 200) {
this.props.validationPassed() this.props.validationPassed()
this.handleLoginResponse(data) this.handleLoginResponse(data)
} else if (errno === 5002) { } else if (errno === 5002) {
this.props.updateCaptchaState({ this.props.showCaptchaModal()
isShowCaptcha: true this.props.endFetchValidationState()
})
typeof nvcReset === 'function' && nvcReset() typeof nvcReset === 'function' && nvcReset()
typeof getNC === 'function' && getNC().then(() => { typeof getNC === 'function' && getNC().then(() => {
_nvc_nc.reset() _nvc_nc.reset()
...@@ -319,6 +327,8 @@ class App extends Component { ...@@ -319,6 +327,8 @@ class App extends Component {
} else { } else {
Toast.info(msg) Toast.info(msg)
} }
this.props.endFetchUser()
this.props.endFetchValidationState()
}) })
} }
...@@ -459,6 +469,9 @@ export default compose( ...@@ -459,6 +469,9 @@ export default compose(
closeCaptchaModal, closeCaptchaModal,
showCaptchaModal, showCaptchaModal,
validationPassed, validationPassed,
endFetchUser,
startFetchValidationState,
endFetchValidationState,
}), }),
withRouter, withRouter,
)(App) )(App)
import React, { Component } from 'react'; import React, {Component} from 'react';
import './index.scss' import './index.scss'
import { connect } from "react-redux"; import {connect} from "react-redux";
import { compose } from "redux"; import {compose} from "redux";
import { HeaderBar } from "@common/index" import {HeaderBar} from "@common/index"
import { getParam, http, browser, wxShare } from "@/utils" import {getParam, http, browser, wxShare} from "@/utils"
import { Toast } from "antd-mobile"; import {Toast} from "antd-mobile";
import { CopyToClipboard } from "react-copy-to-clipboard"; import {CopyToClipboard} from "react-copy-to-clipboard";
import { Link } from 'react-router-dom' import {Link} from 'react-router-dom'
import storage from 'store2' import storage from 'store2'
import { CaptchaAli } from "@common/index" import {CaptchaAli} from "@common/index"
import { showCaptchaModal } from "@/store/no-trace-validation/reducer"; import {showCaptchaModal} from "@/store/no-trace-validation/reducer";
class Invitation extends Component { class Invitation extends Component {
...@@ -96,11 +96,15 @@ class Invitation extends Component { ...@@ -96,11 +96,15 @@ class Invitation extends Component {
joinTeam = data => { joinTeam = data => {
const {user, history, noTraceValidation, showCaptchaModal} = this.props const {user, history, noTraceValidation, showCaptchaModal} = this.props
if(user.isFetching){ if (noTraceValidation.isFetching) {
return return
} }
if (noTraceValidation.isNeedValidation && !noTraceValidation.isShowCaptcha) { if (noTraceValidation.isNeedValidation) {
showCaptchaModal() !noTraceValidation.isShowCaptcha && showCaptchaModal()
return
}
if (user.isFetching) {
return return
} }
......
...@@ -27,9 +27,20 @@ export const validationPassed = () => { ...@@ -27,9 +27,20 @@ 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 = { const initialState = {
isShowCaptcha: false, isShowCaptcha: false,
isNeedValidation: false, isNeedValidation: false,
isFetching: false,
} }
export default function noTraceValidation(state = initialState, action) { export default function noTraceValidation(state = initialState, action) {
...@@ -49,10 +60,21 @@ export default function noTraceValidation(state = initialState, action) { ...@@ -49,10 +60,21 @@ export default function noTraceValidation(state = initialState, action) {
...state, ...state,
...{isShowCaptcha: false}, ...{isShowCaptcha: false},
} }
case START_FETCHING:
return {
...state,
isFetching: true,
}
case VALIDATION_PASSED: case VALIDATION_PASSED:
return { return {
isNeedValidation: false, isNeedValidation: false,
isShowCaptcha: false, isShowCaptcha: false,
isFetching: false,
}
case END_FETCHING:
return {
...state,
isFetching: false,
} }
default: default:
return state return state
......
import { http } from '@/utils'; import {http} from '@/utils';
import { encrypt } from '@/components/passport/encryption'; import {encrypt} from '@/components/passport/encryption';
import jsCookie from 'js-cookie' import jsCookie from 'js-cookie'
const accountLogin = user => dispatch => { const accountLogin = user => dispatch => {
return http.post(`${API['passport-api']}/m/login/accountLogin`, { return http.post(`${API['passport-api']}/m/login/accountLogin`, {
user_name: user.username, user_name: user.username,
password: encrypt(user.password), password: encrypt(user.password),
is_encrypt: 1, is_encrypt: 1,
redirect: encodeURIComponent(user.redirect) redirect: encodeURIComponent(user.redirect),
}).then(res => { }).then(res => {
return storeUser(res, dispatch) return storeUser(res, dispatch)
}) })
} }
const studentLogin = params => dispatch => { const studentLogin = params => dispatch => {
return http.post(`${API['passport-api']}/phone_reg`, { return http.post(`${API['passport-api']}/phone_reg`, {
phone: params.tel, phone: params.tel,
password: params.password, password: params.password,
code: params.code, code: params.code,
area_code: params.num, area_code: params.num,
school_name: params.school, school_name: params.school,
college_name: params.college, college_name: params.college,
student_id: params.uid, student_id: params.uid,
student_name: params.name, student_name: params.name,
redirect: encodeURIComponent(params.redirect), redirect: encodeURIComponent(params.redirect),
type: 1, type: 1,
}).then(res => { }).then(res => {
const { errno, data } = res.data; const {errno, data} = res.data;
let result = {}; let result = {};
if(errno === 0) { if (errno === 0) {
result = { result = {
data: { data: {
errno: 200, errno: 200,
data, data,
} },
}; };
}else { } else {
result = res; result = res;
} }
return storeUser(result, dispatch); return storeUser(result, dispatch);
}); });
} }
const quickLogin = user => dispatch => { const quickLogin = user => dispatch => {
return http.post(`${API['passport-api']}/m/login/quickLogin`, { return http.post(`${API['passport-api']}/m/login/quickLogin`, {
...user, ...user,
plat: 5 plat: 5,
}).then(res => { }).then(res => {
return storeUser(res, dispatch) return storeUser(res, dispatch)
}) })
} }
const storeUser = (res, dispatch) => { const storeUser = (res, dispatch) => {
const data = res.data const data = res.data
let payload let payload
if (data.errno === 200) { if (data.errno === 200) {
const {user_name: username, avatar_file: avatar,is_vip: isVIP, ...rest} = data.data.user_info const {user_name: username, avatar_file: avatar, is_vip: isVIP, ...rest} = data.data.user_info
payload = { payload = {
hasError: false, hasError: false,
msg: data.msg, msg: data.msg,
data: {username, avatar,isVIP, ...rest} data: {username, avatar, isVIP, ...rest},
}
} else {
payload = {
hasError: true,
msg: data.msg,
data: {},
code: data.errno
}
} }
dispatch(setCurrentUser(payload)) } else {
return payload payload = {
hasError: true,
msg: data.msg,
data: {},
code: data.errno,
}
}
dispatch(setCurrentUser(payload))
return payload
} }
const SET_CURRENT_USER = 'SET_CURRENT_USER' const SET_CURRENT_USER = 'SET_CURRENT_USER'
const setCurrentUser = payload => ({ const setCurrentUser = payload => ({
type: SET_CURRENT_USER, type: SET_CURRENT_USER,
payload: {...payload, isFetching: false} payload: {...payload, isFetching: false},
}) })
const LOGOUT = 'LOGOUT' const LOGOUT = 'LOGOUT'
const logout = () => dispatch => { const logout = () => dispatch => {
jsCookie.remove('token', {path: '/', domain: '.julyedu.com'}) jsCookie.remove('token', {path: '/', domain: '.julyedu.com'})
jsCookie.remove('uid', {path: '/', domain: '.julyedu.com'}) jsCookie.remove('uid', {path: '/', domain: '.julyedu.com'})
dispatch(setCurrentUser({hasError: true})) dispatch(setCurrentUser({hasError: true}))
} }
const UPDATE_USER = 'UPDATE_USER' const UPDATE_USER = 'UPDATE_USER'
const updateUser = payload => ({ const updateUser = payload => ({
type: UPDATE_USER, type: UPDATE_USER,
payload payload,
}) })
const START_FETCH_USER = 'START_FETCH_USER' const START_FETCH_USER = 'START_FETCH_USER'
const startFetchUser = () => ({ const startFetchUser = () => ({
type: START_FETCH_USER type: START_FETCH_USER,
})
const END_FETCH_USER = 'END_FETCH_USER'
const endFetchUser = () => ({
type: END_FETCH_USER,
}) })
export { export {
accountLogin, accountLogin,
studentLogin, studentLogin,
SET_CURRENT_USER, SET_CURRENT_USER,
setCurrentUser, setCurrentUser,
quickLogin, quickLogin,
logout, logout,
UPDATE_USER, UPDATE_USER,
updateUser, updateUser,
START_FETCH_USER, START_FETCH_USER,
startFetchUser, startFetchUser,
END_FETCH_USER,
endFetchUser,
} }
import { SET_CURRENT_USER, UPDATE_USER, START_FETCH_USER } from '@/store/userAction'; import {SET_CURRENT_USER, UPDATE_USER, START_FETCH_USER, END_FETCH_USER} from '@/store/userAction';
import { merge } from 'lodash' import {merge} from 'lodash'
const notLoggedIn = 4030 const notLoggedIn = 4030
export const initialState = { export const initialState = {
hasError: true, hasError: true,
code: notLoggedIn, code: notLoggedIn,
msg: '', msg: '',
data: { data: {
username: '', username: '',
avatar: '', avatar: '',
isVip: false, isVip: false,
token: '', token: '',
email: '', email: '',
uid: '' uid: '',
}, },
isFetching: true isFetching: true,
} }
export default function (state = initialState, action) { export default function (state = initialState, action) {
switch (action.type) { switch (action.type) {
case SET_CURRENT_USER: case SET_CURRENT_USER:
return action.payload return action.payload
case UPDATE_USER: case UPDATE_USER:
return merge({}, state, action.payload) return merge({}, state, action.payload)
case START_FETCH_USER: case START_FETCH_USER:
return {...state, isFetching: true} return {...state, isFetching: true}
default: case END_FETCH_USER:
return state 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