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