2021-11-05 10:36:30 +00:00
|
|
|
package devicemngmt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-10-11 07:33:56 +00:00
|
|
|
"git.selly.red/Selly-Modules/logger"
|
2021-11-05 10:36:30 +00:00
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetUserIDByAuthToken ...
|
|
|
|
func (s Service) GetUserIDByAuthToken(authToken string) (userID string) {
|
|
|
|
var (
|
|
|
|
ctx = context.Background()
|
|
|
|
col = s.getDeviceCollection()
|
|
|
|
device = Device{}
|
|
|
|
cond = bson.M{
|
|
|
|
"authToken": authToken,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2021-11-26 10:24:14 +00:00
|
|
|
if authToken == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-11-05 10:36:30 +00:00
|
|
|
// Find
|
|
|
|
if err := col.FindOne(ctx, cond).Decode(&device); err != nil {
|
2021-11-10 10:08:39 +00:00
|
|
|
logger.Error("devicemngmt - getUserIDByAuthToken", logger.LogData{
|
2022-10-05 10:23:29 +00:00
|
|
|
Source: "devicemngmt.GetUserIDByAuthToken",
|
|
|
|
Message: err.Error(),
|
|
|
|
Data: authToken,
|
2021-11-05 10:36:30 +00:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-11-22 08:14:36 +00:00
|
|
|
userID = device.UserID.Hex()
|
2021-11-05 10:36:30 +00:00
|
|
|
return
|
|
|
|
}
|