0302-добавил куки и сломал десктоп авторизацию.

сложно поддерживать однояйцевых близнецов - desktop и TMA, подготовил к рефакторингу структуры
This commit is contained in:
2026-02-03 09:32:02 +03:00
parent 88620f3fb6
commit ea1e5bbf6a
14 changed files with 547 additions and 86 deletions

View File

@@ -53,6 +53,7 @@ func NewPostgresDB(dsn string) *gorm.DB {
&account.User{},
&account.RMSServer{},
&account.ServerUser{},
&account.Session{},
&billing.Order{},
&catalog.Product{},
&catalog.MeasureUnit{},

View File

@@ -552,3 +552,32 @@ func (r *pgRepository) SetMuteDraftNotifications(userID, serverID uuid.UUID, mut
Where("user_id = ? AND server_id = ?", userID, serverID).
Update("mute_draft_notifications", mute).Error
}
// === Session Management ===
// CreateSession создает новую сессию пользователя
func (r *pgRepository) CreateSession(session *account.Session) error {
return r.db.Create(session).Error
}
// GetSessionByToken ищет сессию по токену
func (r *pgRepository) GetSessionByToken(token string) (*account.Session, error) {
var session account.Session
if err := r.db.Where("refresh_token = ?", token).First(&session).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
return nil, err
}
return &session, nil
}
// UpdateSessionExpiry обновляет время истечения сессии (sliding expiration)
func (r *pgRepository) UpdateSessionExpiry(sessionID uuid.UUID, newExpiry time.Time) error {
return r.db.Model(&account.Session{}).Where("id = ?", sessionID).Update("expires_at", newExpiry).Error
}
// DeleteSession удаляет сессию по токену
func (r *pgRepository) DeleteSession(token string) error {
return r.db.Where("refresh_token = ?", token).Delete(&account.Session{}).Error
}