mirror of
				https://github.com/yangjian102621/geekai.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	feat: email registration function is ready
This commit is contained in:
		
							
								
								
									
										27
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								README.md
									
									
									
									
									
								
							@@ -13,12 +13,6 @@ ChatGLM,讯飞星火,文心一言等多个平台的大语言模型。集成了
 | 
			
		||||
* 集成插件 API 功能,可结合大语言模型的 function 功能开发各种强大的插件,已内置实现了微博热搜,今日头条,今日早报和 AI
 | 
			
		||||
  绘画函数插件。
 | 
			
		||||
 | 
			
		||||
## 最新版本一键部署脚本
 | 
			
		||||
目前仅支持 Ubuntu 和 Centos 系统。
 | 
			
		||||
```shell
 | 
			
		||||
bash -c "$(curl -fsSL https://img.r9it.com/tmp/install-v3.2.3-8b588904ef.sh)"
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## 功能截图
 | 
			
		||||
 | 
			
		||||
### PC 端聊天界面
 | 
			
		||||
@@ -69,11 +63,30 @@ bash -c "$(curl -fsSL https://img.r9it.com/tmp/install-v3.2.3-8b588904ef.sh)"
 | 
			
		||||

 | 
			
		||||

 | 
			
		||||
 | 
			
		||||
### 7. 体验地址
 | 
			
		||||
### 体验地址
 | 
			
		||||
 | 
			
		||||
> 免费体验地址:[https://ai.r9it.com/chat](https://ai.r9it.com/chat) <br/>
 | 
			
		||||
> **注意:请合法使用,禁止输出任何敏感、不友好或违规的内容!!!**
 | 
			
		||||
 | 
			
		||||
## 快速部署
 | 
			
		||||
**演示站不提供任何充值点卡售卖或者VIP充值服务。** 如果您体验过后觉得还不错的话,可以花两分钟用下面的一键部署脚本自己部署一套。
 | 
			
		||||
```shell
 | 
			
		||||
bash -c "$(curl -fsSL https://img.r9it.com/tmp/install-v3.2.3-8b588904ef.sh)"
 | 
			
		||||
```
 | 
			
		||||
目前仅支持 Ubuntu 和 Centos 系统。 部署成功之后可以访问下面地址
 | 
			
		||||
 | 
			
		||||
* 前端访问地址:http://localhost:8080/chat 使用移动设备访问会自动跳转到移动端页面。
 | 
			
		||||
* 后台管理地址:http://localhost:8080/admin
 | 
			
		||||
* 移动端地址:http://localhost:8080/mobile
 | 
			
		||||
* 初始后台管理账号:admin/admin123
 | 
			
		||||
* 初始前端体验账号:18575670125/12345678
 | 
			
		||||
 | 
			
		||||
服务启动成功之后不能立刻使用,需要先登录管理后台 -> API-KEY 去添加一个 OpenAI 或者文心一言,科大讯飞等至少一个平台的 API KEY。
 | 
			
		||||
 | 
			
		||||

 | 
			
		||||
 | 
			
		||||
另外,如果您目前还没有 OpenAI 的 API KEY的,推荐您去 https://gpt.bemore.lol 购买,**无需魔法,高速稳定,且价格还远低于 OpenAI 官方**。
 | 
			
		||||
 | 
			
		||||
## 使用须知
 | 
			
		||||
 | 
			
		||||
1. 本项目基于 MIT 协议,免费开放全部源代码,可以作为个人学习使用或者商用。
 | 
			
		||||
 
 | 
			
		||||
@@ -24,6 +24,15 @@ type AppConfig struct {
 | 
			
		||||
	XXLConfig     XXLConfig
 | 
			
		||||
	AlipayConfig  AlipayConfig
 | 
			
		||||
	HuPiPayConfig HuPiPayConfig
 | 
			
		||||
	SmtpConfig    SmtpConfig // 邮件发送配置
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type SmtpConfig struct {
 | 
			
		||||
	Host     string
 | 
			
		||||
	Port     int
 | 
			
		||||
	AppName  string // 应用名称
 | 
			
		||||
	From     string // 发件人邮箱地址
 | 
			
		||||
	Password string // 发件人邮箱密码
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type ChatPlusApiConfig struct {
 | 
			
		||||
 
 | 
			
		||||
@@ -46,7 +46,7 @@ func (h *RewardHandler) List(c *gin.Context) {
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			r.Id = v.Id
 | 
			
		||||
			r.Username = userMap[v.UserId].Mobile
 | 
			
		||||
			r.Username = userMap[v.UserId].Username
 | 
			
		||||
			r.CreatedAt = v.CreatedAt.Unix()
 | 
			
		||||
			r.UpdatedAt = v.UpdatedAt.Unix()
 | 
			
		||||
			rewards = append(rewards, r)
 | 
			
		||||
 
 | 
			
		||||
@@ -27,7 +27,7 @@ func NewUserHandler(app *core.AppServer, db *gorm.DB) *UserHandler {
 | 
			
		||||
func (h *UserHandler) List(c *gin.Context) {
 | 
			
		||||
	page := h.GetInt(c, "page", 1)
 | 
			
		||||
	pageSize := h.GetInt(c, "page_size", 20)
 | 
			
		||||
	mobile := h.GetTrim(c, "mobile")
 | 
			
		||||
	username := h.GetTrim(c, "username")
 | 
			
		||||
 | 
			
		||||
	offset := (page - 1) * pageSize
 | 
			
		||||
	var items []model.User
 | 
			
		||||
@@ -35,8 +35,8 @@ func (h *UserHandler) List(c *gin.Context) {
 | 
			
		||||
	var total int64
 | 
			
		||||
 | 
			
		||||
	session := h.db.Session(&gorm.Session{})
 | 
			
		||||
	if mobile != "" {
 | 
			
		||||
		session = session.Where("mobile LIKE ?", "%"+mobile+"%")
 | 
			
		||||
	if username != "" {
 | 
			
		||||
		session = session.Where("username LIKE ?", "%"+username+"%")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	session.Model(&model.User{}).Count(&total)
 | 
			
		||||
@@ -95,7 +95,7 @@ func (h *UserHandler) Save(c *gin.Context) {
 | 
			
		||||
	} else {
 | 
			
		||||
		salt := utils.RandString(8)
 | 
			
		||||
		u := model.User{
 | 
			
		||||
			Mobile:      data.Mobile,
 | 
			
		||||
			Username:    data.Mobile,
 | 
			
		||||
			Password:    utils.GenPassword(data.Password, salt),
 | 
			
		||||
			Avatar:      "/images/avatar/user.png",
 | 
			
		||||
			Salt:        salt,
 | 
			
		||||
 
 | 
			
		||||
@@ -80,7 +80,7 @@ func (h *ChatHandler) ChatHandle(c *gin.Context) {
 | 
			
		||||
		session = &types.ChatSession{
 | 
			
		||||
			SessionId: sessionId,
 | 
			
		||||
			ClientIP:  c.ClientIP(),
 | 
			
		||||
			Username:  user.Mobile,
 | 
			
		||||
			Username:  user.Username,
 | 
			
		||||
			UserId:    user.Id,
 | 
			
		||||
		}
 | 
			
		||||
		h.App.ChatSession.Put(sessionId, session)
 | 
			
		||||
 
 | 
			
		||||
@@ -204,7 +204,7 @@ func (h *PaymentHandler) PayQrcode(c *gin.Context) {
 | 
			
		||||
	}
 | 
			
		||||
	order := model.Order{
 | 
			
		||||
		UserId:    user.Id,
 | 
			
		||||
		Mobile:    user.Mobile,
 | 
			
		||||
		Mobile:    user.Username,
 | 
			
		||||
		ProductId: product.Id,
 | 
			
		||||
		OrderNo:   orderNo,
 | 
			
		||||
		Subject:   product.Name,
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,7 @@ import (
 | 
			
		||||
	"chatplus/utils/resp"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	"github.com/go-redis/redis/v8"
 | 
			
		||||
	"strings"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const CodeStorePrefix = "/verify/codes/"
 | 
			
		||||
@@ -16,21 +17,27 @@ type SmsHandler struct {
 | 
			
		||||
	BaseHandler
 | 
			
		||||
	redis   *redis.Client
 | 
			
		||||
	sms     *service.AliYunSmsService
 | 
			
		||||
	smtp    *service.SmtpService
 | 
			
		||||
	captcha *service.CaptchaService
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewSmsHandler(app *core.AppServer, client *redis.Client, sms *service.AliYunSmsService, captcha *service.CaptchaService) *SmsHandler {
 | 
			
		||||
	handler := &SmsHandler{redis: client, sms: sms, captcha: captcha}
 | 
			
		||||
func NewSmsHandler(
 | 
			
		||||
	app *core.AppServer,
 | 
			
		||||
	client *redis.Client,
 | 
			
		||||
	sms *service.AliYunSmsService,
 | 
			
		||||
	smtp *service.SmtpService,
 | 
			
		||||
	captcha *service.CaptchaService) *SmsHandler {
 | 
			
		||||
	handler := &SmsHandler{redis: client, sms: sms, captcha: captcha, smtp: smtp}
 | 
			
		||||
	handler.App = app
 | 
			
		||||
	return handler
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SendCode 发送验证码短信
 | 
			
		||||
// SendCode 发送验证码
 | 
			
		||||
func (h *SmsHandler) SendCode(c *gin.Context) {
 | 
			
		||||
	var data struct {
 | 
			
		||||
		Mobile string `json:"mobile"`
 | 
			
		||||
		Key    string `json:"key"`
 | 
			
		||||
		Dots   string `json:"dots"`
 | 
			
		||||
		Receiver string `json:"receiver"` // 接收者
 | 
			
		||||
		Key      string `json:"key"`
 | 
			
		||||
		Dots     string `json:"dots"`
 | 
			
		||||
	}
 | 
			
		||||
	if err := c.ShouldBindJSON(&data); err != nil {
 | 
			
		||||
		resp.ERROR(c, types.InvalidArgs)
 | 
			
		||||
@@ -43,14 +50,19 @@ func (h *SmsHandler) SendCode(c *gin.Context) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	code := utils.RandomNumber(6)
 | 
			
		||||
	err := h.sms.SendVerifyCode(data.Mobile, code)
 | 
			
		||||
	var err error
 | 
			
		||||
	if strings.Contains(data.Receiver, "@") { // email
 | 
			
		||||
		err = h.smtp.SendVerifyCode(data.Receiver, code)
 | 
			
		||||
	} else {
 | 
			
		||||
		err = h.sms.SendVerifyCode(data.Receiver, code)
 | 
			
		||||
	}
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		resp.ERROR(c, err.Error())
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 存储验证码,等待后面注册验证
 | 
			
		||||
	_, err = h.redis.Set(c, CodeStorePrefix+data.Mobile, code, 0).Result()
 | 
			
		||||
	_, err = h.redis.Set(c, CodeStorePrefix+data.Receiver, code, 0).Result()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		resp.ERROR(c, "验证码保存失败")
 | 
			
		||||
		return
 | 
			
		||||
 
 | 
			
		||||
@@ -39,7 +39,7 @@ func NewUserHandler(
 | 
			
		||||
func (h *UserHandler) Register(c *gin.Context) {
 | 
			
		||||
	// parameters process
 | 
			
		||||
	var data struct {
 | 
			
		||||
		Mobile     string `json:"mobile"`
 | 
			
		||||
		Username   string `json:"username"`
 | 
			
		||||
		Password   string `json:"password"`
 | 
			
		||||
		Code       string `json:"code"`
 | 
			
		||||
		InviteCode string `json:"invite_code"`
 | 
			
		||||
@@ -49,21 +49,16 @@ func (h *UserHandler) Register(c *gin.Context) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	data.Password = strings.TrimSpace(data.Password)
 | 
			
		||||
 | 
			
		||||
	if len(data.Mobile) < 10 {
 | 
			
		||||
		resp.ERROR(c, "请输入合法的手机号")
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if len(data.Password) < 8 {
 | 
			
		||||
		resp.ERROR(c, "密码长度不能少于8个字符")
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 检查验证码
 | 
			
		||||
	key := CodeStorePrefix + data.Mobile
 | 
			
		||||
	key := CodeStorePrefix + data.Username
 | 
			
		||||
	code, err := h.redis.Get(c, key).Result()
 | 
			
		||||
	if err != nil || code != data.Code {
 | 
			
		||||
		resp.ERROR(c, "短信验证码错误")
 | 
			
		||||
		resp.ERROR(c, "验证码错误")
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -79,20 +74,20 @@ func (h *UserHandler) Register(c *gin.Context) {
 | 
			
		||||
 | 
			
		||||
	// check if the username is exists
 | 
			
		||||
	var item model.User
 | 
			
		||||
	res := h.db.Where("mobile = ?", data.Mobile).First(&item)
 | 
			
		||||
	res := h.db.Where("username = ?", data.Username).First(&item)
 | 
			
		||||
	if res.RowsAffected > 0 {
 | 
			
		||||
		resp.ERROR(c, "该手机号码已经被注册,请更换其他手机号")
 | 
			
		||||
		resp.ERROR(c, "该用户名已经被注册")
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	salt := utils.RandString(8)
 | 
			
		||||
	user := model.User{
 | 
			
		||||
		Username:   data.Username,
 | 
			
		||||
		Password:   utils.GenPassword(data.Password, salt),
 | 
			
		||||
		Nickname:   fmt.Sprintf("极客学长@%d", utils.RandomNumber(6)),
 | 
			
		||||
		Avatar:     "/images/avatar/user.png",
 | 
			
		||||
		Salt:       salt,
 | 
			
		||||
		Status:     true,
 | 
			
		||||
		Mobile:     data.Mobile,
 | 
			
		||||
		ChatRoles:  utils.JsonEncode([]string{"gpt"}),               // 默认只订阅通用助手角色
 | 
			
		||||
		ChatModels: utils.JsonEncode(h.App.SysConfig.DefaultModels), // 默认开通的模型
 | 
			
		||||
		ChatConfig: utils.JsonEncode(types.UserChatConfig{
 | 
			
		||||
@@ -105,6 +100,7 @@ func (h *UserHandler) Register(c *gin.Context) {
 | 
			
		||||
		Calls:    h.App.SysConfig.InitChatCalls,
 | 
			
		||||
		ImgCalls: h.App.SysConfig.InitImgCalls,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	res = h.db.Create(&user)
 | 
			
		||||
	if res.Error != nil {
 | 
			
		||||
		resp.ERROR(c, "保存数据失败")
 | 
			
		||||
@@ -127,7 +123,7 @@ func (h *UserHandler) Register(c *gin.Context) {
 | 
			
		||||
		h.db.Create(&model.InviteLog{
 | 
			
		||||
			InviterId:  inviteCode.UserId,
 | 
			
		||||
			UserId:     user.Id,
 | 
			
		||||
			Username:   user.Mobile,
 | 
			
		||||
			Username:   user.Username,
 | 
			
		||||
			InviteCode: inviteCode.Code,
 | 
			
		||||
			Reward:     utils.JsonEncode(types.InviteReward{ChatCalls: h.App.SysConfig.InviteChatCalls, ImgCalls: h.App.SysConfig.InviteImgCalls}),
 | 
			
		||||
		})
 | 
			
		||||
@@ -157,7 +153,7 @@ func (h *UserHandler) Register(c *gin.Context) {
 | 
			
		||||
// Login 用户登录
 | 
			
		||||
func (h *UserHandler) Login(c *gin.Context) {
 | 
			
		||||
	var data struct {
 | 
			
		||||
		Mobile   string `json:"username"`
 | 
			
		||||
		Username string `json:"username"`
 | 
			
		||||
		Password string `json:"password"`
 | 
			
		||||
	}
 | 
			
		||||
	if err := c.ShouldBindJSON(&data); err != nil {
 | 
			
		||||
@@ -165,7 +161,7 @@ func (h *UserHandler) Login(c *gin.Context) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	var user model.User
 | 
			
		||||
	res := h.db.Where("mobile = ?", data.Mobile).First(&user)
 | 
			
		||||
	res := h.db.Where("username = ?", data.Username).First(&user)
 | 
			
		||||
	if res.Error != nil {
 | 
			
		||||
		resp.ERROR(c, "用户名不存在")
 | 
			
		||||
		return
 | 
			
		||||
@@ -189,7 +185,7 @@ func (h *UserHandler) Login(c *gin.Context) {
 | 
			
		||||
 | 
			
		||||
	h.db.Create(&model.UserLoginLog{
 | 
			
		||||
		UserId:       user.Id,
 | 
			
		||||
		Username:     user.Mobile,
 | 
			
		||||
		Username:     user.Username,
 | 
			
		||||
		LoginIp:      c.ClientIP(),
 | 
			
		||||
		LoginAddress: utils.Ip2Region(h.searcher, c.ClientIP()),
 | 
			
		||||
	})
 | 
			
		||||
@@ -250,7 +246,7 @@ func (h *UserHandler) Session(c *gin.Context) {
 | 
			
		||||
type userProfile struct {
 | 
			
		||||
	Id          uint                 `json:"id"`
 | 
			
		||||
	Nickname    string               `json:"nickname"`
 | 
			
		||||
	Mobile      string               `json:"mobile"`
 | 
			
		||||
	Username    string               `json:"username"`
 | 
			
		||||
	Avatar      string               `json:"avatar"`
 | 
			
		||||
	ChatConfig  types.UserChatConfig `json:"chat_config"`
 | 
			
		||||
	Calls       int                  `json:"calls"`
 | 
			
		||||
@@ -348,9 +344,9 @@ func (h *UserHandler) UpdatePass(c *gin.Context) {
 | 
			
		||||
// ResetPass 重置密码
 | 
			
		||||
func (h *UserHandler) ResetPass(c *gin.Context) {
 | 
			
		||||
	var data struct {
 | 
			
		||||
		Mobile   string
 | 
			
		||||
		Code     string // 验证码
 | 
			
		||||
		Password string // 新密码
 | 
			
		||||
		Username string `json:"username"`
 | 
			
		||||
		Code     string `json:"code"`     // 验证码
 | 
			
		||||
		Password string `json:"password"` // 新密码
 | 
			
		||||
	}
 | 
			
		||||
	if err := c.ShouldBindJSON(&data); err != nil {
 | 
			
		||||
		resp.ERROR(c, types.InvalidArgs)
 | 
			
		||||
@@ -358,14 +354,14 @@ func (h *UserHandler) ResetPass(c *gin.Context) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var user model.User
 | 
			
		||||
	res := h.db.Where("mobile", data.Mobile).First(&user)
 | 
			
		||||
	res := h.db.Where("username", data.Username).First(&user)
 | 
			
		||||
	if res.Error != nil {
 | 
			
		||||
		resp.ERROR(c, "用户不存在!")
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 检查验证码
 | 
			
		||||
	key := CodeStorePrefix + data.Mobile
 | 
			
		||||
	key := CodeStorePrefix + data.Username
 | 
			
		||||
	code, err := h.redis.Get(c, key).Result()
 | 
			
		||||
	if err != nil || code != data.Code {
 | 
			
		||||
		resp.ERROR(c, "短信验证码错误")
 | 
			
		||||
@@ -386,8 +382,8 @@ func (h *UserHandler) ResetPass(c *gin.Context) {
 | 
			
		||||
// BindMobile 绑定手机号
 | 
			
		||||
func (h *UserHandler) BindMobile(c *gin.Context) {
 | 
			
		||||
	var data struct {
 | 
			
		||||
		Mobile string `json:"mobile"`
 | 
			
		||||
		Code   string `json:"code"`
 | 
			
		||||
		Username string `json:"username"`
 | 
			
		||||
		Code     string `json:"code"`
 | 
			
		||||
	}
 | 
			
		||||
	if err := c.ShouldBindJSON(&data); err != nil {
 | 
			
		||||
		resp.ERROR(c, types.InvalidArgs)
 | 
			
		||||
@@ -395,7 +391,7 @@ func (h *UserHandler) BindMobile(c *gin.Context) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 检查验证码
 | 
			
		||||
	key := CodeStorePrefix + data.Mobile
 | 
			
		||||
	key := CodeStorePrefix + data.Username
 | 
			
		||||
	code, err := h.redis.Get(c, key).Result()
 | 
			
		||||
	if err != nil || code != data.Code {
 | 
			
		||||
		resp.ERROR(c, "短信验证码错误")
 | 
			
		||||
@@ -404,7 +400,7 @@ func (h *UserHandler) BindMobile(c *gin.Context) {
 | 
			
		||||
 | 
			
		||||
	// 检查手机号是否被其他账号绑定
 | 
			
		||||
	var item model.User
 | 
			
		||||
	res := h.db.Where("mobile = ?", data.Mobile).First(&item)
 | 
			
		||||
	res := h.db.Where("username = ?", data.Username).First(&item)
 | 
			
		||||
	if res.Error == nil {
 | 
			
		||||
		resp.ERROR(c, "该手机号已经被其他账号绑定")
 | 
			
		||||
		return
 | 
			
		||||
@@ -416,7 +412,7 @@ func (h *UserHandler) BindMobile(c *gin.Context) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	res = h.db.Model(&user).UpdateColumn("mobile", data.Mobile)
 | 
			
		||||
	res = h.db.Model(&user).UpdateColumn("username", data.Username)
 | 
			
		||||
	if res.Error != nil {
 | 
			
		||||
		resp.ERROR(c, "更新数据库失败")
 | 
			
		||||
		return
 | 
			
		||||
 
 | 
			
		||||
@@ -142,6 +142,9 @@ func main() {
 | 
			
		||||
		fx.Provide(oss.NewUploaderManager),
 | 
			
		||||
		fx.Provide(mj.NewService),
 | 
			
		||||
 | 
			
		||||
		// 邮件服务
 | 
			
		||||
		fx.Provide(service.NewSmtpService),
 | 
			
		||||
 | 
			
		||||
		// 微信机器人服务
 | 
			
		||||
		fx.Provide(wx.NewWeChatBot),
 | 
			
		||||
		fx.Invoke(func(config *types.AppConfig, bot *wx.Bot) {
 | 
			
		||||
 
 | 
			
		||||
@@ -49,3 +49,5 @@ func (s *AliYunSmsService) SendVerifyCode(mobile string, code int) error {
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var _ SmsService = &AliYunSmsService{}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										44
									
								
								api/service/smtp_sms_service.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								api/service/smtp_sms_service.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,44 @@
 | 
			
		||||
package service
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"bytes"
 | 
			
		||||
	"chatplus/core/types"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"mime"
 | 
			
		||||
	"net/smtp"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type SmtpService struct {
 | 
			
		||||
	config *types.SmtpConfig
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewSmtpService(appConfig *types.AppConfig) *SmtpService {
 | 
			
		||||
	return &SmtpService{
 | 
			
		||||
		config: &appConfig.SmtpConfig,
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s *SmtpService) SendVerifyCode(to string, code int) error {
 | 
			
		||||
	subject := "ChatPlus注册验证码"
 | 
			
		||||
	body := fmt.Sprintf("您正在注册 ChatPlus AI 助手账户,注册验证码为 %d,请不要告诉他人。如非本人操作,请忽略此邮件。", code)
 | 
			
		||||
 | 
			
		||||
	// 设置SMTP客户端配置
 | 
			
		||||
	auth := smtp.PlainAuth("", s.config.From, s.config.Password, s.config.Host)
 | 
			
		||||
 | 
			
		||||
	// 对主题进行MIME编码
 | 
			
		||||
	encodedSubject := mime.QEncoding.Encode("UTF-8", subject)
 | 
			
		||||
	// 组装邮件
 | 
			
		||||
	message := bytes.NewBuffer(nil)
 | 
			
		||||
	message.WriteString(fmt.Sprintf("From: \"%s\" <%s>\r\n", s.config.AppName, s.config.From))
 | 
			
		||||
	message.WriteString(fmt.Sprintf("To: %s\r\n", to))
 | 
			
		||||
	message.WriteString(fmt.Sprintf("Subject: %s\r\n", encodedSubject))
 | 
			
		||||
	message.WriteString("\r\n" + body)
 | 
			
		||||
 | 
			
		||||
	// 发送邮件
 | 
			
		||||
	// 发送邮件
 | 
			
		||||
	err := smtp.SendMail(s.config.Host+":"+fmt.Sprint(s.config.Port), auth, s.config.From, []string{to}, message.Bytes())
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return fmt.Errorf("error sending email: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
@@ -96,7 +96,7 @@ func (e *XXLJobExecutor) ResetVipCalls(cxt context.Context, param *xxl.RunReq) (
 | 
			
		||||
	for _, u := range users {
 | 
			
		||||
		// 账号到期,直接清零
 | 
			
		||||
		if u.ExpiredTime <= currentTime.Unix() {
 | 
			
		||||
			logger.Info("账号过期:", u.Mobile)
 | 
			
		||||
			logger.Info("账号过期:", u.Username)
 | 
			
		||||
			u.Calls = 0
 | 
			
		||||
			u.Vip = false
 | 
			
		||||
		} else {
 | 
			
		||||
@@ -133,7 +133,7 @@ func (e *XXLJobExecutor) ResetVipCalls(cxt context.Context, param *xxl.RunReq) (
 | 
			
		||||
			} else {
 | 
			
		||||
				u.ImgCalls = u.ImgCalls + config.VipMonthImgCalls
 | 
			
		||||
			}
 | 
			
		||||
			logger.Infof("%s 点卡结余:%d", u.Mobile, calls)
 | 
			
		||||
			logger.Infof("%s 点卡结余:%d", u.Username, calls)
 | 
			
		||||
		}
 | 
			
		||||
		u.Tokens = 0
 | 
			
		||||
		// update user
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@ package model
 | 
			
		||||
 | 
			
		||||
type User struct {
 | 
			
		||||
	BaseModel
 | 
			
		||||
	Mobile      string
 | 
			
		||||
	Username    string
 | 
			
		||||
	Nickname    string
 | 
			
		||||
	Password    string
 | 
			
		||||
	Avatar      string
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ import "chatplus/core/types"
 | 
			
		||||
 | 
			
		||||
type User struct {
 | 
			
		||||
	BaseVo
 | 
			
		||||
	Mobile      string               `json:"mobile"`
 | 
			
		||||
	Username    string               `json:"username"`
 | 
			
		||||
	Nickname    string               `json:"nickname"`
 | 
			
		||||
	Avatar      string               `json:"avatar"`
 | 
			
		||||
	Salt        string               `json:"salt"`         // 密码盐
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,5 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"chatplus/utils"
 | 
			
		||||
	"fmt"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	fmt.Println(utils.RandString(64))
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -5,4 +5,4 @@ ALTER TABLE `chatgpt_api_keys` DROP INDEX `value`;
 | 
			
		||||
ALTER TABLE `chatgpt_mj_jobs` ADD UNIQUE(`task_id`);
 | 
			
		||||
ALTER TABLE `chatgpt_api_keys` ADD `use_proxy` TINYINT(1) NULL COMMENT '是否使用代理访问' AFTER `enabled`;
 | 
			
		||||
ALTER TABLE `chatgpt_api_keys` ADD `name` VARCHAR(30) NULL COMMENT '名称' AFTER `platform`;
 | 
			
		||||
ALTER TABLE `chatgpt_users` ADD `email` VARCHAR(100) NULL COMMENT '邮箱地址' AFTER `mobile`;
 | 
			
		||||
ALTER TABLE `chatgpt_users` CHANGE `mobile` `username` VARCHAR(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '用户名';
 | 
			
		||||
@@ -10,7 +10,7 @@
 | 
			
		||||
    <div class="user-info" id="user-info">
 | 
			
		||||
      <el-form v-if="user.id" :model="user" label-width="150px">
 | 
			
		||||
        <el-form-item label="账户">
 | 
			
		||||
          <span>{{ user.mobile }}</span>
 | 
			
		||||
          <span>{{ user.username }}</span>
 | 
			
		||||
        </el-form-item>
 | 
			
		||||
        <el-form-item label="剩余对话次数">
 | 
			
		||||
          <el-tag>{{ user['calls'] }}</el-tag>
 | 
			
		||||
@@ -54,17 +54,14 @@ const user = ref({
 | 
			
		||||
  username: '',
 | 
			
		||||
  nickname: '',
 | 
			
		||||
  avatar: '',
 | 
			
		||||
  mobile: '',
 | 
			
		||||
  calls: 0,
 | 
			
		||||
  tokens: 0,
 | 
			
		||||
  chat_config: {api_keys: {OpenAI: "", Azure: "", ChatGLM: ""}}
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
onMounted(() => {
 | 
			
		||||
  // 获取最新用户信息
 | 
			
		||||
  httpGet('/api/user/profile').then(res => {
 | 
			
		||||
    user.value = res.data
 | 
			
		||||
    user.value.chat_config.api_keys = res.data.chat_config.api_keys ?? {OpenAI: "", Azure: "", ChatGLM: ""}
 | 
			
		||||
  }).catch(e => {
 | 
			
		||||
    ElMessage.error("获取用户信息失败:" + e.message)
 | 
			
		||||
  });
 | 
			
		||||
 
 | 
			
		||||
@@ -7,21 +7,21 @@
 | 
			
		||||
      :title="title"
 | 
			
		||||
  >
 | 
			
		||||
    <div class="form" id="bind-mobile-form">
 | 
			
		||||
      <el-alert v-if="mobile !== ''" type="info" show-icon :closable="false" style="margin-bottom: 20px;">
 | 
			
		||||
        <p>当前用户已绑定手机号:{{ mobile }}, 绑定其他手机号之后自动解绑该手机号。</p>
 | 
			
		||||
      <el-alert v-if="username !== ''" type="info" show-icon :closable="false" style="margin-bottom: 20px;">
 | 
			
		||||
        <p>当前绑定账号:{{ username }},只允许使绑定有效的手机号或者邮箱地址作为登录账号。</p>
 | 
			
		||||
      </el-alert>
 | 
			
		||||
 | 
			
		||||
      <el-form :model="form" label-width="120px">
 | 
			
		||||
        <el-form-item label="手机号码">
 | 
			
		||||
          <el-input v-model="form.mobile"/>
 | 
			
		||||
        <el-form-item label="新账号">
 | 
			
		||||
          <el-input v-model="form.username"/>
 | 
			
		||||
        </el-form-item>
 | 
			
		||||
        <el-form-item label="手机验证码">
 | 
			
		||||
        <el-form-item label="验证码">
 | 
			
		||||
          <el-row :gutter="20">
 | 
			
		||||
            <el-col :span="16">
 | 
			
		||||
              <el-input v-model="form.code" maxlength="6"/>
 | 
			
		||||
            </el-col>
 | 
			
		||||
            <el-col :span="8">
 | 
			
		||||
              <send-msg size="" :mobile="form.mobile"/>
 | 
			
		||||
              <send-msg size="" :receiver="form.username"/>
 | 
			
		||||
            </el-col>
 | 
			
		||||
          </el-row>
 | 
			
		||||
        </el-form-item>
 | 
			
		||||
@@ -43,37 +43,36 @@ import {computed, ref} from "vue";
 | 
			
		||||
import SendMsg from "@/components/SendMsg.vue";
 | 
			
		||||
import {ElMessage} from "element-plus";
 | 
			
		||||
import {httpPost} from "@/utils/http";
 | 
			
		||||
import {validateMobile} from "@/utils/validate";
 | 
			
		||||
import {validateEmail, validateMobile} from "@/utils/validate";
 | 
			
		||||
 | 
			
		||||
const props = defineProps({
 | 
			
		||||
  show: Boolean,
 | 
			
		||||
  mobile: String
 | 
			
		||||
  username: String
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const showDialog = computed(() => {
 | 
			
		||||
  return props.show
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
const title = ref('绑定手机号')
 | 
			
		||||
const title = ref('重置登录账号')
 | 
			
		||||
const form = ref({
 | 
			
		||||
  mobile: '',
 | 
			
		||||
  username: '',
 | 
			
		||||
  code: ''
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
const emits = defineEmits(['hide']);
 | 
			
		||||
 | 
			
		||||
const save = () => {
 | 
			
		||||
  if (!validateMobile(form.value.mobile)) {
 | 
			
		||||
    return ElMessage.error("请输入正确的手机号码");
 | 
			
		||||
  if (!validateMobile(form.value.username) && !validateEmail(form.value.username)) {
 | 
			
		||||
    return ElMessage.error("请输入合法的手机号/邮箱地址")
 | 
			
		||||
  }
 | 
			
		||||
  if (form.value.code === '') {
 | 
			
		||||
    return ElMessage.error("请输入短信验证码");
 | 
			
		||||
    return ElMessage.error("请输入验证码");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  httpPost('/api/user/bind/mobile', form.value).then(() => {
 | 
			
		||||
  httpPost('/api/user/bind/username', form.value).then(() => {
 | 
			
		||||
    ElMessage.success({
 | 
			
		||||
      message: '绑定成功',
 | 
			
		||||
      appendTo: '#bind-mobile-form',
 | 
			
		||||
      duration: 1000,
 | 
			
		||||
      onClose: () => emits('hide', false)
 | 
			
		||||
    })
 | 
			
		||||
@@ -10,16 +10,16 @@
 | 
			
		||||
      <div class="form">
 | 
			
		||||
 | 
			
		||||
        <el-form :model="form" label-width="120px" label-position="left">
 | 
			
		||||
          <el-form-item label="手机号码">
 | 
			
		||||
            <el-input v-model="form.mobile"/>
 | 
			
		||||
          <el-form-item label="用户名">
 | 
			
		||||
            <el-input v-model="form.username" placeholder="手机号/邮箱地址"/>
 | 
			
		||||
          </el-form-item>
 | 
			
		||||
          <el-form-item label="手机验证码">
 | 
			
		||||
          <el-form-item label="验证码">
 | 
			
		||||
            <el-row :gutter="20">
 | 
			
		||||
              <el-col :span="16">
 | 
			
		||||
                <el-input v-model="form.code" maxlength="6"/>
 | 
			
		||||
              </el-col>
 | 
			
		||||
              <el-col :span="8">
 | 
			
		||||
                <send-msg size="" :mobile="form.mobile"/>
 | 
			
		||||
                <send-msg size="" :receiver="form.username"/>
 | 
			
		||||
              </el-col>
 | 
			
		||||
            </el-row>
 | 
			
		||||
          </el-form-item>
 | 
			
		||||
@@ -48,7 +48,7 @@ import {computed, ref} from "vue";
 | 
			
		||||
import SendMsg from "@/components/SendMsg.vue";
 | 
			
		||||
import {ElMessage} from "element-plus";
 | 
			
		||||
import {httpPost} from "@/utils/http";
 | 
			
		||||
import {validateMobile} from "@/utils/validate";
 | 
			
		||||
import {validateEmail, validateMobile} from "@/utils/validate";
 | 
			
		||||
 | 
			
		||||
const props = defineProps({
 | 
			
		||||
  show: Boolean,
 | 
			
		||||
@@ -61,7 +61,7 @@ const showDialog = computed(() => {
 | 
			
		||||
 | 
			
		||||
const title = ref('重置密码')
 | 
			
		||||
const form = ref({
 | 
			
		||||
  mobile: '',
 | 
			
		||||
  username: '',
 | 
			
		||||
  code: '',
 | 
			
		||||
  password: '',
 | 
			
		||||
  repass: ''
 | 
			
		||||
@@ -70,11 +70,11 @@ const form = ref({
 | 
			
		||||
const emits = defineEmits(['hide']);
 | 
			
		||||
 | 
			
		||||
const save = () => {
 | 
			
		||||
  if (!validateMobile(form.value.mobile)) {
 | 
			
		||||
    return ElMessage.error("请输入正确的手机号码");
 | 
			
		||||
  if (!validateMobile(form.value.username) && !validateEmail(form.value.username)) {
 | 
			
		||||
    return ElMessage.error("请输入正确的手机号码/邮箱地址");
 | 
			
		||||
  }
 | 
			
		||||
  if (form.value.code === '') {
 | 
			
		||||
    return ElMessage.error("请输入短信验证码");
 | 
			
		||||
    return ElMessage.error("请输入验证码");
 | 
			
		||||
  }
 | 
			
		||||
  if (form.value.repass !== form.value.password) {
 | 
			
		||||
    return ElMessage.error("两次输入密码不一致");
 | 
			
		||||
 
 | 
			
		||||
@@ -28,13 +28,13 @@
 | 
			
		||||
// 发送短信验证码组件
 | 
			
		||||
import {ref} from "vue";
 | 
			
		||||
import lodash from 'lodash'
 | 
			
		||||
import {validateMobile} from "@/utils/validate";
 | 
			
		||||
import {validateEmail, validateMobile} from "@/utils/validate";
 | 
			
		||||
import {ElMessage} from "element-plus";
 | 
			
		||||
import {httpGet, httpPost} from "@/utils/http";
 | 
			
		||||
import CaptchaPlus from "@/components/CaptchaPlus.vue";
 | 
			
		||||
 | 
			
		||||
const props = defineProps({
 | 
			
		||||
  mobile: String,
 | 
			
		||||
  receiver: String,
 | 
			
		||||
  size: String,
 | 
			
		||||
});
 | 
			
		||||
const btnText = ref('发送验证码')
 | 
			
		||||
@@ -82,8 +82,8 @@ const handleConfirm = (dots) => {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const loadCaptcha = () => {
 | 
			
		||||
  if (!validateMobile(props.mobile)) {
 | 
			
		||||
    return ElMessage.error("请输入合法的手机号")
 | 
			
		||||
  if (!validateMobile(props.receiver) && !validateEmail(props.receiver)) {
 | 
			
		||||
    return ElMessage.error("请输入合法的手机号/邮箱地址")
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  showCaptcha.value = true
 | 
			
		||||
@@ -96,8 +96,8 @@ const sendMsg = () => {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  canSend.value = false
 | 
			
		||||
  httpPost('/api/sms/code', {mobile: props.mobile, key: captKey.value, dots: dots.value}).then(() => {
 | 
			
		||||
    ElMessage.success('短信发送成功')
 | 
			
		||||
  httpPost('/api/sms/code', {receiver: props.receiver, key: captKey.value, dots: dots.value}).then(() => {
 | 
			
		||||
    ElMessage.success('验证码发送成功')
 | 
			
		||||
    let time = 120
 | 
			
		||||
    btnText.value = time
 | 
			
		||||
    const handler = setInterval(() => {
 | 
			
		||||
@@ -112,7 +112,7 @@ const sendMsg = () => {
 | 
			
		||||
    }, 1000)
 | 
			
		||||
  }).catch(e => {
 | 
			
		||||
    canSend.value = true
 | 
			
		||||
    ElMessage.error('短信发送失败:' + e.message)
 | 
			
		||||
    ElMessage.error('验证码发送失败:' + e.message)
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -17,8 +17,8 @@
 | 
			
		||||
      <el-form-item label="昵称">
 | 
			
		||||
        <el-input v-model="user['nickname']"/>
 | 
			
		||||
      </el-form-item>
 | 
			
		||||
      <el-form-item label="手机号">
 | 
			
		||||
        <span>{{ user.mobile }}</span>
 | 
			
		||||
      <el-form-item label="账号">
 | 
			
		||||
        <span>{{ user.username }}</span>
 | 
			
		||||
        <el-tooltip
 | 
			
		||||
            class="box-item"
 | 
			
		||||
            effect="light"
 | 
			
		||||
 
 | 
			
		||||
@@ -1,74 +0,0 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <van-dialog v-model:show="showDialog"
 | 
			
		||||
              :title="title"
 | 
			
		||||
              :show-cancel-button="mobile !== ''"
 | 
			
		||||
              @confirm="save"
 | 
			
		||||
              @cancel="close">
 | 
			
		||||
    <van-cell-group inset>
 | 
			
		||||
      <van-field
 | 
			
		||||
          v-model="form.mobile"
 | 
			
		||||
          label="手机号"
 | 
			
		||||
          placeholder="请输入手机号"
 | 
			
		||||
      />
 | 
			
		||||
      <van-field
 | 
			
		||||
          v-model.number="form.code"
 | 
			
		||||
          center
 | 
			
		||||
          clearable
 | 
			
		||||
          label="短信验证码"
 | 
			
		||||
          placeholder="请输入短信验证码"
 | 
			
		||||
      >
 | 
			
		||||
        <template #button>
 | 
			
		||||
          <send-msg size="small" :mobile="form.mobile"/>
 | 
			
		||||
        </template>
 | 
			
		||||
      </van-field>
 | 
			
		||||
    </van-cell-group>
 | 
			
		||||
  </van-dialog>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script setup>
 | 
			
		||||
import {computed, ref} from "vue";
 | 
			
		||||
import {httpPost} from "@/utils/http";
 | 
			
		||||
import {validateMobile} from "@/utils/validate";
 | 
			
		||||
import {showNotify} from "vant";
 | 
			
		||||
import SendMsg from "@/components/SendMsg.vue";
 | 
			
		||||
 | 
			
		||||
const props = defineProps({
 | 
			
		||||
  show: Boolean,
 | 
			
		||||
  mobile: String
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const showDialog = computed(() => {
 | 
			
		||||
  return props.show
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
const title = ref('绑定手机号')
 | 
			
		||||
const form = ref({
 | 
			
		||||
  mobile: '',
 | 
			
		||||
  code: ''
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
const emits = defineEmits(['hide']);
 | 
			
		||||
 | 
			
		||||
const save = () => {
 | 
			
		||||
  if (!validateMobile(form.value.mobile)) {
 | 
			
		||||
    return showNotify({type: 'danger', message: '请输入正确的手机号码'});
 | 
			
		||||
  }
 | 
			
		||||
  if (form.value.code === '') {
 | 
			
		||||
    return showNotify({type: "danger", message: '请输入短信验证码'})
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  httpPost('/api/user/bind/mobile', form.value).then(() => {
 | 
			
		||||
    showNotify({type: 'success', message: '绑定成功', duration: 1000, onClose: emits('hide', false)});
 | 
			
		||||
  }).catch(e => {
 | 
			
		||||
    showNotify({type: 'danger', message: '绑定失败:' + e.message, duration: 2000});
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const close = function () {
 | 
			
		||||
  emits('hide', false);
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style scoped>
 | 
			
		||||
 | 
			
		||||
</style>
 | 
			
		||||
@@ -84,6 +84,10 @@ export function dateFormat(timestamp, format) {
 | 
			
		||||
 | 
			
		||||
// 判断数组中是否包含某个元素
 | 
			
		||||
export function arrayContains(array, value, compare) {
 | 
			
		||||
    if (!array) {
 | 
			
		||||
        return false
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (typeof compare !== 'function') {
 | 
			
		||||
        compare = function (v1, v2) {
 | 
			
		||||
            return v1 === v2;
 | 
			
		||||
 
 | 
			
		||||
@@ -231,12 +231,17 @@
 | 
			
		||||
      <div class="notice">
 | 
			
		||||
        <el-text type="primary">
 | 
			
		||||
          注意:当前站点仅为开源项目
 | 
			
		||||
          <a style="color: #F56C6C" href="https://github.com/yangjian102621/chatgpt-plus">ChatPlus</a>
 | 
			
		||||
          <a style="color: #F56C6C" href="https://github.com/yangjian102621/chatgpt-plus" target="_blank">ChatPlus</a>
 | 
			
		||||
          的演示项目,本项目单纯就是给大家体验项目功能使用。<br/>
 | 
			
		||||
 | 
			
		||||
          体验额度用完之后请不要在当前站点进行任何充值操作!!!<br/>
 | 
			
		||||
          体验额度用完之后请不要在当前站点进行任何充值操作!!!<br/>
 | 
			
		||||
          体验额度用完之后请不要在当前站点进行任何充值操作!!!<br/>
 | 
			
		||||
 | 
			
		||||
          如果觉得好用你就花几分钟自己部署一套,没有API KEY 的同学可以去
 | 
			
		||||
          <a href="https://gpt.bemore.lol" target="_blank"
 | 
			
		||||
             style="font-size: 20px;color:#F56C6C">https://gpt.bemore.lol</a>
 | 
			
		||||
          购买,现在有超级优惠,价格远低于 OpenAI 官方。
 | 
			
		||||
        </el-text>
 | 
			
		||||
 | 
			
		||||
        <p style="text-align: right">
 | 
			
		||||
@@ -350,7 +355,7 @@ onMounted(() => {
 | 
			
		||||
 | 
			
		||||
    httpGet("/api/admin/config/get?key=system").then(res => {
 | 
			
		||||
      title.value = res.data.title
 | 
			
		||||
      const show = localStorage.getItem(showNoticeKey.value + loginUser.value.mobile)
 | 
			
		||||
      const show = localStorage.getItem(showNoticeKey.value + loginUser.value.username)
 | 
			
		||||
      if (!show) {
 | 
			
		||||
        showDemoNotice.value = res.data['show_demo_notice']
 | 
			
		||||
      }
 | 
			
		||||
@@ -878,7 +883,7 @@ const getModelValue = (model_id) => {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const notShow = () => {
 | 
			
		||||
  localStorage.setItem(showNoticeKey.value + loginUser.value.mobile, true)
 | 
			
		||||
  localStorage.setItem(showNoticeKey.value + loginUser.value.username, true)
 | 
			
		||||
  showDemoNotice.value = false
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 
 | 
			
		||||
@@ -2,9 +2,7 @@
 | 
			
		||||
  <div class="home">
 | 
			
		||||
    <div class="navigator">
 | 
			
		||||
      <div class="logo">
 | 
			
		||||
        <el-link href="/">
 | 
			
		||||
          <el-image :src="logo"/>
 | 
			
		||||
        </el-link>
 | 
			
		||||
        <el-image :src="logo"/>
 | 
			
		||||
        <div class="divider"></div>
 | 
			
		||||
      </div>
 | 
			
		||||
      <ul class="nav-items">
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,7 @@
 | 
			
		||||
        <div class="header">{{ title }}</div>
 | 
			
		||||
        <div class="content">
 | 
			
		||||
          <div class="block">
 | 
			
		||||
            <el-input placeholder="手机号" size="large" maxlength="11" v-model="username" autocomplete="off">
 | 
			
		||||
            <el-input placeholder="手机号/邮箱地址" size="large" v-model="username" autocomplete="off">
 | 
			
		||||
              <template #prefix>
 | 
			
		||||
                <el-icon>
 | 
			
		||||
                  <UserFilled/>
 | 
			
		||||
@@ -59,7 +59,7 @@ import FooterBar from "@/components/FooterBar.vue";
 | 
			
		||||
import {isMobile} from "@/utils/libs";
 | 
			
		||||
import {checkSession} from "@/action/session";
 | 
			
		||||
import {setUserToken} from "@/store/session";
 | 
			
		||||
import {validateMobile} from "@/utils/validate";
 | 
			
		||||
import {validateEmail, validateMobile} from "@/utils/validate";
 | 
			
		||||
import {prevRoute} from "@/router";
 | 
			
		||||
import ResetPass from "@/components/ResetPass.vue";
 | 
			
		||||
 | 
			
		||||
@@ -92,8 +92,8 @@ onUnmounted(() => {
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
const login = function () {
 | 
			
		||||
  if (!validateMobile(username.value)) {
 | 
			
		||||
    return ElMessage.error('请输入合法的手机号');
 | 
			
		||||
  if (!validateMobile(username.value) && !validateEmail(username.value)) {
 | 
			
		||||
    return ElMessage.error("请输入合法的手机号/邮箱地址")
 | 
			
		||||
  }
 | 
			
		||||
  if (password.value.trim() === '') {
 | 
			
		||||
    return ElMessage.error('请输入密码');
 | 
			
		||||
 
 | 
			
		||||
@@ -14,7 +14,7 @@
 | 
			
		||||
                <el-button type="primary" @click="showPasswordDialog = true">修改密码</el-button>
 | 
			
		||||
              </el-col>
 | 
			
		||||
              <el-col :span="12">
 | 
			
		||||
                <el-button type="primary" @click="showBindMobileDialog = true">绑定手机号</el-button>
 | 
			
		||||
                <el-button type="primary" @click="showBindMobileDialog = true">更改账号</el-button>
 | 
			
		||||
              </el-col>
 | 
			
		||||
              <el-col :span="12">
 | 
			
		||||
                <el-button type="primary" v-if="enableReward" @click="showRewardDialog = true">加入众筹</el-button>
 | 
			
		||||
@@ -93,7 +93,7 @@
 | 
			
		||||
    <password-dialog v-if="isLogin" :show="showPasswordDialog" @hide="showPasswordDialog = false"
 | 
			
		||||
                     @logout="logout"/>
 | 
			
		||||
 | 
			
		||||
    <bind-mobile v-if="isLogin" :show="showBindMobileDialog" :mobile="user.mobile"
 | 
			
		||||
    <bind-mobile v-if="isLogin" :show="showBindMobileDialog" :username="user.username"
 | 
			
		||||
                 @hide="showBindMobileDialog = false"/>
 | 
			
		||||
 | 
			
		||||
    <reward-verify v-if="isLogin" :show="showRewardVerifyDialog" @hide="showRewardVerifyDialog = false"/>
 | 
			
		||||
@@ -158,7 +158,7 @@ import LoginDialog from "@/components/LoginDialog.vue";
 | 
			
		||||
import {checkSession} from "@/action/session";
 | 
			
		||||
import UserProfile from "@/components/UserProfile.vue";
 | 
			
		||||
import PasswordDialog from "@/components/PasswordDialog.vue";
 | 
			
		||||
import BindMobile from "@/components/BindMobile.vue";
 | 
			
		||||
import BindMobile from "@/components/ResetAccount.vue";
 | 
			
		||||
import RewardVerify from "@/components/RewardVerify.vue";
 | 
			
		||||
import {useRouter} from "vue-router";
 | 
			
		||||
import {removeUserToken} from "@/store/session";
 | 
			
		||||
 
 | 
			
		||||
@@ -12,9 +12,9 @@
 | 
			
		||||
          <div class="content">
 | 
			
		||||
            <el-form :model="formData" label-width="120px" ref="formRef">
 | 
			
		||||
              <div class="block">
 | 
			
		||||
                <el-input placeholder="手机号码"
 | 
			
		||||
                          size="large" maxlength="11"
 | 
			
		||||
                          v-model="formData.mobile"
 | 
			
		||||
                <el-input :placeholder="placeholder"
 | 
			
		||||
                          size="large"
 | 
			
		||||
                          v-model="formData.username"
 | 
			
		||||
                          autocomplete="off">
 | 
			
		||||
                  <template #prefix>
 | 
			
		||||
                    <el-icon>
 | 
			
		||||
@@ -49,10 +49,10 @@
 | 
			
		||||
                </el-input>
 | 
			
		||||
              </div>
 | 
			
		||||
 | 
			
		||||
              <div class="block" v-if="enableMsg">
 | 
			
		||||
              <div class="block">
 | 
			
		||||
                <el-row :gutter="10">
 | 
			
		||||
                  <el-col :span="12">
 | 
			
		||||
                    <el-input placeholder="手机验证码"
 | 
			
		||||
                    <el-input placeholder="验证码"
 | 
			
		||||
                              size="large" maxlength="30"
 | 
			
		||||
                              v-model="formData.code"
 | 
			
		||||
                              autocomplete="off">
 | 
			
		||||
@@ -64,7 +64,7 @@
 | 
			
		||||
                    </el-input>
 | 
			
		||||
                  </el-col>
 | 
			
		||||
                  <el-col :span="12">
 | 
			
		||||
                    <send-msg size="large" :mobile="formData.mobile"/>
 | 
			
		||||
                    <send-msg size="large" :receiver="formData.username"/>
 | 
			
		||||
                  </el-col>
 | 
			
		||||
                </el-row>
 | 
			
		||||
              </div>
 | 
			
		||||
@@ -118,42 +118,44 @@
 | 
			
		||||
import {ref} from "vue";
 | 
			
		||||
import {Checked, Iphone, Lock, Message} from "@element-plus/icons-vue";
 | 
			
		||||
import {httpGet, httpPost} from "@/utils/http";
 | 
			
		||||
import {ElMessage, ElNotification} from "element-plus";
 | 
			
		||||
import {ElMessage} from "element-plus";
 | 
			
		||||
import {useRouter} from "vue-router";
 | 
			
		||||
import FooterBar from "@/components/FooterBar.vue";
 | 
			
		||||
import SendMsg from "@/components/SendMsg.vue";
 | 
			
		||||
import {validateMobile} from "@/utils/validate";
 | 
			
		||||
import {isMobile} from "@/utils/libs";
 | 
			
		||||
import {validateEmail, validateMobile} from "@/utils/validate";
 | 
			
		||||
import {arrayContains} from "@/utils/libs";
 | 
			
		||||
import {setUserToken} from "@/store/session";
 | 
			
		||||
import {checkSession} from "@/action/session";
 | 
			
		||||
 | 
			
		||||
const router = useRouter();
 | 
			
		||||
const title = ref('ChatPlus 用户注册');
 | 
			
		||||
const formData = ref({
 | 
			
		||||
  mobile: '',
 | 
			
		||||
  username: '',
 | 
			
		||||
  password: '',
 | 
			
		||||
  code: '',
 | 
			
		||||
  repass: '',
 | 
			
		||||
  invite_code: router.currentRoute.value.query['invite_code'],
 | 
			
		||||
})
 | 
			
		||||
const formRef = ref(null)
 | 
			
		||||
const enableMsg = ref(false)
 | 
			
		||||
const enableMobile = ref(false)
 | 
			
		||||
const enableEmail = ref(false)
 | 
			
		||||
const enableRegister = ref(true)
 | 
			
		||||
const wxImg = ref("/images/wx.png")
 | 
			
		||||
const ways = []
 | 
			
		||||
const placeholder = ref("用户名:")
 | 
			
		||||
 | 
			
		||||
httpGet("/api/admin/config/get?key=system").then(res => {
 | 
			
		||||
  if (res.data) {
 | 
			
		||||
    enableMsg.value = res.data['enabled_msg']
 | 
			
		||||
    enableRegister.value = res.data['enabled_register']
 | 
			
		||||
    if (res.data['force_invite'] && !formData.value.invite_code) {
 | 
			
		||||
      ElNotification({
 | 
			
		||||
        title: '提示:',
 | 
			
		||||
        dangerouslyUseHTMLString: true,
 | 
			
		||||
        message: '当前系统开启了强制邀请注册功能,必须有邀请码才能注册哦。扫描下面二维码获取邀请码。<br/> <img alt="qrcode" src="/images/wx.png" />',
 | 
			
		||||
        type: 'info',
 | 
			
		||||
        duration: 5000,
 | 
			
		||||
      })
 | 
			
		||||
    const registerWays = res.data['register_ways']
 | 
			
		||||
    if (arrayContains(registerWays, "mobile")) {
 | 
			
		||||
      enableMobile.value = true
 | 
			
		||||
      ways.push("手机号")
 | 
			
		||||
    }
 | 
			
		||||
    if (arrayContains(registerWays, "email")) {
 | 
			
		||||
      enableEmail.value = true
 | 
			
		||||
      ways.push("邮箱地址")
 | 
			
		||||
    }
 | 
			
		||||
    placeholder.value += ways.join("/")
 | 
			
		||||
  }
 | 
			
		||||
}).catch(e => {
 | 
			
		||||
  ElMessage.error("获取系统配置失败:" + e.message)
 | 
			
		||||
@@ -165,9 +167,19 @@ httpGet("/api/invite/hits", {code: formData.value.invite_code}).then(() => {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const register = function () {
 | 
			
		||||
  if (!validateMobile(formData.value.mobile)) {
 | 
			
		||||
  if (formData.value.username === '') {
 | 
			
		||||
    return ElMessage.error('请输入用户名');
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (!enableMobile.value && !validateEmail(formData.value.username)) {
 | 
			
		||||
    return ElMessage.error('请输入合法的邮箱地址');
 | 
			
		||||
  }
 | 
			
		||||
  if (!enableEmail.value && !validateMobile(formData.value.username)) {
 | 
			
		||||
    return ElMessage.error('请输入合法的手机号');
 | 
			
		||||
  }
 | 
			
		||||
  if (!validateMobile(formData.value.username) && !validateEmail(formData.value.username)) {
 | 
			
		||||
    return ElMessage.error('请输入合法的手机号或者邮箱地址');
 | 
			
		||||
  }
 | 
			
		||||
  if (formData.value.password.length < 8) {
 | 
			
		||||
    return ElMessage.error('密码的长度为8-16个字符');
 | 
			
		||||
  }
 | 
			
		||||
@@ -175,7 +187,7 @@ const register = function () {
 | 
			
		||||
    return ElMessage.error('两次输入密码不一致');
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (enableMsg.value && formData.value.code === '') {
 | 
			
		||||
  if (formData.value.code === '') {
 | 
			
		||||
    return ElMessage.error('请输入短信验证码');
 | 
			
		||||
  }
 | 
			
		||||
  httpPost('/api/user/register', formData.value).then((res) => {
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,9 @@
 | 
			
		||||
 | 
			
		||||
    <div class="handle-box">
 | 
			
		||||
      <el-button type="primary" :icon="Plus" @click="add">新增</el-button>
 | 
			
		||||
      <a href="https://gpt.bemore.lol" target="_blank" style="margin-left: 10px">
 | 
			
		||||
        <el-button type="success" :icon="ShoppingCart" @click="add" plain>购买API-KEY</el-button>
 | 
			
		||||
      </a>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    <el-row>
 | 
			
		||||
@@ -129,7 +132,7 @@ import {reactive, ref} from "vue";
 | 
			
		||||
import {httpGet, httpPost} from "@/utils/http";
 | 
			
		||||
import {ElMessage} from "element-plus";
 | 
			
		||||
import {dateFormat, disabledDate, removeArrayItem} from "@/utils/libs";
 | 
			
		||||
import {InfoFilled, Plus} from "@element-plus/icons-vue";
 | 
			
		||||
import {InfoFilled, Plus, ShoppingCart} from "@element-plus/icons-vue";
 | 
			
		||||
 | 
			
		||||
// 变量定义
 | 
			
		||||
const items = ref([])
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <div class="container user-list" v-loading="loading">
 | 
			
		||||
    <div class="handle-box">
 | 
			
		||||
      <el-input v-model="query.mobile" placeholder="手机号码" class="handle-input mr10"></el-input>
 | 
			
		||||
      <el-input v-model="query.username" placeholder="账号" class="handle-input mr10"></el-input>
 | 
			
		||||
      <el-button type="primary" :icon="Search" @click="handleSearch">搜索</el-button>
 | 
			
		||||
 | 
			
		||||
      <el-button type="success" :icon="Plus" @click="addUser">新增用户</el-button>
 | 
			
		||||
@@ -13,7 +13,7 @@
 | 
			
		||||
        <el-table-column type="selection" width="38"/>
 | 
			
		||||
        <el-table-column prop="mobile" label="账号">
 | 
			
		||||
          <template #default="scope">
 | 
			
		||||
            <span>{{ scope.row.mobile }}</span>
 | 
			
		||||
            <span>{{ scope.row.username }}</span>
 | 
			
		||||
            <el-image v-if="scope.row.vip" :src="vipImg" style="height: 20px;position: relative; top:5px; left: 5px"/>
 | 
			
		||||
          </template>
 | 
			
		||||
        </el-table-column>
 | 
			
		||||
@@ -69,7 +69,7 @@
 | 
			
		||||
        width="50%"
 | 
			
		||||
    >
 | 
			
		||||
      <el-form :model="user" label-width="100px" ref="userEditFormRef" :rules="rules">
 | 
			
		||||
        <el-form-item label="手机号:" prop="mobile">
 | 
			
		||||
        <el-form-item label="手机号:" prop="username">
 | 
			
		||||
          <el-input v-model="user.mobile" autocomplete="off"/>
 | 
			
		||||
        </el-form-item>
 | 
			
		||||
        <el-form-item v-if="add" label="密码:" prop="password">
 | 
			
		||||
@@ -150,7 +150,7 @@
 | 
			
		||||
    >
 | 
			
		||||
      <el-form label-width="100px" ref="userEditFormRef">
 | 
			
		||||
        <el-form-item label="账户:">
 | 
			
		||||
          <el-input v-model="pass.mobile" autocomplete="off" readonly disabled/>
 | 
			
		||||
          <el-input v-model="pass.username" autocomplete="off" readonly disabled/>
 | 
			
		||||
        </el-form-item>
 | 
			
		||||
 | 
			
		||||
        <el-form-item label="新密码:">
 | 
			
		||||
@@ -177,13 +177,13 @@ import {Plus, Search} from "@element-plus/icons-vue";
 | 
			
		||||
 | 
			
		||||
// 变量定义
 | 
			
		||||
const users = ref({page: 1, page_size: 15, items: []})
 | 
			
		||||
const query = ref({mobile: '', page: 1, page_size: 15})
 | 
			
		||||
const query = ref({username: '', page: 1, page_size: 15})
 | 
			
		||||
 | 
			
		||||
const title = ref('添加用户')
 | 
			
		||||
const vipImg = ref("/images/vip.png")
 | 
			
		||||
const add = ref(true)
 | 
			
		||||
const user = ref({chat_roles: [], chat_models: []})
 | 
			
		||||
const pass = ref({mobile: '', password: '', id: 0})
 | 
			
		||||
const pass = ref({username: '', password: '', id: 0})
 | 
			
		||||
const roles = ref([])
 | 
			
		||||
const models = ref([])
 | 
			
		||||
const showUserEditDialog = ref(false)
 | 
			
		||||
@@ -191,7 +191,7 @@ const showResetPassDialog = ref(false)
 | 
			
		||||
const rules = reactive({
 | 
			
		||||
  nickname: [{required: true, message: '请输入昵称', trigger: 'change',}],
 | 
			
		||||
  password: [{required: true, message: '请输入密码', trigger: 'change',}],
 | 
			
		||||
  mobile: [{required: true, message: '请输入手机号码', trigger: 'change',}],
 | 
			
		||||
  username: [{required: true, message: '请输入手机号码', trigger: 'change',}],
 | 
			
		||||
  calls: [
 | 
			
		||||
    {required: true, message: '请输入提问次数'},
 | 
			
		||||
    {type: 'number', message: '请输入有效数字'},
 | 
			
		||||
@@ -309,7 +309,7 @@ const handleSelectionChange = function (rows) {
 | 
			
		||||
const resetPass = (row) => {
 | 
			
		||||
  showResetPassDialog.value = true
 | 
			
		||||
  pass.value.id = row.id
 | 
			
		||||
  pass.value.mobile = row.mobile
 | 
			
		||||
  pass.value.username = row.mobile
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const doResetPass = () => {
 | 
			
		||||
 
 | 
			
		||||
@@ -73,8 +73,6 @@
 | 
			
		||||
      <van-field v-model="tmpChatTitle" label="" placeholder="请输入对话标题" class="field"/>
 | 
			
		||||
    </van-dialog>
 | 
			
		||||
 | 
			
		||||
    <bind-mobile v-if="isLogin" :show="showBindMobileDialog" :mobile="loginUser.mobile"
 | 
			
		||||
                 @hide="showBindMobileDialog = false"/>
 | 
			
		||||
  </div>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
@@ -86,7 +84,6 @@ import {checkSession} from "@/action/session";
 | 
			
		||||
import {router} from "@/router";
 | 
			
		||||
import {setChatConfig} from "@/store/chat";
 | 
			
		||||
import {removeArrayItem} from "@/utils/libs";
 | 
			
		||||
import BindMobile from "@/components/mobile/BindMobile.vue";
 | 
			
		||||
 | 
			
		||||
const title = ref("会话列表")
 | 
			
		||||
const chatName = ref("")
 | 
			
		||||
@@ -101,7 +98,6 @@ const roles = ref([])
 | 
			
		||||
const models = ref([])
 | 
			
		||||
const showPicker = ref(false)
 | 
			
		||||
const columns = ref([roles.value, models.value])
 | 
			
		||||
const showBindMobileDialog = ref(false)
 | 
			
		||||
const showEditChat = ref(false)
 | 
			
		||||
const item = ref({})
 | 
			
		||||
const tmpChatTitle = ref("")
 | 
			
		||||
 
 | 
			
		||||
@@ -52,9 +52,6 @@
 | 
			
		||||
              <el-col :span="12">
 | 
			
		||||
                <el-button type="primary" @click="showPasswordDialog = true">修改密码</el-button>
 | 
			
		||||
              </el-col>
 | 
			
		||||
              <el-col :span="12">
 | 
			
		||||
                <el-button type="primary" @click="showBindMobileDialog = true">绑定手机号</el-button>
 | 
			
		||||
              </el-col>
 | 
			
		||||
              <el-col :span="12">
 | 
			
		||||
                <el-button type="primary" v-if="enableReward" @click="showRewardDialog = true">加入众筹</el-button>
 | 
			
		||||
              </el-col>
 | 
			
		||||
@@ -72,8 +69,6 @@
 | 
			
		||||
      <login-dialog :show="showLoginDialog" @hide="showLoginDialog = false"/>
 | 
			
		||||
      <password-dialog v-if="isLogin" :show="showPasswordDialog" width="100%" @hide="showPasswordDialog = false"
 | 
			
		||||
                       @logout="logout"/>
 | 
			
		||||
      <bind-mobile v-if="isLogin" :show="showBindMobileDialog" width="100%" :mobile="user.mobile"
 | 
			
		||||
                   @hide="showBindMobileDialog = false"/>
 | 
			
		||||
      <reward-verify v-if="isLogin" :show="showRewardVerifyDialog" @hide="showRewardVerifyDialog = false"/>
 | 
			
		||||
      <el-dialog
 | 
			
		||||
          v-model="showRewardDialog"
 | 
			
		||||
@@ -135,11 +130,9 @@ import LoginDialog from "@/components/LoginDialog.vue";
 | 
			
		||||
import {checkSession} from "@/action/session";
 | 
			
		||||
import UserProfile from "@/components/UserProfile.vue";
 | 
			
		||||
import PasswordDialog from "@/components/PasswordDialog.vue";
 | 
			
		||||
import BindMobile from "@/components/BindMobile.vue";
 | 
			
		||||
import RewardVerify from "@/components/RewardVerify.vue";
 | 
			
		||||
import {useRouter} from "vue-router";
 | 
			
		||||
import {removeUserToken} from "@/store/session";
 | 
			
		||||
import UserOrder from "@/components/UserOrder.vue";
 | 
			
		||||
import CountDown from "@/components/CountDown.vue";
 | 
			
		||||
 | 
			
		||||
const listBoxHeight = window.innerHeight - 97
 | 
			
		||||
@@ -151,7 +144,6 @@ const enableReward = ref(false) // 是否启用众筹功能
 | 
			
		||||
const rewardImg = ref('/images/reward.png')
 | 
			
		||||
const qrcode = ref("")
 | 
			
		||||
const showPasswordDialog = ref(false);
 | 
			
		||||
const showBindMobileDialog = ref(false);
 | 
			
		||||
const showRewardDialog = ref(false);
 | 
			
		||||
const showRewardVerifyDialog = ref(false);
 | 
			
		||||
const text = ref("")
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user