Commit e46a84f3 authored by nano's avatar nano

complete

parent 4356914e
{
"private": true,
"scripts": {
"start": "roadhog server",
"start": "PORT=8081 roadhog server",
"build": "roadhog build",
"lint": "eslint --ext .js src test",
"precommit": "npm run lint"
......@@ -22,7 +22,8 @@
"react-dom": "^15.4.0",
"react-image-crop": "^2.0.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": {
"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 {
apiRoot: 'http://192.168.1.9:3000',
returnSSO: 'http://localhost:8000/',
SSOProvider: 'https://ygobbs.com/session/sso_provider'
};
import { message } from 'antd';
import { routerRedux } from 'dva/router';
import { activate, checkUserExists, forgot, login, register, reset } from '../services/auth';
import { login, forgot, register, reset, activate, checkUserExists } from '../services/auth'
import { message } from 'antd'
import { routerRedux } from 'dva/router'
import config from '../config'
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 {
}
},
},
subscriptions: {},
subscriptions: {
},
};
......@@ -2,6 +2,7 @@ import { routerRedux } from 'dva/router'
import { updateProfile, updateAccount } from '../services/user'
import { getAuthUser } from '../services/auth'
import { message } from 'antd'
import { handleSSO } from '../utils/sso'
......@@ -89,6 +90,7 @@ export default {
localStorage.setItem("token", token)
}
<<<<<<< Updated upstream
if(user && user.active) {
yield put(routerRedux.replace("/profiles"))
// message.info("登录成功")
......@@ -96,28 +98,70 @@ export default {
yield put(routerRedux.replace(`/verify`))
}
=======
if(user) {
if(handleSSO(user)){
return
}
if(user.active) {
yield put(routerRedux.replace("/profiles"))
// message.info("登录成功")
} else {
yield put(routerRedux.replace(`/verify`))
}
}
>>>>>>> Stashed changes
},
*preLogin({ payload }, { call, put }) {
let token = localStorage.getItem("token")
const {token } = payload
if(!token) {
yield put(routerRedux.replace("/signin"))
}
try {
let { data } = yield call(getAuthUser, { token })
if (data ) {
yield put({ type: 'preLoginSuccess', payload: { user: data, token }})
<<<<<<< Updated upstream
if(data.active) {
// yield put(routerRedux.replace("/profiles"))
}
}
} catch (error) {
message.error(error.message)
=======
if(data) {
if(handleSSO(user)){
return
}
if(data.active) {
yield put(routerRedux.replace("/profiles"))
}else {
yield put(routerRedux.replace("/verify"))
}
}
}
} catch (error) {
yield put(routerRedux.replace("/signin"))
>>>>>>> Stashed changes
}
},
*updateProfile({ payload }, { call, put, select }) {
message.destroy()
let token = yield select(state => state.user.token)
let { messages } = yield select(state => state.common)
try {
<<<<<<< Updated upstream
let token = yield select(state => state.user.token)
let { messages } = yield select(state => state.common)
=======
>>>>>>> Stashed changes
let { data } = yield call(updateProfile, {...payload, token})
......@@ -165,10 +209,21 @@ export default {
},
subscriptions: {
setup({ dispatch, history }) {
let token = localStorage.getItem("token")
if(window.location.pathname != '/signin') {
dispatch({ type: 'preLogin', payload: { token } })
}
history.listen((a) => {
console.log(a)
})
return history.listen(({ pathname, query }) => {
if (pathname == '/profiles') {
console.log(pathname, query)
dispatch({ type: 'preLogin', payload: query })
if(pathname == 'profiles' && !token) {
history.push("/signin")
}
})
}
......
......@@ -21,16 +21,16 @@ import Index from "./routes/Index.js";
function RouterConfig({ history }) {
return (
<Router history={history}>
<Redirect from="/" to="/signin"/>
<Route path="/" component={Index} >
<Redirect from="/home" to="/profiles" />
<Route path="/signin" component={Login}/>
<Route path="/forgot" component={Forgot}/>
<Route path="/signup" component={Register}/>
<Route path="/reset" component={Reset}/>
<Route path="/profiles" component={Profiles}/>
</Route>
<Route path="/activate" component={Active}/>
<Route path="/verify" component={Verify} />
</Route>
</Router>
);
}
......
......@@ -3,13 +3,13 @@ import { connect } from 'dva';
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 (
<div style={{ height: "100%" }}>
<DocumentTitle title={messages['title'] || 'Moe Cube'}>
<Particles
params={{
const particleConfig = {
'particles': {
'number': {
'value': 20,
......@@ -121,20 +121,49 @@ function Index({ children, messages }) {
}
},
'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
</Link>
</Menu.Item>
</Menu>
</Header>
<Particles
params={particleConfig}
style={{
position: "fixed"
}}
/>
</DocumentTitle>
{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>
);
}
function mapStateToProps(state) {
const {
common: {messages}
common: { messages }
} = state
return {
messages
......
......@@ -38,9 +38,7 @@ class Login extends React.Component {
return (
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '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">
<FormItem>
{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) => {
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
}
\ No newline at end of file
......@@ -5418,6 +5418,10 @@ unpipe@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
url-api-polyfill@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/url-api-polyfill/-/url-api-polyfill-1.1.0.tgz#a99fa3e110c1fbe1dbf9bb2a2427254b0fd2235f"
url-loader@^0.5.7:
version "0.5.8"
resolved "https://registry.yarnpkg.com/url-loader/-/url-loader-0.5.8.tgz#b9183b1801e0f847718673673040bc9dc1c715c5"
......
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