Support Github and Gitea OAuth providers

هذا الالتزام موجود في:
Thomas Miceli
2023-04-17 14:25:39 +02:00
الأصل 47cbf5e7ef
التزام a6c5696ceb
10 ملفات معدلة مع 641 إضافات و20 حذوفات

عرض الملف

@@ -1,6 +1,12 @@
package models
import "time"
import (
"crypto/sha256"
"encoding/base64"
"golang.org/x/crypto/ssh"
"gorm.io/gorm"
"time"
)
type SSHKey struct {
ID uint `gorm:"primaryKey"`
@@ -13,6 +19,16 @@ type SSHKey struct {
User User `validate:"-" `
}
func (sshKey *SSHKey) BeforeCreate(tx *gorm.DB) error {
pubKey, _, _, _, err := ssh.ParseAuthorizedKey([]byte(sshKey.Content))
if err != nil {
return err
}
sha := sha256.Sum256(pubKey.Marshal())
sshKey.SHA = base64.StdEncoding.EncodeToString(sha[:])
return nil
}
func GetSSHKeysByUserID(userId uint) ([]*SSHKey, error) {
var sshKeys []*SSHKey
err := db.