Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 46s
- app/cmd/flag.go: 新增 MysqlDSNFlag(env MYSQL_DSN) - start/reset: 读取并传给 model.Init - model.Init 改为三选一:MySQL > PostgreSQL > SQLite - 新增 initMysql():连接池参数对齐 Postgres 那套(10/100、30m 生命周期) - order.go: return_url / notify_url 从 TEXT 改 VARCHAR(1024) MySQL 8 不允许 TEXT 列带 DEFAULT(Error 1101),改 varchar 三库通用 实测(真 mysql:8.0 容器):6 张表全部建出,bep_order 列类型符合预期
54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/urfave/cli/v3"
|
|
"github.com/v03413/bepusdt/app/model"
|
|
"github.com/v03413/bepusdt/app/task"
|
|
"github.com/v03413/bepusdt/app/utils"
|
|
"golang.org/x/crypto/bcrypt"
|
|
)
|
|
|
|
var Reset = &cli.Command{
|
|
Name: "reset",
|
|
Usage: "忘记密码时,此命令可重置账号密码登录入口",
|
|
Flags: []cli.Flag{SQLiteFlag, PostgresDSNFlag, MysqlDSNFlag},
|
|
Before: func(ctx context.Context, c *cli.Command) (context.Context, error) {
|
|
sqlite := c.String("sqlite")
|
|
postgres := c.String("postgres")
|
|
mysql := c.String("mysql")
|
|
if err := model.Init(sqlite, postgres, mysql); err != nil {
|
|
return ctx, fmt.Errorf("数据库初始化失败 %w", err)
|
|
}
|
|
|
|
return ctx, task.Init()
|
|
},
|
|
After: func(ctx context.Context, c *cli.Command) error {
|
|
model.Close()
|
|
|
|
return nil
|
|
},
|
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
|
hash := utils.Md5String(time.Now().String())
|
|
|
|
username := hash[8:16]
|
|
password := hash[0:8]
|
|
entrance := fmt.Sprintf("/%s", hash[10:20])
|
|
encrypt, _ := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
|
|
|
model.SetK(model.AdminSecure, entrance)
|
|
model.SetK(model.AdminUsername, username)
|
|
model.SetK(model.AdminPassword, string(encrypt))
|
|
|
|
fmt.Println("重置成功,对应信息如下:")
|
|
fmt.Printf("管理员账号:%s\n管理员密码:%s\n后台管理入口:%s\n", username, password, entrance)
|
|
fmt.Println("请妥善保存以上信息!")
|
|
fmt.Println("-------------------------------")
|
|
|
|
return nil
|
|
},
|
|
}
|