services

package
v0.0.0-...-40b64a3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2024 License: AGPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JwtAccessType  = "access"
	JwtRefreshType = "refresh"
)
View Source
const ConfirmRegistrationTemplate = `` /* 600-byte string literal not displayed */
View Source
const DeleteAccountTemplate = `` /* 704-byte string literal not displayed */
View Source
const EmailPasswordTemplate = `` /* 534-byte string literal not displayed */
View Source
const InternalTokenAudience = "solar-network"
View Source
const ResetPasswordTemplate = `` /* 515-byte string literal not displayed */

Variables

View Source
var EReader *sec.JwtReader
View Source
var EWriter *sec.JwtWriter

Functions

func ActiveTicket

func ActiveTicket(ticket models.AuthTicket) (models.AuthTicket, error)

func ActiveTicketWithPassword

func ActiveTicketWithPassword(ticket models.AuthTicket, password string) (models.AuthTicket, error)

func AddAuditRecord

func AddAuditRecord(operator models.Account, act, ip, ua string, metadata map[string]any)

AddAuditRecord to keep logs to make administrators' operations clear to query

func AddEvent

func AddEvent(user uint, event, target, ip, ua string)

AddEvent to keep operation logs by user themselves clear to query

func AddNotifySubscriber

func AddNotifySubscriber(user models.Account, provider, id, tk, ua string) (models.NotificationSubscriber, error)

func AddRealmMember

func AddRealmMember(user models.Account, affected models.Account, target models.Realm) error

func Authenticate

func Authenticate(sessionId uint) (ctx models.AuthTicket, perms map[string]any, err error)

func CacheAuthContext

func CacheAuthContext(sessionId uint) (models.AuthTicket, error)

func CacheNotificationPreference

func CacheNotificationPreference(prefs models.PreferenceNotification)

func CacheUserStatus

func CacheUserStatus(uid uint, status models.Status)

func CheckAbleToDeleteAccount

func CheckAbleToDeleteAccount(user models.Account) error

func CheckAbleToResetPassword

func CheckAbleToResetPassword(user models.Account) error

func CheckDailyCanSign

func CheckDailyCanSign(user models.Account) error

func CheckFactor

func CheckFactor(factor models.AuthFactor, code string) error

func CheckNotificationNotifiable

func CheckNotificationNotifiable(account models.Account, topic string) bool

func CheckNotificationNotifiableBatch

func CheckNotificationNotifiableBatch(accounts []models.Account, topic string) []bool

func ClearStatus

func ClearStatus(user models.Account) error

func ComparePermNode

func ComparePermNode(held any, required any) bool

func ConfirmAccount

func ConfirmAccount(code string) error

func ConfirmDeleteAccount

func ConfirmDeleteAccount(code string) error

func ConfirmResetPassword

func ConfirmResetPassword(code, newPassword string) error

func CountUserFactor

func CountUserFactor(userId uint) int64

func CreateAccount

func CreateAccount(name, nick, email, password string) (models.Account, error)

func DailySign

func DailySign(user models.Account) (models.SignRecord, error)

func DeleteAccount

func DeleteAccount(id uint) error

func DeleteRealm

func DeleteRealm(realm models.Realm) error

func DeleteRelationship

func DeleteRelationship(relationship models.AccountRelationship) error

func DetectRisk

func DetectRisk(user models.Account, ip, ua string) int

DetectRisk is used for detect user environment is suitable for no multifactorial authenticating or not. Return the remaining steps, value is from 1 to 2, may appear 3 if user enabled the third-authentication-factor.

func DoAutoDatabaseCleanup

func DoAutoDatabaseCleanup()

func DoAutoSignoff

func DoAutoSignoff()

func EditRealm

func EditRealm(realm models.Realm) (models.Realm, error)

func EditRelationship

func EditRelationship(relationship models.AccountRelationship) (models.AccountRelationship, error)

func EditStatus

func EditStatus(user models.Account, status models.Status) (models.Status, error)

func EncodeJwt

func EncodeJwt(id string, typ, sub, sed string, nonce *string, aud []string, exp time.Time, idTokenUser ...models.Account) (string, error)

func ExchangeOauthToken

func ExchangeOauthToken(clientId, clientSecret, redirectUri, token string) (idk, atk, rtk string, err error)

func ExchangeToken

func ExchangeToken(token string) (atk, rtk string, err error)

func FilterPermNodes

func FilterPermNodes(tree map[string]any, claims []string) map[string]any

func ForceConfirmAccount

func ForceConfirmAccount(user models.Account) error

func GetAbuseReport

func GetAbuseReport(id uint) (models.AbuseReport, error)

func GetAccount

func GetAccount(id uint) (models.Account, error)

func GetAccountList

func GetAccountList(id []uint) ([]models.Account, error)

func GetAccountWithName

func GetAccountWithName(alias string) (models.Account, error)

func GetAuthContext

func GetAuthContext(sessionId uint) (models.AuthTicket, error)

func GetAuthContextCacheKey

func GetAuthContextCacheKey(sessionId uint) string

func GetAuthPreference

func GetAuthPreference(account models.Account) (models.PreferenceAuth, error)

func GetBotCount

func GetBotCount(user models.Account) (int64, error)

func GetFactor

func GetFactor(id uint) (models.AuthFactor, error)

func GetFactorCode

func GetFactorCode(factor models.AuthFactor) (bool, error)

func GetNotificationPreference

func GetNotificationPreference(account models.Account) (models.PreferenceNotification, error)

func GetNotificationPreferenceCacheKey

func GetNotificationPreferenceCacheKey(accountId uint) string

func GetPasswordTypeFactor

func GetPasswordTypeFactor(userId uint) (models.AuthFactor, error)

func GetRealmMember

func GetRealmMember(userId uint, realmId uint) (models.RealmMember, error)

func GetRealmWithAlias

func GetRealmWithAlias(alias string) (models.Realm, error)

func GetRelationWithTwoNode

func GetRelationWithTwoNode(userId, relatedId uint, noPreload ...bool) (models.AccountRelationship, error)

func GetRelationship

func GetRelationship(otherId uint) (models.AccountRelationship, error)

func GetStatus

func GetStatus(uid uint) (models.Status, error)

func GetStatusCacheKey

func GetStatusCacheKey(uid uint) string

func GetStatusDisturbable

func GetStatusDisturbable(uid uint) error

func GetStatusOnline

func GetStatusOnline(uid uint) error

func GetThirdClient

func GetThirdClient(id string) (models.ThirdClient, error)

func GetThirdClientWithSecret

func GetThirdClientWithSecret(id, secret string) (models.ThirdClient, error)

func GetThirdClientWithUser

func GetThirdClientWithUser(id string, userId uint) (models.ThirdClient, error)

func GetTicket

func GetTicket(id uint) (models.AuthTicket, error)

func GetTicketWithToken

func GetTicketWithToken(tokenId string) (models.AuthTicket, error)

func GetTodayDailySign

func GetTodayDailySign(user models.Account) (models.SignRecord, error)

func GetToken

func GetToken(ticket models.AuthTicket) (atk, rtk string, err error)

func GetUserAccountGroup

func GetUserAccountGroup(user models.Account) ([]models.AccountGroup, error)

func GetUserOnline

func GetUserOnline(uid uint) bool

func GrantBadge

func GrantBadge(user models.Account, badge models.Badge) error

func HandleFriend

func HandleFriend(userA models.Account, userB models.Account, isAccept bool) error

func HasPermNode

func HasPermNode(perms map[string]any, requiredKey string, requiredValue any) bool

func HasPermNodeWithDefault

func HasPermNodeWithDefault(perms map[string]any, requiredKey string, requiredValue any, defaultValue any) bool

func HashPassword

func HashPassword(raw string) string

func InvalidAuthCacheWithUser

func InvalidAuthCacheWithUser(userId uint)

func ListAbuseReport

func ListAbuseReport(account models.Account) ([]models.AbuseReport, error)

func ListAllRelationship

func ListAllRelationship(user models.Account) ([]models.AccountRelationship, error)

func ListAvailableRealm

func ListAvailableRealm(user models.Account) ([]models.Realm, error)

func ListCommunityRealm

func ListCommunityRealm() ([]models.Realm, error)

func ListOwnedRealm

func ListOwnedRealm(user models.Account) ([]models.Realm, error)

func ListRealmMember

func ListRealmMember(realmId uint) ([]models.RealmMember, error)

func ListRelationshipWithFilter

func ListRelationshipWithFilter(user models.Account, status models.RelationshipStatus) ([]models.AccountRelationship, error)

func ListUserFactor

func ListUserFactor(userId uint) ([]models.AuthFactor, error)

func LookupAccount

func LookupAccount(probe string) (models.Account, error)

func NewAbuseReport

func NewAbuseReport(resource string, reason string, account models.Account) (models.AbuseReport, error)

func NewApiKey

func NewApiKey(user models.Account, key models.ApiKey, ip, ua string, claims []string) (models.ApiKey, error)

func NewBlockship

func NewBlockship(userA models.Account, userB models.Account) (models.AccountRelationship, error)

func NewBot

func NewBot(user models.Account, bot models.Account) (models.Account, error)

func NewFriend

func NewFriend(userA models.Account, userB models.Account, skipPending ...bool) (models.AccountRelationship, error)

func NewMagicToken

func NewMagicToken(mode models.MagicTokenType, assignTo *models.Account, expiredAt *time.Time) (models.MagicToken, error)

func NewNotification

func NewNotification(notification models.Notification) error

NewNotification will create a notification and push via the push method it Pleases provide the notification with the account field is not empty

func NewNotificationBatch

func NewNotificationBatch(notifications []models.Notification) error

func NewOauthTicket

func NewOauthTicket(
	user models.Account,
	client models.ThirdClient,
	claims, audiences []string,
	ip, ua string, nonce *string,
) (models.AuthTicket, error)

func NewRealm

func NewRealm(realm models.Realm, user models.Account) (models.Realm, error)

func NewStatus

func NewStatus(user models.Account, status models.Status) (models.Status, error)

func NewTicket

func NewTicket(user models.Account, ip, ua string) (models.AuthTicket, error)

func NotifyMagicToken

func NotifyMagicToken(token models.MagicToken) error

func PerformTicketCheck

func PerformTicketCheck(ticket models.AuthTicket, factor models.AuthFactor, code string) (models.AuthTicket, error)

func PickTicketAttempt

func PickTicketAttempt(user models.Account, ip string) (models.AuthTicket, error)

PickTicketAttempt is trying to pick up the ticket that hasn't completed but created by a same client (identify by ip address). Then the client can continue their journey to get ticket activated.

func PushNotification

func PushNotification(notification models.Notification, skipNotifiableCheck ...bool) error

PushNotification will push a notification to the user, via websocket, firebase, or APNs Please provide the notification with the account field is not empty

func PushNotificationBatch

func PushNotificationBatch(notifications []models.Notification, skipNotifiableCheck ...bool)

func RecycleUnConfirmAccount

func RecycleUnConfirmAccount()

func RefreshToken

func RefreshToken(token string) (atk, rtk string, err error)

func RemoveRealmMember

func RemoveRealmMember(user models.Account, affected models.Account, target models.Realm) error

func RequestDeleteAccount

func RequestDeleteAccount(user models.Account) error

func RequestResetPassword

func RequestResetPassword(user models.Account) error

func RevokeBadge

func RevokeBadge(badge models.Badge) error

func RollApiKey

func RollApiKey(key models.ApiKey) (models.ApiKey, error)

func RotateTicket

func RotateTicket(ticket models.AuthTicket, fullyRestart ...bool) (models.AuthTicket, error)

func SaveEventChanges

func SaveEventChanges()

SaveEventChanges runs every 60 seconds to save events / audits changes into the database

func SearchAccount

func SearchAccount(probe string) ([]models.Account, error)

func SetAccountLastSeen

func SetAccountLastSeen(uid uint) error

func UpdateAbuseReportStatus

func UpdateAbuseReportStatus(id uint, status, message string) error

func UpdateAuthPreference

func UpdateAuthPreference(account models.Account, config models.AuthConfig) (models.PreferenceAuth, error)

func UpdateNotificationPreference

func UpdateNotificationPreference(account models.Account, config map[string]bool) (models.PreferenceNotification, error)

func ValidateAccountName

func ValidateAccountName(val string, min, max int) bool

func ValidateMagicToken

func ValidateMagicToken(code string, mode models.MagicTokenType) (models.MagicToken, error)

func VerifyPassword

func VerifyPassword(text string, password string) bool

Types

type PayloadClaims

type PayloadClaims struct {
	jwt.RegisteredClaims

	// Internal Stuff
	SessionID string `json:"sed"`

	// ID Token Stuff
	Name  string `json:"name,omitempty"`
	Nick  string `json:"preferred_username,omitempty"`
	Email string `json:"email,omitempty"`

	// Additional Stuff
	AuthorizedParties string `json:"azp,omitempty"`
	Nonce             string `json:"nonce,omitempty"`
	Type              string `json:"typ"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL