mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-03 01:41:44 +00:00
- **feat: add documentation and GitHub Actions workflow for publishing documentation** - **docs(concepts): add documentation for chain modules** - **refactor: Simplify session management with SQLite storage and remove deprecated code** - **refactor: Simplify database initialization and remove DatabaseContext** - **refactor: move connection handling logic to resolver package** - **feat: implement session management with database persistence** - **feat: Ensure config directory exists when creating database path** - **feat: Add SetUserHandle function to set user handle in session** - **feat: Add public methods to set session fields with database save** - **refactor: Remove unused session setter functions** - **feat: Add getter methods for all Session Model properties** - **feat: enhance Session model with user name details** - **feat: add Motr support and update UI elements** - **<no value>** - **feat: Add unique handle constraint and method to check handle existence** - **docs: update site URL to onsonr.dev** - **fix: correct import statement for database package** - **test: updated CI to run tests on pull requests and merge groups** - **docs: remove reference to develop branch in workflow** - **feat: add WebAuthn support for user registration** - **fix: correct smart account attenuation preset name** - **feat: add ComputeIssuerDID and ComputeSonrAddr functions to ucan package** - **test: add unit tests for MPC keyset and keyshare** - **feat: introduce new script to streamline GitHub issue creation**
169 lines
4.4 KiB
Go
169 lines
4.4 KiB
Go
package session
|
|
|
|
import (
|
|
"github.com/labstack/echo/v4"
|
|
"github.com/onsonr/sonr/pkg/gateway/internal/database"
|
|
)
|
|
|
|
// ╭───────────────────────────────────────────────────────╮
|
|
// │ DB Setter Functions │
|
|
// ╰───────────────────────────────────────────────────────╯
|
|
|
|
// SetUserHandle sets the user handle in the session
|
|
func SetUserHandle(c echo.Context, handle string) error {
|
|
sess, err := Get(c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
sess.Session().UserHandle = handle
|
|
return sess.db.Save(sess.Session()).Error
|
|
}
|
|
|
|
// SetFirstName sets the first name in the session
|
|
func SetFirstName(c echo.Context, name string) error {
|
|
sess, err := Get(c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
sess.Session().FirstName = name
|
|
return sess.db.Save(sess.Session()).Error
|
|
}
|
|
|
|
// SetLastInitial sets the last initial in the session
|
|
func SetLastInitial(c echo.Context, initial string) error {
|
|
sess, err := Get(c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
sess.Session().LastInitial = initial
|
|
return sess.db.Save(sess.Session()).Error
|
|
}
|
|
|
|
// SetVaultAddress sets the vault address in the session
|
|
func SetVaultAddress(c echo.Context, address string) error {
|
|
sess, err := Get(c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
sess.Session().VaultAddress = address
|
|
return sess.db.Save(sess.Session()).Error
|
|
}
|
|
|
|
// ╭───────────────────────────────────────────────────────╮
|
|
// │ DB Getter Functions │
|
|
// ╰───────────────────────────────────────────────────────╯
|
|
|
|
// GetID returns the session ID
|
|
func GetID(c echo.Context) (string, error) {
|
|
sess, err := Get(c)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return sess.Session().ID, nil
|
|
}
|
|
|
|
// GetBrowserName returns the browser name
|
|
func GetBrowserName(c echo.Context) (string, error) {
|
|
sess, err := Get(c)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return sess.Session().BrowserName, nil
|
|
}
|
|
|
|
// GetBrowserVersion returns the browser version
|
|
func GetBrowserVersion(c echo.Context) (string, error) {
|
|
sess, err := Get(c)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return sess.Session().BrowserVersion, nil
|
|
}
|
|
|
|
// GetUserArchitecture returns the user architecture
|
|
func GetUserArchitecture(c echo.Context) (string, error) {
|
|
sess, err := Get(c)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return sess.Session().UserArchitecture, nil
|
|
}
|
|
|
|
// GetPlatform returns the platform
|
|
func GetPlatform(c echo.Context) (string, error) {
|
|
sess, err := Get(c)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return sess.Session().Platform, nil
|
|
}
|
|
|
|
// GetPlatformVersion returns the platform version
|
|
func GetPlatformVersion(c echo.Context) (string, error) {
|
|
sess, err := Get(c)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return sess.Session().PlatformVersion, nil
|
|
}
|
|
|
|
// GetDeviceModel returns the device model
|
|
func GetDeviceModel(c echo.Context) (string, error) {
|
|
sess, err := Get(c)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return sess.Session().DeviceModel, nil
|
|
}
|
|
|
|
// GetUserHandle returns the user handle
|
|
func GetUserHandle(c echo.Context) (string, error) {
|
|
sess, err := Get(c)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return sess.Session().UserHandle, nil
|
|
}
|
|
|
|
// GetFirstName returns the first name
|
|
func GetFirstName(c echo.Context) (string, error) {
|
|
sess, err := Get(c)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return sess.Session().FirstName, nil
|
|
}
|
|
|
|
// GetLastInitial returns the last initial
|
|
func GetLastInitial(c echo.Context) (string, error) {
|
|
sess, err := Get(c)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return sess.Session().LastInitial, nil
|
|
}
|
|
|
|
// GetVaultAddress returns the vault address
|
|
func GetVaultAddress(c echo.Context) (string, error) {
|
|
sess, err := Get(c)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return sess.Session().VaultAddress, nil
|
|
}
|
|
|
|
// HandleExists checks if a handle already exists in any session
|
|
func HandleExists(c echo.Context, handle string) (bool, error) {
|
|
sess, err := Get(c)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
var count int64
|
|
if err := sess.db.Model(&database.Session{}).Where("user_handle = ?", handle).Count(&count).Error; err != nil {
|
|
return false, err
|
|
}
|
|
|
|
return count > 0, nil
|
|
}
|