Commit 65f2b519 authored by caobo's avatar caobo

添加用户后台

parent 38f67391
const AuthName = 'l_q6KiRVG4200kwRXIwVfgY1yOIa';
const AuthPass = 'N11ztBU2lExdNOklH2AmX4JOzdIa';
export {
AuthName,
AuthPass
}
\ No newline at end of file
const router = require("express").Router();
const mongodb = require("mongodb");
const MongoClient = mongodb.MongoClient;
const axios = require("axios");
const moment = require('moment');
const jwt = require('jsonwebtoken');
let db = {};
const dbpath = process.env.MONGO || "mongodb://127.0.0.1:27017/addwechat?poolSize=100000000";
const AuthName = 'l_q6KiRVG4200kwRXIwVfgY1yOIa';
const AuthPass = 'N11ztBU2lExdNOklH2AmX4JOzdIa';
const salt = "BreakingBad";
const ROLES = {
ADMIN: 1,
PUB: 2,
SALEMANAGER: 3
}
const SECRET = 'remarketing-token';
let myToken = '';
// TODO ! put into init
MongoClient.connect(dbpath, (err, conn) => {
if (err) return console.log(err);
console.log("#### DB CONNECTED");
db = conn.db(process.env.MONGO_DB || "remarketing");
db
.collection("session")
.createIndex({ createdAt: 1 }, { expireAfterSeconds: 3600 * 24 });
});
// router.get('/*',function (req, res) {
// res.send("das");
// })
router.get('/ping',function (req, res) {
res.send({ status: 'ok' });
})
router.get('/search',function (req, res) {
res.send({ status: 'ok' });
})
const created = '';
function generateToken(token) {
let timeNow = Math.floor(Date.now() / 1000);
if(token)
// let token = jwt.sign({
// data,
// exp: created + 3600 * 24
// }, salt, {algorithm: 'RS256'});
// console.log(token);
return token;
}
router.post('/login',function(req,res) {
const { username, password } = req.body;
if(username === 'break' && password === '123456'){
axios.post('http://10.1.0.216:9912/getAuth',{
AuthName,
AuthPass
})
.then(rep => {
if(rep && rep.status === 200) {
res.send({result:rep.data});
}
else {
res.send({ msg: '服务器开小差了' });
}
})
.catch(err => {
res.send({ msg: err });
});
}
else{
res.send({ msg: '用户名密码错误' });
}
});
module.exports = {
router
}
\ No newline at end of file
const express = require('express');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const path = require('path');
//const morgan = require('morgan');
const http = require('http');
const app = express();
const api = require('./api');
const server = http.Server(app);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(cookieParser());
app.use(express.static(__dirname + '/dist'));
app.get('/*',function(req,res) {
res.sendFile(path.resolve(__dirname , 'dist/index.html'));
})
app.use('/api', api.router);
server.listen(process.env.PORT || 8081, function() {
console.log('server started');
});
\ No newline at end of file
This diff is collapsed.
...@@ -6,11 +6,18 @@ ...@@ -6,11 +6,18 @@
"serve": "vue-cli-service serve", "serve": "vue-cli-service serve",
"build": "vue-cli-service build", "build": "vue-cli-service build",
"lint": "vue-cli-service lint", "lint": "vue-cli-service lint",
"test:unit": "vue-cli-service test:unit" "test:unit": "vue-cli-service test:unit",
"start": "node-dev app.js"
}, },
"dependencies": { "dependencies": {
"axios": "^0.18.0", "axios": "^0.18.0",
"body-parser": "^1.18.3",
"cookie-parser": "^1.4.3",
"element-ui": "^2.4.5", "element-ui": "^2.4.5",
"express": "^4.16.3",
"jsonwebtoken": "^8.3.0",
"moment": "^2.22.2",
"mongodb": "^3.1.6",
"vue": "^2.5.17", "vue": "^2.5.17",
"vue-class-component": "^6.0.0", "vue-class-component": "^6.0.0",
"vue-property-decorator": "^7.0.0", "vue-property-decorator": "^7.0.0",
......
...@@ -12,7 +12,7 @@ const createFilterList = ( ...@@ -12,7 +12,7 @@ const createFilterList = (
desc: string, desc: string,
code: string, code: string,
}) => { }) => {
return axios.post(`api/permission`, form); return axios.post(`api/search`, form);
}; };
export { export {
......
import axios from 'axios';
axios.defaults.withCredentials = true;
const getUser = (form: { username: string, password: string }) => {
return axios.post('/api/login', form);
};
export {
getUser,
};
import axios from 'axios';
axios.defaults.withCredentials = true;
const getPermissions = (size: number, page?: number) => {
return axios.get(`/api/permission?page=${page}&size=${size}`);
};
const createPermission = (
form: {
name: string,
desc: string,
code: string,
}) => {
return axios.post(`api/permission`, form);
};
const updatePermission = (
form: {
id: string,
name?: string,
desc?: string,
status?: boolean,
}) => {
return axios.put(`api/permission`, form);
};
const deletePermission = (form: { permissionId: string }) => {
return axios.delete(`/api/permission`, { data: { permissionId: form.permissionId } });
};
export {
getPermissions,
createPermission,
updatePermission,
deletePermission,
};
import axios from 'axios';
axios.defaults.withCredentials = true;
const getRoles = (size: number, page?: number) => {
return axios.get(`/api/rolePermission?page=${page}&size=${size}`);
};
const createRole = (
form: {
name: string,
status?: boolean,
isUsed?: boolean,
parent?: string,
children?: string,
}) => {
return axios.post(`api/role`, form);
};
const updateRole = (
form: {
id: string,
status?: boolean,
isUsed?: boolean,
parent?: string,
children?: string,
}) => {
return axios.put(`api/role`, form);
};
const deleteRole = (form: { roleId: string }) => {
return axios.delete(`/api/role`, { data: { roleId: form.roleId } });
};
const setPermission = (form: { permissionId: string, roleId: string }) => {
return axios.post(`/api/setPermission`, form);
};
export {
getRoles,
createRole,
updateRole,
deleteRole,
setPermission,
};
import axios from 'axios';
axios.defaults.withCredentials = true;
const getPassports = (size: number, page?: number) => {
return axios.get(`/api/passport?page=${page}&size=${size}`);
};
const createPassport = (
form: {
password: string,
username: string,
email: string,
}) => {
return axios.post(`/api/passport`, form);
};
const updatePassport = (
form: {
id: string,
password?: string,
IsDelete?: boolean,
}) => {
return axios.put(`/api/passport`, form);
};
const deletePassport = (form: {id: string}) => {
return axios.delete(`/api/passport`, {data: {id: form.id}});
};
const setRole = (form: { passportId: string, roleId: string }) => {
return axios.post(`/api/setRole`, form);
};
export {
getPassports,
createPassport,
updatePassport,
deletePassport,
setRole,
};
import Vue from 'vue'; import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import login from './modules/login';
import filterNumber from './modules/filterNumber'; import filterNumber from './modules/filterNumber';
import addTask from './modules/addTask'; import addTask from './modules/addTask';
Vue.use(Vuex); Vue.use(Vuex);
export default new Vuex.Store({ export default new Vuex.Store({
modules: { modules: {
login,
filterNumber, filterNumber,
addTask, addTask,
}, },
......
import { Commit } from 'vuex';
import { Message } from 'element-ui';
import { GET_TOKEN } from '../types';
import { getUser } from '@/api/login';
export interface State {
isLogin: boolean;
}
const loginState: State = {
isLogin: false,
};
const actions = {
[GET_TOKEN](
context: { commit: Commit, state: State },
payload: { username: string, password: string },
) {
// 获取角色列表
getUser(payload).then((data) => {
const result = data.data.result;
if (result) {
context.commit(GET_TOKEN, result);
} else {
Message.error(`获取数据失败错误原因是${data.data.msg}`);
}
}).catch((err) => {
throw(err);
});
},
};
const mutations = {
[GET_TOKEN](state: State, data: { username: string, password: string }) {
state.isLogin = true;
// state.dataList = data.rows;
// state.count = data.count;
},
};
export default {
state: loginState,
actions,
mutations,
};
...@@ -34,6 +34,11 @@ export const GET_FILTERLIST = 'GET_FILTERLIST'; ...@@ -34,6 +34,11 @@ export const GET_FILTERLIST = 'GET_FILTERLIST';
// 创建筛选条件 // 创建筛选条件
export const CREATE_FILTERLIST = 'CREATE_FILTERLIST'; export const CREATE_FILTERLIST = 'CREATE_FILTERLIST';
// 登录
export const GET_TOKEN = 'GET_TOKEN';
// export const GET_FILTERLIST = 'GET_FILTERLIST'; // export const GET_FILTERLIST = 'GET_FILTERLIST';
// export const GET_FILTERLIST = 'GET_FILTERLIST'; // export const GET_FILTERLIST = 'GET_FILTERLIST';
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<el-input v-model="loginForm.password" auto-complete="off" placeholder="请输入您的密码" type="password"></el-input> <el-input v-model="loginForm.password" auto-complete="off" placeholder="请输入您的密码" type="password"></el-input>
</el-form-item> </el-form-item>
</el-form> </el-form>
<el-button @click='loginSumbit()'> <el-button @click='loginSumbit()' :loading='loginState.islogin' ref='sumbitBtn'>
登录 登录
</el-button> </el-button>
</div> </div>
...@@ -20,24 +20,40 @@ ...@@ -20,24 +20,40 @@
<script lang='ts'> <script lang='ts'>
import { Component, Vue } from 'vue-property-decorator'; import { Component, Vue } from 'vue-property-decorator';
import { getUser } from '../api/login';
import { Action, State } from 'vuex-class';
import { GET_TOKEN } from '@/store/types';
@Component({ @Component({
}) })
export default class Overview extends Vue { export default class Overview extends Vue {
@State('login') public loginState: any;
@Action(GET_TOKEN) public getToken: any;
public loginForm = { public loginForm = {
username: '', username: '',
password: '', password: '',
}; };
public $refs!: {
sumbitBtn: HTMLFormElement,
};
public loginSumbit() { public loginSumbit() {
if (this.loginForm.username === 'zhangsan' && this.loginForm.password === '123456') { if (this.loginForm.username === '' || this.loginForm.password === '') {
// 发送请求,接受到token。 alert('请输入信息');
this.$router.push('/filternumber'); return false;
} else {
this.$message.error('您所输入的用户名或密码不正确');
} }
const sumbitBtn = this.$refs.sumbitBtn;
this.getToken(this.loginForm).then(() => {
const islogin = this.loginState.islogin;
if (!islogin) {
sumbitBtn.disabled = islogin;
} else {
sumbitBtn.disabled = islogin;
this.$router.push('/filterNumber');
}
});
} }
} }
</script> </script>
......
module.exports = { module.exports = {
baseUrl: process.env.NODE_ENV === 'production' ? baseUrl: process.env.NODE_ENV === 'production' ?
'/production-sub-path/' : './' :
'/', '/',
devServer: { devServer: {
// proxy: 'http://localhost:8999', // proxy: 'http://localhost:8999',
......
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