feat(profile): implement yggdrasil profile signing
This commit is contained in:
@@ -94,3 +94,36 @@ func (r *UserRepository) CreateAccessToken(ctx context.Context, userID int, acce
|
||||
_, err := r.DB.ExecContext(ctx, query, userID, accessToken, clientToken)
|
||||
return err
|
||||
}
|
||||
|
||||
// GetProfileByUUID находит пользователя и его профиль по UUID.
|
||||
func (r *UserRepository) GetProfileByUUID(ctx context.Context, userUUID uuid.UUID) (*models.User, *models.Profile, error) {
|
||||
user := &models.User{UUID: userUUID}
|
||||
profile := &models.Profile{}
|
||||
var skinHash, capeHash sql.NullString // Используем NullString для полей, которые могут быть NULL
|
||||
|
||||
query := `
|
||||
SELECT u.id, u.username, p.skin_hash, p.cape_hash
|
||||
FROM users u
|
||||
JOIN profiles p ON u.id = p.user_id
|
||||
WHERE u.uuid = $1`
|
||||
|
||||
err := r.DB.QueryRowContext(ctx, query, userUUID).Scan(
|
||||
&user.ID, &user.Username, &skinHash, &capeHash,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, nil, ErrUserNotFound
|
||||
}
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if skinHash.Valid {
|
||||
profile.SkinHash = skinHash.String
|
||||
}
|
||||
if capeHash.Valid {
|
||||
profile.CapeHash = capeHash.String
|
||||
}
|
||||
|
||||
return user, profile, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user