mirror of
https://gitee.com/czh-dev/upload-hub
synced 2026-09-05 23:47:46 +08:00
feat:访问密码加密
This commit is contained in:
@@ -29,19 +29,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="password-config-modal">
|
<div class="password-config-modal">
|
||||||
<el-dialog
|
<el-dialog title="请输入密码" :visible.sync="showPasswordDialog" width="30%" :close-on-click-modal="false"
|
||||||
title="请输入密码"
|
:show-close="false" custom-class="password-dialog">
|
||||||
:visible.sync="showPasswordDialog"
|
<el-input v-model="inputPassword" type="text" placeholder="请输入密码" />
|
||||||
width="30%"
|
|
||||||
:close-on-click-modal="false"
|
|
||||||
:show-close="false"
|
|
||||||
custom-class="password-dialog"
|
|
||||||
>
|
|
||||||
<el-input
|
|
||||||
v-model="inputPassword"
|
|
||||||
type="text"
|
|
||||||
placeholder="请输入密码"
|
|
||||||
/>
|
|
||||||
<span slot="footer" class="dialog-footer">
|
<span slot="footer" class="dialog-footer">
|
||||||
<el-button @click="verifyPassword">确定</el-button>
|
<el-button @click="verifyPassword">确定</el-button>
|
||||||
</span>
|
</span>
|
||||||
@@ -51,9 +41,9 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import SparkMD5 from 'spark-md5'
|
||||||
import sseManager from '@/utils/sse';
|
import sseManager from '@/utils/sse';
|
||||||
import { getPassword, setPassword } from '@/utils/api';
|
import { getPassword, setPassword } from '@/utils/api';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'PasswordConfig',
|
name: 'PasswordConfig',
|
||||||
props: {
|
props: {
|
||||||
@@ -90,6 +80,7 @@ export default {
|
|||||||
this.showPasswordDialog = true;
|
this.showPasswordDialog = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
localStorage.setItem('main', mainUser);
|
||||||
localStorage.setItem('password', password);
|
localStorage.setItem('password', password);
|
||||||
this.$emit('main-user', mainUser);
|
this.$emit('main-user', mainUser);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -102,17 +93,27 @@ export default {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.tempEnablePassword) {
|
let hashedPassword = '';
|
||||||
this.tempPassword = '';
|
if (this.tempEnablePassword) {
|
||||||
|
const spark = new SparkMD5();
|
||||||
|
spark.append(this.tempPassword);
|
||||||
|
hashedPassword = spark.end();
|
||||||
}
|
}
|
||||||
const res = await setPassword(this.tempPassword);
|
|
||||||
|
const res = await setPassword(hashedPassword);
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
this.$message.success('保存成功');
|
this.$message.success('保存成功');
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
verifyPassword() {
|
verifyPassword() {
|
||||||
if (this.tempPassword === this.inputPassword) {
|
let hashedPassword = '';
|
||||||
|
const spark = new SparkMD5();
|
||||||
|
spark.append(this.inputPassword);
|
||||||
|
hashedPassword = spark.end();
|
||||||
|
|
||||||
|
if (this.tempPassword === hashedPassword) {
|
||||||
|
this.tempPassword = this.inputPassword;
|
||||||
this.showPasswordDialog = false;
|
this.showPasswordDialog = false;
|
||||||
this.inputPassword = '';
|
this.inputPassword = '';
|
||||||
} else {
|
} else {
|
||||||
@@ -182,7 +183,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.form-group input {
|
.form-group input {
|
||||||
width: 100%;
|
width: 95%;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
border: 1px solid #ddd;
|
border: 1px solid #ddd;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-button :type="enableShare ? 'danger' : 'primary'" size="medium" @click="stopSharing" class="stop-btn">
|
<el-button :disabled="!isAdmin" :type="enableShare ? 'danger' : 'primary'" size="medium" @click="stopSharing" class="stop-btn">
|
||||||
<i class="el-icon-switch-button"></i>
|
<i class="el-icon-switch-button"></i>
|
||||||
{{ enableShare ? '终止分享' : '开始分享' }}
|
{{ enableShare ? '终止分享' : '开始分享' }}
|
||||||
</el-button>
|
</el-button>
|
||||||
@@ -57,7 +57,7 @@
|
|||||||
<el-button type="success" size="mini" plain @click="copyLink(scope.row.accessUrl)" class="action-btn">
|
<el-button type="success" size="mini" plain @click="copyLink(scope.row.accessUrl)" class="action-btn">
|
||||||
<i class="el-icon-link"></i>
|
<i class="el-icon-link"></i>
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button type="danger" size="mini" plain @click="deleteFile(scope.row.fileIdentifier)" class="action-btn">
|
<el-button v-if="isAdmin" type="danger" size="mini" plain @click="deleteFile(scope.row.fileIdentifier)" class="action-btn">
|
||||||
<i class="el-icon-delete"></i>
|
<i class="el-icon-delete"></i>
|
||||||
</el-button>
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
@@ -87,6 +87,7 @@ export default {
|
|||||||
this.fetchFiles();
|
this.fetchFiles();
|
||||||
this.getShareStatus();
|
this.getShareStatus();
|
||||||
this.getShareAddress();
|
this.getShareAddress();
|
||||||
|
this.getAuth();
|
||||||
|
|
||||||
sseManager.subscribe('sharedFileUpdate', () => {
|
sseManager.subscribe('sharedFileUpdate', () => {
|
||||||
this.fetchFiles();
|
this.fetchFiles();
|
||||||
@@ -105,6 +106,10 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
getAuth() {
|
||||||
|
const isAdmin = localStorage.getItem('main')
|
||||||
|
this.isAdmin = isAdmin === 'true'
|
||||||
|
},
|
||||||
async getShareAddress() {
|
async getShareAddress() {
|
||||||
try {
|
try {
|
||||||
const res = await shareAddress();
|
const res = await shareAddress();
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<div class="menu-container" @mouseenter="showMenu = true" @mouseleave="showMenu = false">
|
<div class="menu-container" @mouseenter="showMenu = true" @mouseleave="showMenu = false">
|
||||||
<div class="menu-icon">☰</div>
|
<div class="menu-icon">☰</div>
|
||||||
<div v-show="showMenu" class="dropdown-menu">
|
<div v-show="showMenu" class="dropdown-menu">
|
||||||
<div class="menu-item" @click="openSettings">上传设置</div>
|
<div class="menu-item" v-if="isAdmin" @click="openSettings">上传设置</div>
|
||||||
<div class="menu-item" v-if="isAdmin" @click="openStorageConfig">存储配置</div>
|
<div class="menu-item" v-if="isAdmin" @click="openStorageConfig">存储配置</div>
|
||||||
<div class="menu-item" v-if="isAdmin" @click="openPasswordConfig">密码设置</div>
|
<div class="menu-item" v-if="isAdmin" @click="openPasswordConfig">密码设置</div>
|
||||||
<div class="menu-item" @click="openAbout">关于</div>
|
<div class="menu-item" @click="openAbout">关于</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user