You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/file/user.go

53 lines
1.0 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package file
import (
"github.com/veypi/OneAuth/cfg"
"github.com/veypi/OneAuth/models"
"github.com/veypi/OneAuth/oalib"
"net/http"
"strconv"
)
/**
* @name: user
* @author: veypi <i@veypi.com>
* @date: 2021-12-04 11:49
* @descriptionuser
**/
func userFileChecker(w http.ResponseWriter, r *http.Request) (prefix string, mountPoint string, ownerID string, actorID string, err error) {
user := &models.User{}
u, p, ok := r.BasicAuth()
if ok {
user.Username = u
err = cfg.DB().Where("username = ?", u).First(user).Error
if err != nil {
return
}
var isAuth bool
isAuth, err = user.CheckLogin(p)
if err != nil || !isAuth {
return
}
} else {
p := &oalib.PayLoad{}
h := r.Header.Get("auth_token")
ok, err = p.ParseToken(h, cfg.CFG.APPKey)
if !ok {
return
}
user.ID = p.ID
err = cfg.DB().Where("ID = ?", p.ID).First(user).Error
if err != nil {
return
}
}
if user.ID > 0 {
actorID = strconv.Itoa(int(user.ID))
ownerID = actorID
mountPoint = actorID
prefix = ""
return
}
return
}