mirror of
https://github.com/zuiidea/antd-admin
synced 2026-10-20 22:43:43 +00:00
login
This commit is contained in:
+15
-1
@@ -29,13 +29,27 @@ Watch.watch(adminUsersData, function () {
|
||||
|
||||
module.exports = {
|
||||
'POST /api/login' (req, res) {
|
||||
const userItem = req.body
|
||||
const d = adminUsersData.filter(function (item) {
|
||||
return item.username==userItem.username
|
||||
})
|
||||
if(!!d.length){
|
||||
if(d[0].password==userItem.password){
|
||||
|
||||
}else {
|
||||
|
||||
}
|
||||
}else {
|
||||
|
||||
}
|
||||
const now = new Date()
|
||||
now.setDate(now.getDate()+1)
|
||||
Cookie.set('user_session', now.getTime())
|
||||
Cookie.set('user_name', userItem.username)
|
||||
res.json({success: true})
|
||||
},
|
||||
|
||||
'GET /api/userInfo' (req, res) {
|
||||
res.json({success: true})
|
||||
res.json({success: true,username:"吴彦祖"})
|
||||
},
|
||||
}
|
||||
|
||||
+20
-4
@@ -2,8 +2,6 @@ import {login, userInfo} from '../services/app'
|
||||
import {parse} from 'qs'
|
||||
import Cookie from 'js-cookie'
|
||||
|
||||
console.log(Cookie.get('user_session'));
|
||||
|
||||
export default {
|
||||
namespace : 'app',
|
||||
state : {
|
||||
@@ -11,30 +9,48 @@ export default {
|
||||
? true
|
||||
: false,
|
||||
loading: false,
|
||||
user:{
|
||||
name:"吴彦祖",
|
||||
},
|
||||
loginButtonLoading: false
|
||||
},
|
||||
effects : {
|
||||
*login({
|
||||
payload
|
||||
}, {call, put}) {
|
||||
yield put({type: 'showButtonLoading'})
|
||||
yield put({type: 'showLoginButtonLoading'})
|
||||
const data = yield call(login, parse(payload))
|
||||
if (data) {
|
||||
yield put({type: 'loginSuccess', payload: {
|
||||
data
|
||||
}})
|
||||
}
|
||||
},
|
||||
*userInfo({
|
||||
payload
|
||||
}, {call, put}) {
|
||||
yield put({type: 'showLoading'})
|
||||
const data = yield call(login, parse(payload))
|
||||
if (data) {
|
||||
console.log(data);
|
||||
}
|
||||
}
|
||||
},
|
||||
reducers : {
|
||||
loginSuccess(state) {
|
||||
return {login: true, loading: false, loginButtonLoading: false}
|
||||
},
|
||||
showLoading(state) {
|
||||
showLoginButtonLoading(state) {
|
||||
return {
|
||||
...state,
|
||||
loginButtonLoading: true
|
||||
}
|
||||
},
|
||||
showLoading(state) {
|
||||
return {
|
||||
...state,
|
||||
loading: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user