feat: add nickname field for user

This commit is contained in:
RockYang 2023-12-29 17:39:37 +08:00
parent 3d2035d08a
commit 3c6e86d04b
9 changed files with 40 additions and 39 deletions

View File

@ -155,7 +155,7 @@ func authorizeMiddleware(s *AppServer, client *redis.Client) gin.HandlerFunc {
c.Request.URL.Path == "/api/invite/hits" || c.Request.URL.Path == "/api/invite/hits" ||
c.Request.URL.Path == "/api/sd/jobs" || c.Request.URL.Path == "/api/sd/jobs" ||
c.Request.URL.Path == "/api/upload" || c.Request.URL.Path == "/api/upload" ||
strings.HasPrefix(c.Request.URL.Path, "/test/") || strings.HasPrefix(c.Request.URL.Path, "/api/test") ||
strings.HasPrefix(c.Request.URL.Path, "/api/function/") || strings.HasPrefix(c.Request.URL.Path, "/api/function/") ||
strings.HasPrefix(c.Request.URL.Path, "/api/sms/") || strings.HasPrefix(c.Request.URL.Path, "/api/sms/") ||
strings.HasPrefix(c.Request.URL.Path, "/api/captcha/") || strings.HasPrefix(c.Request.URL.Path, "/api/captcha/") ||

View File

@ -1,40 +1,34 @@
package handler package handler
import ( import (
"chatplus/service" "chatplus/store/model"
"chatplus/utils"
"chatplus/utils/resp"
"fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gorm.io/gorm"
) )
type TestHandler struct { type TestHandler struct {
snowflake *service.Snowflake db *gorm.DB
} }
func NewTestHandler(snowflake *service.Snowflake) *TestHandler { func NewTestHandler(db *gorm.DB) *TestHandler {
return &TestHandler{snowflake: snowflake} return &TestHandler{db: db}
} }
func (h *TestHandler) TestPay(c *gin.Context) { func (h *TestHandler) Test(c *gin.Context) {
//appId := "" //Appid var users []model.User
//appSecret := "" //密钥 tx := h.db.Find(&users)
//var host = "https://api.xunhupay.com/payment/do.html" //跳转支付页接口URL if tx.Error != nil {
//client := payment.NewXunHuPay(appId, appSecret) //初始化调用 resp.ERROR(c, tx.Error.Error())
// return
////支付参数appid、time、nonce_str和hash这四个参数不用传调用的时候执行方法内部已经处理 }
//orderNo, _ := h.snowflake.Next()
//params := map[string]string{ for _, u := range users {
// "version": "1.1", u.Nickname = fmt.Sprintf("极客学长@%d", utils.RandomNumber(6))
// "trade_order_id": orderNo, h.db.Updates(&u)
// "total_fee": "0.1", }
// "title": "测试支付",
// "notify_url": "http://xxxxxxx.com", resp.SUCCESS(c)
// "return_url": "http://localhost:8888",
// "wap_name": "极客学长",
// "callback_url": "",
//}
//
//execute, err := client.Execute(host, params) //执行支付操作
//if err != nil {
// logger.Error(err)
//}
//resp.SUCCESS(c, execute)
} }

View File

@ -95,6 +95,7 @@ func (h *UserHandler) Register(c *gin.Context) {
salt := utils.RandString(8) salt := utils.RandString(8)
user := model.User{ user := model.User{
Password: utils.GenPassword(data.Password, salt), Password: utils.GenPassword(data.Password, salt),
Nickname: fmt.Sprintf("极客学长@%d", utils.RandomNumber(6)),
Avatar: "/images/avatar/user.png", Avatar: "/images/avatar/user.png",
Salt: salt, Salt: salt,
Status: true, Status: true,
@ -256,6 +257,7 @@ func (h *UserHandler) Session(c *gin.Context) {
type userProfile struct { type userProfile struct {
Id uint `json:"id"` Id uint `json:"id"`
Nickname string `json:"nickname"`
Mobile string `json:"mobile"` Mobile string `json:"mobile"`
Avatar string `json:"avatar"` Avatar string `json:"avatar"`
ChatConfig types.UserChatConfig `json:"chat_config"` ChatConfig types.UserChatConfig `json:"chat_config"`

View File

@ -364,8 +364,7 @@ func main() {
fx.Provide(handler.NewTestHandler), fx.Provide(handler.NewTestHandler),
fx.Invoke(func(s *core.AppServer, h *handler.TestHandler) { fx.Invoke(func(s *core.AppServer, h *handler.TestHandler) {
group := s.Engine.Group("/test/") s.Engine.GET("/api/test", h.Test)
group.GET("pay", h.TestPay)
}), }),
fx.Invoke(func(s *core.AppServer, db *gorm.DB) { fx.Invoke(func(s *core.AppServer, db *gorm.DB) {
err := s.Run(db) err := s.Run(db)

View File

@ -3,6 +3,7 @@ package model
type User struct { type User struct {
BaseModel BaseModel
Mobile string Mobile string
Nickname string
Password string Password string
Avatar string Avatar string
Salt string // 密码盐 Salt string // 密码盐

View File

@ -5,6 +5,7 @@ import "chatplus/core/types"
type User struct { type User struct {
BaseVo BaseVo
Mobile string `json:"mobile"` Mobile string `json:"mobile"`
Nickname string `json:"nickname"`
Avatar string `json:"avatar"` Avatar string `json:"avatar"`
Salt string `json:"salt"` // 密码盐 Salt string `json:"salt"` // 密码盐
TotalTokens int64 `json:"total_tokens"` // 总消耗tokens TotalTokens int64 `json:"total_tokens"` // 总消耗tokens

View File

@ -0,0 +1 @@
ALTER TABLE `chatgpt_users` ADD `nickname` VARCHAR(30) NOT NULL COMMENT '昵称' AFTER `mobile`;

View File

@ -14,7 +14,10 @@
</el-icon> </el-icon>
</el-upload> </el-upload>
</el-row> </el-row>
<el-form-item label="账户"> <el-form-item label="昵称">
{{ user['nickname'] }}
</el-form-item>
<el-form-item label="手机号">
<span>{{ user.mobile }}</span> <span>{{ user.mobile }}</span>
<el-tooltip <el-tooltip
class="box-item" class="box-item"

View File

@ -43,7 +43,7 @@
<el-dropdown :hide-on-click="true" class="user-info" trigger="click" v-if="isLogin"> <el-dropdown :hide-on-click="true" class="user-info" trigger="click" v-if="isLogin">
<span class="el-dropdown-link"> <span class="el-dropdown-link">
<el-image :src="loginUser.avatar"/> <el-image :src="loginUser.avatar"/>
<span class="username">{{ '极客学长@' + loginUser.mobile }}</span> <span class="username">{{ loginUser.nickname }}</span>
<el-icon><ArrowDown/></el-icon> <el-icon><ArrowDown/></el-icon>
</span> </span>
<template #dropdown> <template #dropdown>
@ -105,12 +105,12 @@
:value="item.id" :value="item.id"
/> />
</el-select> </el-select>
<el-button type="primary" @click="newChat"> <el-button type="primary" @click="newChat">
<el-icon> <el-icon>
<Plus/> <Plus/>
</el-icon> </el-icon>
新建对话 新建对话
</el-button> </el-button>
<el-button type="success" @click="exportChat" plain> <el-button type="success" @click="exportChat" plain>
<i class="iconfont icon-export"></i> <i class="iconfont icon-export"></i>