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) {
if(handleSSO(user)){
return
}
if(user.active) {
yield put(routerRedux.replace("/profiles")) yield put(routerRedux.replace("/profiles"))
// message.info("登录成功") // message.info("登录成功")
} else { } else {
yield put(routerRedux.replace(`/verify`)) 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) {
if(handleSSO(user)){
return
}
if(data.active) { if(data.active) {
// yield put(routerRedux.replace("/profiles")) 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()
try {
let token = yield select(state => state.user.token) let token = yield select(state => state.user.token)
let { messages } = yield select(state => state.common) let { messages } = yield select(state => state.common)
try {
let { data } = yield call(updateProfile, {...payload, token}) let { data } = yield call(updateProfile, {...payload, token})
...@@ -165,10 +186,16 @@ export default { ...@@ -165,10 +186,16 @@ 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")
} }
}) })
} }
......
...@@ -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>
<Route path="/activate" component={Active}/> <Route path="/activate" component={Active}/>
<Route path="/verify" component={Verify} /> <Route path="/verify" component={Verify} />
</Route>
</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;
function Index({ children, messages }) {
return ( const particleConfig = {
<div style={{ height: '100%' }}>
<DocumentTitle title={messages['title'] || 'Moe Cube'}>
<Particles
params={{
'particles': { 'particles': {
'number': { 'number': {
'value': 20, 'value': 20,
'density': { 'density': {
'enable': true, 'enable': true,
'value_area': 1000, 'value_area': 1000
}, }
}, },
'color': { 'color': {
'value': '#888', 'value': '#888',
'opacity': 0.4, 'opacity': 0.4
}, },
'shape': { 'shape': {
'type': 'circle', 'type': 'circle',
'stroke': { 'stroke': {
'width': 4, 'width': 4,
'color': '#888', 'color': '#888',
'opacity': 0.4, 'opacity': 0.4
}, },
'polygon': { 'polygon': {
'nb_sides': 5, 'nb_sides': 5
}, },
'image': { 'image': {
'src': 'img/github.svg', 'src': 'img/github.svg',
'width': 100, 'width': 100,
'height': 100, 'height': 100
}, }
}, },
'opacity': { 'opacity': {
'value': 0.5, 'value': 0.5,
...@@ -44,8 +45,8 @@ function Index({ children, messages }) { ...@@ -44,8 +45,8 @@ function Index({ children, messages }) {
'enable': false, 'enable': false,
'speed': 1, 'speed': 1,
'opacity_min': 0.1, 'opacity_min': 0.1,
'sync': false, 'sync': false
}, }
}, },
'size': { 'size': {
'value': 3, 'value': 3,
...@@ -54,15 +55,15 @@ function Index({ children, messages }) { ...@@ -54,15 +55,15 @@ function Index({ children, messages }) {
'enable': false, 'enable': false,
'speed': 1, 'speed': 1,
'size_min': 0.1, 'size_min': 0.1,
'sync': false, 'sync': false
}, }
}, },
'line_linked': { 'line_linked': {
'enable': true, 'enable': true,
'distance': 150, 'distance': 150,
'color': '#888', 'color': '#888',
'opacity': 0.4, 'opacity': 0.4,
'width': 1, 'width': 1
}, },
'move': { 'move': {
'enable': true, 'enable': true,
...@@ -75,9 +76,9 @@ function Index({ children, messages }) { ...@@ -75,9 +76,9 @@ function Index({ children, messages }) {
'attract': { 'attract': {
'enable': false, 'enable': false,
'rotateX': 600, 'rotateX': 600,
'rotateY': 1200, 'rotateY': 1200
}, }
}, }
}, },
'interactivity': { 'interactivity': {
'detect_on': 'canvas', 'detect_on': 'canvas',
...@@ -85,58 +86,87 @@ function Index({ children, messages }) { ...@@ -85,58 +86,87 @@ function Index({ children, messages }) {
'onhover': { 'onhover': {
'enable': true, 'enable': true,
'mode': 'grab', 'mode': 'grab',
'nb': 2, 'nb': 2
}, },
'onclick': { 'onclick': {
'enable': true, 'enable': true,
'mode': 'push', 'mode': 'push'
}, },
'resize': true, 'resize': true
}, },
'modes': { 'modes': {
'grab': { 'grab': {
'distance': 400, 'distance': 400,
'line_linked': { 'line_linked': {
'opacity': 0.4, 'opacity': 0.4
}, }
}, },
'bubble': { 'bubble': {
'distance': 400, 'distance': 400,
'size': 20, 'size': 20,
'duration': 2, 'duration': 2,
'opacity': 8, 'opacity': 8,
'speed': 1, 'speed': 1
}, },
'repulse': { 'repulse': {
'distance': 200, 'distance': 200,
'duration': 0.4, 'duration': 0.4
}, },
'push': { 'push': {
'particles_nb': 4, 'particles_nb': 4
}, },
'remove': { 'remove': {
'particles_nb': 2, 'particles_nb': 2
}, }
}, }
}, },
'retina_detect': true, 'retina_detect': true
}} }
function Index({ dispatch, children, messages }) {
return (
<div style={{ height: "100%" }}>
<DocumentTitle title={messages['title'] || 'Moe Cube'} />
<Header style={{ display: 'flex', alignItems: 'center'}}>
<Link to="/home" style={{ marginTop: '20px'}}>
<img src={logo} style={{ width: '140px', height: '44px'}}/>
</Link>
<Menu
theme="dark"
mode="horizontal"
defaultSelectedKeys={['1']}
style={{ lineHeight: '64px' }}>
<Menu.Item key="1">
<Link to="/home">
Home
</Link>
</Menu.Item>
</Menu>
</Header>
<Particles
params={particleConfig}
style={{ style={{
position: 'fixed', position: "fixed"
}} }}
/> />
</DocumentTitle>
{children} {children}
<Footer style={{ position: 'absolute', width: '100%', bottom: 0, left: 0, display: 'flex', justifyContent: 'space-between' }}>
<div>© MoeCube 2017 all right reserved.</div>
</Footer>
</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 diff is collapsed.
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