User center page

This commit is contained in:
2024-04-21 12:20:06 +08:00
parent ee6e7324b2
commit 6b26cad796
23 changed files with 353 additions and 61 deletions

View File

@ -85,14 +85,14 @@ func GrantAuthContext(jti string) (models.AuthContext, error) {
var ctx models.AuthContext
// Query data from primary database
session, err := GetTicketWithToken(jti)
ticket, err := GetTicketWithToken(jti)
if err != nil {
return ctx, fmt.Errorf("invalid auth session: %v", err)
} else if err := session.IsAvailable(); err != nil {
return ctx, fmt.Errorf("unavailable auth session: %v", err)
return ctx, fmt.Errorf("invalid auth ticket: %v", err)
} else if err := ticket.IsAvailable(); err != nil {
return ctx, fmt.Errorf("unavailable auth ticket: %v", err)
}
user, err := GetAccount(session.AccountID)
user, err := GetAccount(ticket.AccountID)
if err != nil {
return ctx, fmt.Errorf("invalid account: %v", err)
}
@ -100,7 +100,7 @@ func GrantAuthContext(jti string) (models.AuthContext, error) {
// Every context should expires in some while
// Once user update their account info, this will have delay to update
ctx = models.AuthContext{
Ticket: session,
Ticket: ticket,
Account: user,
ExpiredAt: time.Now().Add(5 * time.Minute),
}

View File

@ -14,7 +14,7 @@ func DoAutoSignoff() {
duration := time.Duration(viper.GetInt64("security.auto_signoff_duration")) * time.Second
divider := time.Now().Add(-duration)
log.Debug().Time("before", divider).Msg("Now signing off sessions...")
log.Debug().Time("before", divider).Msg("Now signing off tickets...")
if tx := database.C.
Where("last_grant_at < ?", divider).

View File

@ -45,7 +45,7 @@ func NewTicket(user models.Account, ip, ua string) (models.AuthTicket, error) {
UserAgent: ua,
RequireMFA: requireMFA,
RequireAuthenticate: true,
ExpiredAt: lo.ToPtr(time.Now().Add(2 * time.Hour)),
ExpiredAt: nil,
AvailableAt: nil,
AccountID: user.ID,
}