feat: import iconfont styles, change password function is ready

This commit is contained in:
RockYang 2023-06-16 17:28:21 +08:00
parent 6f37024e34
commit a3ee7ca2d8
13 changed files with 231 additions and 13 deletions

View File

@ -318,3 +318,43 @@ func (h *UserHandler) Profile(c *gin.Context) {
userVo.UpdatedAt = user.UpdatedAt.Unix()
resp.SUCCESS(c, userVo)
}
// Password 更新密码
func (h *UserHandler) Password(c *gin.Context) {
var data struct {
OldPass string `json:"old_pass"`
Password string `json:"password"`
}
if err := c.ShouldBindJSON(&data); err != nil {
resp.ERROR(c, types.InvalidArgs)
return
}
if len(data.Password) < 8 {
resp.ERROR(c, "密码长度不能少于8个字符")
return
}
user, err := utils.GetLoginUser(c, h.db)
if err != nil {
resp.NotAuth(c)
return
}
password := utils.GenPassword(data.OldPass, user.Salt)
logger.Info(user.Salt, ",", user.Password, ",", password, ",", data.OldPass)
if password != user.Password {
resp.ERROR(c, "原密码错误")
return
}
newPass := utils.GenPassword(data.Password, user.Salt)
res := h.db.Model(&user).UpdateColumn("password", newPass)
if res.Error != nil {
logger.Error("更新数据库失败: ", res.Error)
resp.ERROR(c, "更新数据库失败")
return
}
resp.SUCCESS(c)
}

View File

@ -106,6 +106,7 @@ func main() {
group.GET("session", h.Session)
group.GET("profile", h.Profile)
group.POST("profile/update", h.ProfileUpdate)
group.POST("password", h.Password)
}),
fx.Invoke(func(s *core.AppServer, h *handler.ChatHandler) {
group := s.Engine.Group("/api/chat/")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -0,0 +1,31 @@
@font-face {
font-family: "iconfont"; /* Project id 4125778 */
src: url('iconfont.woff2?t=1686901862117') format('woff2'),
url('iconfont.woff?t=1686901862117') format('woff'),
url('iconfont.ttf?t=1686901862117') format('truetype');
}
.iconfont {
font-family: "iconfont" !important;
font-size: 16px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-password:before {
content: "\e62a";
}
.icon-send:before {
content: "\e604";
}
.icon-logout:before {
content: "\e62e";
}
.icon-github:before {
content: "\e66f";
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,4 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=https://www.iconfont.cn/manage/index?manage_type=myprojects&projectId=4125778
HostUrl=https://www.iconfont.cn/api/project/download.zip?spm=a313x.7781069.1998910419.d7543c303&pid=4125778&ctoken=SHhMU2NkC6BavrZsXJmrL-LS

View File

@ -0,0 +1,37 @@
{
"id": "4125778",
"name": "chatgpt",
"font_family": "iconfont",
"css_prefix_text": "icon-",
"description": "",
"glyphs": [
{
"icon_id": "611345",
"name": "密码",
"font_class": "password",
"unicode": "e62a",
"unicode_decimal": 58922
},
{
"icon_id": "1418205",
"name": "发送",
"font_class": "send",
"unicode": "e604",
"unicode_decimal": 58884
},
{
"icon_id": "1048893",
"name": "注销",
"font_class": "logout",
"unicode": "e62e",
"unicode_decimal": 58926
},
{
"icon_id": "14401714",
"name": "github",
"font_class": "github",
"unicode": "e66f",
"unicode_decimal": 58991
}
]
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,96 @@
<template>
<el-dialog
v-model="show"
:close-on-click-modal="false"
:show-close="true"
:before-close="close"
title="修改密码"
>
<div class="form" id="password-form">
<el-form :model="form" label-width="120px">
<el-form-item label="原始密码">
<el-input v-model="form['old_pass']" type="password"/>
</el-form-item>
<el-form-item label="新密码">
<el-input v-model="form['password']" type="password"/>
</el-form-item>
<el-form-item label="确认密码">
<el-input v-model="form['repass']" type="password"/>
</el-form-item>
</el-form>
</div>
<template #footer>
<span class="dialog-footer">
<el-button @click="close">关闭</el-button>
<el-button type="primary" @click="save">
保存
</el-button>
</span>
</template>
</el-dialog>
</template>
<script setup>
import {defineEmits, defineProps, onMounted, ref} from "vue"
import {httpGet, httpPost} from "@/utils/http";
import {ElMessage} from "element-plus";
const props = defineProps({
show: Boolean,
});
const form = ref({})
onMounted(() => {
})
const emits = defineEmits(['hide']);
const save = function () {
if (form.value['password'].length < 8) {
return ElMessage.error('密码的长度为8-16个字符');
}
if (form.value['repass'] !== form.value['password']) {
return ElMessage.error('两次输入密码不一致');
}
httpPost('/api/user/password', form.value).then(() => {
ElMessage.success({
message: '更新成功',
appendTo: document.getElementById('password-form'),
onClose: () => emits('logout', false)
})
}).catch((e) => {
ElMessage.error({
message: '更新失败,'+e.message,
appendTo: document.getElementById('password-form')
})
})
}
const close = function () {
emits('hide', false);
}
</script>
<style lang="stylus">
.el-dialog {
--el-dialog-width 90%;
max-width 500px;
.el-dialog__body {
padding-top 10px;
max-height 600px;
overflow-y auto;
.form {
position relative;
.el-message {
position: absolute;
}
}
}
}
</style>

View File

@ -55,6 +55,11 @@
<span>聊天设置</span>
</el-dropdown-item>
<el-dropdown-item @click="showPasswordDialog=true">
<i class="iconfont icon-password"></i>
<span>修改密码</span>
</el-dropdown-item>
<el-dropdown-item @click="clearAllChats">
<el-icon>
<Delete/>
@ -63,18 +68,17 @@
</el-dropdown-item>
<el-dropdown-item @click="logout">
<el-icon>
<Monitor/>
</el-icon>
<i class="iconfont icon-logout"></i>
<span>注销</span>
</el-dropdown-item>
<!-- <el-dropdown-item>-->
<!-- <i class="icon-font icon-github"></i>-->
<!-- <span>-->
<!-- <el-link type="primary" href="https://github.com/yangjian102621/chatgpt-plus" target="_blank">ChatGPT-Plus-V3</el-link>-->
<!-- </span>-->
<!-- </el-dropdown-item>-->
<el-dropdown-item>
<i class="iconfont icon-github"></i>
<span>
powered by
<el-link type="primary" href="https://github.com/yangjian102621/chatgpt-plus" target="_blank">chatgpt-plus-v3</el-link>
</span>
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
@ -180,6 +184,7 @@
</el-container>
<config-dialog :show="showConfigDialog" :models="models" @hide="showConfigDialog = false" @update-user="updateUser" />
<password-dialog :show="showPasswordDialog" @hide="showPasswordDialog = false" @logout="logout" />
</div>
@ -210,6 +215,7 @@ import {httpGet, httpPost} from "@/utils/http";
import {useRouter} from "vue-router";
import Clipboard from "clipboard";
import ConfigDialog from "@/components/ConfigDialog.vue";
import PasswordDialog from "@/components/PasswordDialog.vue";
const title = ref('ChatGPT-智能助手');
const logo = 'images/logo.png';
@ -229,6 +235,7 @@ const roleId = ref(0)
const newChatItem = ref(null);
const router = useRouter();
const showConfigDialog = ref(false);
const showPasswordDialog = ref(false);
if (!user.value) {
router.push("login");
@ -712,6 +719,7 @@ const updateUser = function (data) {
</script>
<style lang="stylus">
@import '@/assets/iconfont/iconfont.css';
#app {
height: 100%;
@ -729,13 +737,13 @@ const updateUser = function (data) {
.logo {
background-color: #ffffff
border-radius: 50%;
width: 40px;
height: 40px;
border-radius: 8px;
width: 35px;
height: 35px;
}
span {
padding-top: 8px;
padding-top: 5px;
padding-left: 10px;
}
}