Prepare for storing last server

master
HimbeerserverDE 2021-10-24 15:21:56 +02:00
parent 813d03a5c7
commit 89644e4702
No known key found for this signature in database
GPG Key ID: 1A651504791E6A8B
2 changed files with 19 additions and 0 deletions

View File

@ -25,6 +25,8 @@ type authBackend interface {
Exists(name string) bool
Passwd(name string) (salt, verifier []byte, err error)
SetPasswd(name string, salt, verifier []byte) error
LastSrv(name string) (string, error)
SetLastSrv(name, srv string) error
Timestamp(name string) (time.Time, error)
Import(in []user)
Export() ([]user, error)

View File

@ -52,6 +52,23 @@ func (a authFiles) SetPasswd(name string, salt, verifier []byte) error {
return nil
}
// LastSrv returns the last server a user was on.
func (a authFiles) LastSrv(name string) (string, error) {
os.Mkdir(Path("auth"), 0700)
os.Mkdir(Path("auth/", name), 0700)
srv, err := os.ReadFile(Path("auth/", name, "/last_server"))
return string(srv), err
}
// SetLastSrv sets the last server a user was on.
func (a authFiles) SetLastSrv(name, srv string) error {
os.Mkdir(Path("auth"), 0700)
os.Mkdir(Path("auth/", name), 0700)
return os.WriteFile(Path("auth/", name, "/last_server"), []byte(srv), 0600)
}
// Timestamp returns the last time an authentication entry was accessed
// or an error.
func (a authFiles) Timestamp(name string) (time.Time, error) {