Commit f7bfe813 authored by 2breakegg's avatar 2breakegg

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/routes/Index.js
#	yarn.lock
parents 10470369 d8e3bbe7
...@@ -22,7 +22,8 @@ ...@@ -22,7 +22,8 @@
"react-dom": "^15.4.0", "react-dom": "^15.4.0",
"react-image-crop": "^2.0.3", "react-image-crop": "^2.0.3",
"react-intl": "^2.2.3", "react-intl": "^2.2.3",
"react-particles-js": "^1.5.0" "react-particles-js": "^1.5.0",
"url-api-polyfill": "^1.1.0"
}, },
"devDependencies": { "devDependencies": {
"babel-eslint": "^7.1.1", "babel-eslint": "^7.1.1",
......
src/assets/MoeCube.png

95 KB | W: | H:

src/assets/MoeCube.png

68.9 KB | W: | H:

src/assets/MoeCube.png
src/assets/MoeCube.png
src/assets/MoeCube.png
src/assets/MoeCube.png
  • 2-up
  • Swipe
  • Onion skin
export default { export default {
apiRoot: 'http://192.168.1.9:3000', apiRoot: 'http://192.168.1.9:3000'
}; };
import { message } from 'antd'; import { login, forgot, register, reset, activate, checkUserExists } from '../services/auth'
import { routerRedux } from 'dva/router'; import { message } from 'antd'
import { activate, checkUserExists, forgot, login, register, reset } from '../services/auth'; import { routerRedux } from 'dva/router'
import config from '../config'
export default { export default {
...@@ -238,5 +240,12 @@ export default { ...@@ -238,5 +240,12 @@ export default {
} }
}, },
}, },
subscriptions: {}, subscriptions: {
setup({ dispatch, history }) {
return history.listen(({ pathname, query }) => {
})
}
}
}; };
export default {
namespace: 'haha',
state: {
text: '123213213',
},
reducers: {
change(state, action) {
return {
...state, ...action.payload
};
},
},
effects: {},
subscriptions: {},
};
...@@ -48,5 +48,7 @@ export default { ...@@ -48,5 +48,7 @@ export default {
} }
}, },
}, },
subscriptions: {}, subscriptions: {
},
}; };
...@@ -2,6 +2,7 @@ import { routerRedux } from 'dva/router' ...@@ -2,6 +2,7 @@ import { routerRedux } from 'dva/router'
import { updateProfile, updateAccount } from '../services/user' import { updateProfile, updateAccount } from '../services/user'
import { getAuthUser } from '../services/auth' import { getAuthUser } from '../services/auth'
import { message } from 'antd' import { message } from 'antd'
import { handleSSO } from '../utils/sso'
...@@ -89,35 +90,55 @@ export default { ...@@ -89,35 +90,55 @@ export default {
localStorage.setItem("token", token) localStorage.setItem("token", token)
} }
if(user && user.active) { if(user) {
yield put(routerRedux.replace("/profiles")) if(handleSSO(user)){
// message.info("登录成功") return
} else { }
yield put(routerRedux.replace(`/verify`))
if(user.active) {
yield put(routerRedux.replace("/profiles"))
// message.info("登录成功")
} else {
yield put(routerRedux.replace(`/verify`))
}
} }
}, },
*preLogin({ payload }, { call, put }) { *preLogin({ payload }, { call, put }) {
let token = localStorage.getItem("token") const {token } = payload
if(!token) {
yield put(routerRedux.replace("/signin"))
}
try { try {
let { data } = yield call(getAuthUser, { token }) let { data } = yield call(getAuthUser, { token })
if (data ) { if (data ) {
yield put({ type: 'preLoginSuccess', payload: { user: data, token }}) yield put({ type: 'preLoginSuccess', payload: { user: data, token }})
if(data.active) {
// yield put(routerRedux.replace("/profiles")) if(data) {
} if(handleSSO(user)){
} return
}
if(data.active) {
yield put(routerRedux.replace("/profiles"))
}else {
yield put(routerRedux.replace("/verify"))
}
}
}
} catch (error) { } catch (error) {
message.error(error.message) yield put(routerRedux.replace("/signin"))
} }
}, },
*updateProfile({ payload }, { call, put, select }) { *updateProfile({ payload }, { call, put, select }) {
message.destroy() message.destroy()
let token = yield select(state => state.user.token)
let { messages } = yield select(state => state.common)
try { try {
let token = yield select(state => state.user.token)
let { messages } = yield select(state => state.common)
let { data } = yield call(updateProfile, {...payload, token}) let { data } = yield call(updateProfile, {...payload, token})
...@@ -165,12 +186,18 @@ export default { ...@@ -165,12 +186,18 @@ export default {
}, },
subscriptions: { subscriptions: {
setup({ dispatch, history }) { setup({ dispatch, history }) {
let token = localStorage.getItem("token")
return history.listen(({ pathname, query }) => { return history.listen(({ pathname, query }) => {
if (pathname == '/profiles') {
dispatch({ type: 'preLogin', payload: query }) if(pathname == '/' || pathname == 'profiles') {
dispatch({ type: 'preLogin', payload: { token } })
}
if(pathname == 'profiles' && !token) {
history.push("/signin")
} }
}) })
} }
}, },
}; };
\ No newline at end of file
...@@ -21,16 +21,16 @@ import Index from "./routes/Index.js"; ...@@ -21,16 +21,16 @@ import Index from "./routes/Index.js";
function RouterConfig({ history }) { function RouterConfig({ history }) {
return ( return (
<Router history={history}> <Router history={history}>
<Redirect from="/" to="/signin"/>
<Route path="/" component={Index} > <Route path="/" component={Index} >
<Redirect from="/home" to="/profiles" />
<Route path="/signin" component={Login}/> <Route path="/signin" component={Login}/>
<Route path="/forgot" component={Forgot}/> <Route path="/forgot" component={Forgot}/>
<Route path="/signup" component={Register}/> <Route path="/signup" component={Register}/>
<Route path="/reset" component={Reset}/> <Route path="/reset" component={Reset}/>
<Route path="/profiles" component={Profiles}/> <Route path="/profiles" component={Profiles}/>
<Route path="/activate" component={Active}/>
<Route path="/verify" component={Verify} />
</Route> </Route>
<Route path="/activate" component={Active}/>
<Route path="/verify" component={Verify} />
</Router> </Router>
); );
} }
......
import { connect } from 'dva';
import React from 'react'; import React from 'react';
import DocumentTitle from 'react-document-title'; import { connect } from 'dva';
import Particles from 'react-particles-js'; import styles from './Index.less';
import Particles from 'react-particles-js'
import DocumentTitle from 'react-document-title'
import { Layout, Button, Menu } from 'antd';
import { Link } from 'dva/router'
import logo from '../assets/MoeCube.png'
const { Header, Footer, Sider, Content } = Layout;
const particleConfig = {
'particles': {
'number': {
'value': 20,
'density': {
'enable': true,
'value_area': 1000
}
},
'color': {
'value': '#888',
'opacity': 0.4
},
'shape': {
'type': 'circle',
'stroke': {
'width': 4,
'color': '#888',
'opacity': 0.4
},
'polygon': {
'nb_sides': 5
},
'image': {
'src': 'img/github.svg',
'width': 100,
'height': 100
}
},
'opacity': {
'value': 0.5,
'random': false,
'anim': {
'enable': false,
'speed': 1,
'opacity_min': 0.1,
'sync': false
}
},
'size': {
'value': 3,
'random': true,
'anim': {
'enable': false,
'speed': 1,
'size_min': 0.1,
'sync': false
}
},
'line_linked': {
'enable': true,
'distance': 150,
'color': '#888',
'opacity': 0.4,
'width': 1
},
'move': {
'enable': true,
'speed': 1,
'direction': 'none',
'random': false,
'straight': false,
'out_mode': 'out',
'bounce': false,
'attract': {
'enable': false,
'rotateX': 600,
'rotateY': 1200
}
}
},
'interactivity': {
'detect_on': 'canvas',
'events': {
'onhover': {
'enable': true,
'mode': 'grab',
'nb': 2
},
'onclick': {
'enable': true,
'mode': 'push'
},
'resize': true
},
'modes': {
'grab': {
'distance': 400,
'line_linked': {
'opacity': 0.4
}
},
'bubble': {
'distance': 400,
'size': 20,
'duration': 2,
'opacity': 8,
'speed': 1
},
'repulse': {
'distance': 200,
'duration': 0.4
},
'push': {
'particles_nb': 4
},
'remove': {
'particles_nb': 2
}
}
},
'retina_detect': true
}
function Index({ children, messages }) { function Index({ dispatch, children, messages }) {
return ( return (
<div style={{ height: '100%' }}> <div style={{ height: "100%" }}>
<DocumentTitle title={messages['title'] || 'Moe Cube'}> <DocumentTitle title={messages['title'] || 'Moe Cube'} />
<Particles
params={{ <Header style={{ display: 'flex', alignItems: 'center'}}>
'particles': { <Link to="/home" style={{ marginTop: '20px'}}>
'number': { <img src={logo} style={{ width: '140px', height: '44px'}}/>
'value': 20, </Link>
'density': {
'enable': true, <Menu
'value_area': 1000, theme="dark"
}, mode="horizontal"
}, defaultSelectedKeys={['1']}
'color': { style={{ lineHeight: '64px' }}>
'value': '#888', <Menu.Item key="1">
'opacity': 0.4, <Link to="/home">
}, Home
'shape': { </Link>
'type': 'circle', </Menu.Item>
'stroke': { </Menu>
'width': 4, </Header>
'color': '#888',
'opacity': 0.4, <Particles
}, params={particleConfig}
'polygon': { style={{
'nb_sides': 5, position: "fixed"
}, }}
'image': { />
'src': 'img/github.svg', {children}
'width': 100,
'height': 100, <Footer style={{ position: 'absolute', width: '100%', bottom: 0, left: 0, display: 'flex', justifyContent: 'space-between' }}>
}, <div>© MoeCube 2017 all right reserved.</div>
}, </Footer>
'opacity': {
'value': 0.5,
'random': false,
'anim': {
'enable': false,
'speed': 1,
'opacity_min': 0.1,
'sync': false,
},
},
'size': {
'value': 3,
'random': true,
'anim': {
'enable': false,
'speed': 1,
'size_min': 0.1,
'sync': false,
},
},
'line_linked': {
'enable': true,
'distance': 150,
'color': '#888',
'opacity': 0.4,
'width': 1,
},
'move': {
'enable': true,
'speed': 1,
'direction': 'none',
'random': false,
'straight': false,
'out_mode': 'out',
'bounce': false,
'attract': {
'enable': false,
'rotateX': 600,
'rotateY': 1200,
},
},
},
'interactivity': {
'detect_on': 'canvas',
'events': {
'onhover': {
'enable': true,
'mode': 'grab',
'nb': 2,
},
'onclick': {
'enable': true,
'mode': 'push',
},
'resize': true,
},
'modes': {
'grab': {
'distance': 400,
'line_linked': {
'opacity': 0.4,
},
},
'bubble': {
'distance': 400,
'size': 20,
'duration': 2,
'opacity': 8,
'speed': 1,
},
'repulse': {
'distance': 200,
'duration': 0.4,
},
'push': {
'particles_nb': 4,
},
'remove': {
'particles_nb': 2,
},
},
},
'retina_detect': true,
}}
style={{
position: 'fixed',
}}
/>
</DocumentTitle>
{children}
</div> </div>
); );
} }
function mapStateToProps(state) { function mapStateToProps(state) {
const { const {
common: { messages }, common: { messages }
} = state; } = state
return { return {
messages, messages
}; };
} }
......
...@@ -38,9 +38,7 @@ class Login extends React.Component { ...@@ -38,9 +38,7 @@ class Login extends React.Component {
return ( return (
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '100%' }}> <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '100%' }}>
<Spin spinning={loading} delay={100}> <Spin spinning={loading} delay={100}>
<FormItem style={{display: 'flex', justifyContent:'center'}}>
<img src={logo} style={{height:'20vw', width: '20vw'}}/>
</FormItem>
<Form onSubmit={this.onSubmitLogin} className="login-form"> <Form onSubmit={this.onSubmitLogin} className="login-form">
<FormItem> <FormItem>
{getFieldDecorator('account', { {getFieldDecorator('account', {
......
import crypto from 'crypto'
import "url-api-polyfill";
const url = new URL(window.location)
let sso
let ssoString = url.searchParams.get('sso')
if (ssoString) {
sso = new URLSearchParams(Buffer.from(ssoString, 'base64').toString())
}
export const handleSSO = (user) => {
if(sso) {
let params = new URLSearchParams()
let url = new URL(sso.get("return_sso_url"));
for (let [key, value] of Object.entries(user)) {
params.set(key, value)
}
params.set("return_sso_url", sso.get("return_sso_url"))
params.set("nonce", sso.get("nonce"))
params.set("external_id", user.id)
let payload = Buffer.from(params.toString()).toString('base64')
url.searchParams.set("sso", payload)
url.searchParams.set('sig', crypto.createHmac('sha256', 'zsZv6LXHDwwtUAGa').update(payload).digest('hex'))
window.location.href = url
return true
}else {
return false
}
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
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