Commit af1b43f9 authored by lvweichao's avatar lvweichao

update: user page authentication

parent 4f963e12
...@@ -73,25 +73,15 @@ exports.get_ks3_config = async (ctx, next) => { ...@@ -73,25 +73,15 @@ exports.get_ks3_config = async (ctx, next) => {
const policy = { const policy = {
"expiration": new Date(getExpires(3600)*1000).toISOString(), //一小时后 "expiration": new Date(getExpires(3600)*1000).toISOString(), //一小时后
"conditions": [ "conditions": [
["eq","$bucket", bucket], ["eq","$bucket", bucket]
["starts-with","$acl", "public-read"],
// ["starts-with", "$key", ""],
// ["starts-with", "$name", ""], //表单中传了name字段,也需要加到policy中
// ["starts-with", "$x-kss-meta-custom-param1",""],
// ["starts-with", "$x-kss-newfilename-in-body",""],//必须只包含小写字符
// ["starts-with", "$Cache-Control",""],
// ["starts-with", "$Expires", ""],
// ["starts-with", "$Content-Disposition", ""],
// ["starts-with", "$Content-Type",""],
// ["starts-with", "$Content-Encoding",""]
] ]
} }
const stringToSign = Ks3Util.Base64.encode(JSON.stringify(policy)) const stringToSign = Ks3Util.Base64.encode(JSON.stringify(policy))
console.log('stringToSign:::', stringToSign) console.log('stringToSign:::', stringToSign)
// const signature = Ks3Util.b64_hmac_sha1(KS3_CONFIG.AccessKeySecret, stringToSign) const signature = Ks3Util.b64_hmac_sha1(KS3_CONFIG.SK, stringToSign)
const signature = crypto.createHmac('sha1', KS3_CONFIG.SK).update(stringToSign).digest().toString('base64'); // const signature = crypto.createHmac('sha1', KS3_CONFIG.SK).update(stringToSign).digest().toString('base64');
console.log("signature::::::", signature) console.log("signature::::::", signature)
ctx.body = { ctx.body = {
......
...@@ -12,6 +12,7 @@ Ks3.b64_hmac_sha1 = function (key, data) { ...@@ -12,6 +12,7 @@ Ks3.b64_hmac_sha1 = function (key, data) {
* Convert an array of big-endian words to a base-64 string * Convert an array of big-endian words to a base-64 string
*/ */
Ks3.binb2b64 = function (binarray) { Ks3.binb2b64 = function (binarray) {
console.log("binb2b64::::::", binarray)
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var str = ""; var str = "";
for (var i = 0; i < binarray.length * 4; i += 3) { for (var i = 0; i < binarray.length * 4; i += 3) {
...@@ -23,6 +24,8 @@ Ks3.binb2b64 = function (binarray) { ...@@ -23,6 +24,8 @@ Ks3.binb2b64 = function (binarray) {
else str += tab.charAt((triplet >> 6 * (3 - j)) & 0x3F); else str += tab.charAt((triplet >> 6 * (3 - j)) & 0x3F);
} }
} }
console.log("binb2b6422222::::::", str)
return str; return str;
} }
......
...@@ -4,10 +4,20 @@ exports.httpReq = (ctx, opts) => { ...@@ -4,10 +4,20 @@ exports.httpReq = (ctx, opts) => {
opts.timeout = opts.timeout || 1000 opts.timeout = opts.timeout || 1000
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var time_start = +new Date() var time_start = +new Date()
opts.qs = {...ctx.request.query, ...opts.qs};
const defaultQs = {
appid: 'merchant-op',
cv: '1.0.0',
version: '999999',
distribution: 'op',
net: 'wifi',
platform: '2',
}
opts.qs = { ...defaultQs, ...ctx.request.query, ...opts.qs};
request(opts, (err, res, body) => { request(opts, (err, res, body) => {
console.info(`[Api] httpReq (${opts.url},${opts.headers && opts.headers.cookie}, user:[${opts.qs.op_cur_user}]) spent: ${+new Date() - time_start}ms`) console.info(`[Api] httpReq (${ctx.request.url}, user:[${opts.qs.op_cur_user}]) spent: ${+new Date() - time_start}ms`)
if (!err) { if (!err) {
resolve(body) resolve(body)
......
...@@ -47,7 +47,6 @@ export default { ...@@ -47,7 +47,6 @@ export default {
}, },
activeMenu: function () { activeMenu: function () {
console.log(988888, this.$route.path)
return this.$route.path; return this.$route.path;
}, },
}, },
......
ks3-js-sdk @ ea6ab311
Subproject commit ea6ab311ebfa69725e824a5cc28bd53d93681d34
...@@ -8,30 +8,32 @@ import "element-plus/lib/theme-chalk/index.css"; ...@@ -8,30 +8,32 @@ import "element-plus/lib/theme-chalk/index.css";
import "dayjs/locale/zh-cn"; import "dayjs/locale/zh-cn";
import locale from "element-plus/lib/locale/lang/zh-cn"; import locale from "element-plus/lib/locale/lang/zh-cn";
/* import { fetchCurrentUser } from "./service/user"; import { fetchCurrentUser } from "./service/user";
import { checkPathAuth } from "./utils/authUtil"; import { checkPathAuth } from "./utils/authUtil";
import { redirectToLogin } from "./utils/util"; */ import { redirectToLogin } from "./utils/util";
// 处理路由权限 // 处理路由权限
/* router.beforeResolve(async (to, from, next) => { router.beforeResolve(async (to, from, next) => {
if (to.meta.requireAuth && !store.state.permissions) {
if (!to.meta.requireAuth) next();
if (!store.state.permissions) {
const { status, user } = await fetchCurrentUser(); const { status, user } = await fetchCurrentUser();
if (status === 'success') { if (status === 'success') {
store.commit('updateUserInfo', user); store.commit('updateUserInfo', user);
store.dispatch('updateUserPermission', { email: user.email }).then(() => { await store.dispatch('updateUserPermission', { email: user.email })
if (!checkPathAuth(to.path)) {
router.push('/403')
}
})
next()
} else { } else {
redirectToLogin(); redirectToLogin();
return false;
} }
return false; }
if (!checkPathAuth(to.path)) {
router.push('/403')
} else { } else {
next() next()
} }
}) */ })
createApp(App) createApp(App)
.use(router) .use(router)
......
<template> <template>
<div> <div>
<layout> Forbidden! </layout> <layout> 没有权限! </layout>
</div> </div>
</template> </template>
......
<template> <template>
<div> <div>
<layout> <layout>
not found 页面不存在!
</layout> </layout>
</div> </div>
</template> </template>
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
<el-form-item class="func-btn"> <el-form-item class="func-btn">
<el-button type="primary" @click="getUserList">查询</el-button> <el-button type="primary" @click="getUserList">查询</el-button>
<el-button @click="onReset">重置</el-button> <el-button @click="onReset">重置</el-button>
<el-button @click="createUser">新建用户</el-button> <el-button @click="createUser" :disabled="!permission.get('create')">新建用户</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
<el-table :data="renderUserList" border style="width: 100%"> <el-table :data="renderUserList" border style="width: 100%">
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
<el-button type="text" size="small" @click="checkUser(scope.row)" <el-button type="text" size="small" @click="checkUser(scope.row)"
>查看</el-button >查看</el-button
> >
<el-button @click="editUser(scope.row)" type="text" size="small" <el-button @click="editUser(scope.row)" type="text" size="small" :disabled="!permission.get('edit')"
>修改</el-button >修改</el-button
> >
<el-button <el-button
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
type="text" type="text"
size="small" size="small"
@click="disableUser(scope.row)" @click="disableUser(scope.row)"
:disabled="!permission.get('enable')"
>禁用</el-button >禁用</el-button
> >
<el-button <el-button
...@@ -65,6 +66,7 @@ ...@@ -65,6 +66,7 @@
type="text" type="text"
size="small" size="small"
@click="enableUser(scope.row)" @click="enableUser(scope.row)"
:disabled="!permission.get('disable')"
>启用</el-button >启用</el-button
> >
</template> </template>
...@@ -140,6 +142,12 @@ export default { ...@@ -140,6 +142,12 @@ export default {
}; };
}, },
computed: { computed: {
permission() {
const modulePermissions = this.$store.getters.moduleSubPermissions('user') || [];
console.log('Current page func-permissions:', modulePermissions);
return new Map(modulePermissions.map(ele => [ele.name, true]))
},
renderUserList() { renderUserList() {
const statusMap = new Map([ const statusMap = new Map([
[1, "启用"], [1, "启用"],
...@@ -266,6 +274,7 @@ export default { ...@@ -266,6 +274,7 @@ export default {
user_mobile: "", user_mobile: "",
user_status: "", user_status: "",
}; };
this.getUserList();
}, },
updatePage({ page, pageSize }) { updatePage({ page, pageSize }) {
......
...@@ -13,13 +13,13 @@ import axios from '../utils/request'; ...@@ -13,13 +13,13 @@ import axios from '../utils/request';
export async function ksOssUpload(file) { export async function ksOssUpload(file) {
const {bucket, objectId, policy, signature} = await getKs3Config(); const { bucket, objectId, policy, signature } = await getKs3Config();
const protocal = window.location.protocol === 'https:' ? 'https' : 'http'; const protocal = window.location.protocol === 'https:' ? 'https' : 'http';
const uploadURL = `${protocal}://${KS3_CONST.DOMAIN}/${bucket}`; const uploadURL = `${protocal}://${KS3_CONST.DOMAIN}/${bucket}`;
// return new Promise((resolve, reject) => { // return new Promise((resolve, reject) => {
// CommonServer.getKsOssSign().then(res => { // CommonServer.getKsOssSign().then(res => {
// const { accessid, policy, signature } = res // const { accessid, policy, signature } = res
const formData = new FormData() const formData = new FormData()
formData.append('acl', 'public-read') formData.append('acl', 'public-read')
formData.append('key', objectId) formData.append('key', objectId)
...@@ -27,23 +27,9 @@ export async function ksOssUpload(file) { ...@@ -27,23 +27,9 @@ export async function ksOssUpload(file) {
formData.append('KSSAccessKeyId', KS3_CONST.AccessKeyID) formData.append('KSSAccessKeyId', KS3_CONST.AccessKeyID)
formData.append('policy', policy) formData.append('policy', policy)
formData.append('file', file) formData.append('file', file)
const res = await axios.post(uploadURL, formData).then(res => { console.log('ksOssUpload url::', uploadURL)
console.log(66666 ,res) const res = await axios({ url: uploadURL, method: 'post', data: formData, withCredentials: false }).then(res => {
// const { status } = res console.log('ksOssUpload res::', res)
// if (status === 200) {
// const data = {
// url: `${OSS_URL}/${key}`,
// type: fileType(file.name)
// }
// resolve(data)
// } else {
// reject(res)
// }
}) })
// .catch(err => {
// reject(err)
// })
return res; return res;
// }).catch(err => {})
// })
} }
\ No newline at end of file
/**
* axios封装
*/
import axios from "axios"; import axios from "axios";
import store from "@/store" import store from "@/store"
import { v1 as uuidv1 } from 'uuid';
// import { ElMessage } from "element-plus"; // import { ElMessage } from "element-plus";
// import { APP_URI } from "../config/app.config"; // import { APP_URI } from "../config/app.config";
/** /**
...@@ -32,7 +31,9 @@ export const defaultConfig = { ...@@ -32,7 +31,9 @@ export const defaultConfig = {
*/ */
const getDefaultParams = () => { const getDefaultParams = () => {
return { return {
'op_cur_user': store.state.userInfo && store.state.userInfo.email 'op_cur_user': store.state.userInfo && store.state.userInfo.email,
'reqid': uuidv1().replace(/-/g, '')
} }
}; };
const getDefaultHeaders = () => {}; const getDefaultHeaders = () => {};
......
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