2024-02-06 04:28:12 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-03-20 12:56:43 +00:00
|
|
|
|
2024-06-17 14:21:34 +00:00
|
|
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
|
|
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
2024-02-06 04:28:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func GetThirdClient(id string) (models.ThirdClient, error) {
|
|
|
|
var client models.ThirdClient
|
|
|
|
if err := database.C.Where(&models.ThirdClient{
|
|
|
|
Alias: id,
|
|
|
|
}).First(&client).Error; err != nil {
|
|
|
|
return client, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return client, nil
|
|
|
|
}
|
|
|
|
|
2024-08-24 15:49:19 +00:00
|
|
|
func GetThirdClientWithUser(id string, userId uint) (models.ThirdClient, error) {
|
|
|
|
var client models.ThirdClient
|
|
|
|
if err := database.C.Where(&models.ThirdClient{
|
|
|
|
Alias: id,
|
|
|
|
AccountID: &userId,
|
|
|
|
}).First(&client).Error; err != nil {
|
|
|
|
return client, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return client, nil
|
|
|
|
}
|
|
|
|
|
2024-02-06 04:28:12 +00:00
|
|
|
func GetThirdClientWithSecret(id, secret string) (models.ThirdClient, error) {
|
|
|
|
client, err := GetThirdClient(id)
|
|
|
|
if err != nil {
|
|
|
|
return client, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if client.Secret != secret {
|
|
|
|
return client, fmt.Errorf("invalid client secret")
|
|
|
|
}
|
|
|
|
|
|
|
|
return client, nil
|
|
|
|
}
|