🔨 change path

This commit is contained in:
微凉
2021-10-28 12:37:31 +08:00
parent 55f683b12d
commit 98f7dffed9
5 changed files with 51 additions and 26 deletions

31
server/check.go Normal file
View File

@ -0,0 +1,31 @@
package server
import (
"fmt"
"github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils"
"github.com/gofiber/fiber/v2"
"gorm.io/gorm"
)
func Auth(ctx *fiber.Ctx) error {
token := ctx.Get("token")
password, err := model.GetSettingByKey("password")
if err != nil {
if err == gorm.ErrRecordNotFound {
return ErrorResp(ctx, fmt.Errorf("password not set"), 400)
}
return ErrorResp(ctx, err, 500)
}
if token != utils.GetMD5Encode(password.Value) {
return ErrorResp(ctx, fmt.Errorf("wrong password"), 401)
}
return ctx.Next()
}
func CheckAccount(ctx *fiber.Ctx) error {
if model.AccountsCount() == 0 {
return ErrorResp(ctx,fmt.Errorf("no accounts,please add one first"),1001)
}
return ctx.Next()
}