accounts

package
v1.7.21 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPasswordBusy = errors.New("password service is busy")

ErrPasswordBusy reports that the KDF admission queue stayed full for the whole wait window. It is deliberately distinct from "wrong password" so callers can answer "try again" instead of consuming a login attempt.

View Source
var (
	// TwoFactorIssuer 是认证器 App 里显示的发行方名称。
	// 必须是 Nekomari 而不是上游的 Komari Monitor:这个字符串会被用户永久保存在
	// 认证器里,写错品牌等于让每个用户都看到上游的名字。
	TwoFactorIssuer = "Nekomari"
)

Functions

func BindingExternalAccount

func BindingExternalAccount(uuid string, sso_id string) error

func CheckPassword

func CheckPassword(username, passwd string) (uuid string, success bool, err error)

CheckPassword 检查密码是否正确

密码正确返回用户 UUID 和 true;密码错误返回空字符串和 false。 KDF 并发槽位排队超时返回 ErrPasswordBusy,调用方必须把它当作「稍后重试」, 不能当作密码错误 —— 否则并发登录时所有人(含管理员)都会看到「密码错误」。

func CreateAccount

func CreateAccount(username, passwd string) (user models.User, err error)

func CreateAccountWithDB

func CreateAccountWithDB(db *gorm.DB, username, passwd string) (user models.User, err error)

func CreateSession

func CreateSession(uuid string, expires int, userAgent, ip, login_method string) (string, error)

CreateSession 创建新会话

func DeleteAccountByUsername

func DeleteAccountByUsername(username string) (err error)

func DeleteAccountByUsernameWithDB

func DeleteAccountByUsernameWithDB(db *gorm.DB, username string) (err error)

func DeleteAllSessions

func DeleteAllSessions() error

func DeleteOtherSessions added in v0.1.14

func DeleteOtherSessions(uuid, keep string) error

DeleteOtherSessions revokes every session of one account except keep. Replacing a second factor is an account-security change, so anyone else holding a session for that account must re-authenticate; the caller's own session survives so the change does not log the operator out of the page that made it.

func DeleteSession

func DeleteSession(session string) (err error)

DeleteSession 删除指定会话

func Disable2Fa

func Disable2Fa(uuid string) error

func Enable2Fa

func Enable2Fa(uuid, secret string) error

func ForceResetPassword

func ForceResetPassword(username, passwd string) (err error)

ForceResetPassword 强制重置用户密码

func Generate2Fa

func Generate2Fa() (string, image.Image, error)

func GetAllSessions

func GetAllSessions() (sessions []models.Session, err error)

GetAllSessions 获取所有会话

func GetSession

func GetSession(session string) (uuid string, err error)

GetSession 根据会话 ID 获取 UUID

func GetUserBySSO

func GetUserBySSO(ssoID string) (user models.User, err error)

通过 SSO 信息获取用户

func GetUserBySession

func GetUserBySession(session string) (models.User, error)

func GetUserByUUID

func GetUserByUUID(uuid string) (user models.User, err error)

func PasswordRetryAfter added in v0.1.14

func PasswordRetryAfter() time.Duration

PasswordRetryAfter is how long a caller should wait before retrying a check that returned ErrPasswordBusy.

func RemoveExpiredSessions

func RemoveExpiredSessions() error

func Replace2Fa added in v0.1.14

func Replace2Fa(uuid, secret, expected string) error

Replace2Fa overwrites an existing factor. It is only reachable from the password-authorised re-enrollment path (see Rebind2FA in web/api/admin): a lost authenticator cannot produce the code that /2fa/disable requires, so without a replacement path the only recovery was the disable2FA CLI command on the host. Callers must have established the account's identity first; this function deliberately performs no verification of its own.

The update is conditional on the factor still being the one the re-enrollment started against, so a pending token cannot clobber a factor that changed while it was outstanding.

func UnbindExternalAccount

func UnbindExternalAccount(uuid string) error

func UpdateLatest

func UpdateLatest(session, useragent, ip string) error

func UpdateUser

func UpdateUser(uuid string, name, password, sso_type *string) error

func Verify2Fa

func Verify2Fa(uuid, code string) (bool, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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