alist/server/middlewares/auth.go

27 lines
591 B
Go
Raw Normal View History

2021-12-07 07:56:43 +00:00
package middlewares
import (
2021-12-07 12:16:34 +00:00
"github.com/Xhofe/alist/conf"
2021-12-07 07:56:43 +00:00
"github.com/Xhofe/alist/server/common"
"github.com/gin-gonic/gin"
)
func Auth(c *gin.Context) {
token := c.GetHeader("Authorization")
2021-12-07 12:16:34 +00:00
//password, err := model.GetSettingByKey("password")
//if err != nil {
// if err == gorm.ErrRecordNotFound {
// common.ErrorResp(c, fmt.Errorf("password not set"), 400)
// return
// }
// common.ErrorResp(c, err, 500)
// return
//}
//if token != utils.GetMD5Encode(password.Value) {
if token != conf.Token {
2022-01-13 13:23:27 +00:00
common.ErrorStrResp(c, "Wrong password", 401)
2021-12-07 07:56:43 +00:00
return
}
c.Next()
2022-01-13 13:23:27 +00:00
}