mirror of
https://github.com/hanzoai/mail.git
synced 2026-09-23 23:53:02 +00:00
Fork of github.com/mjl-/mox at 5656ca6d1b
(upstream v0.0.15 plus 55 commits).
Rename the module path in go.mod and the import paths in 268 Go files. Also
update the five scripts that "go install" the module (genwebsite.sh,
docker-release.sh, apidiff.sh, test-upgrade.sh, Dockerfile.release), which
would otherwise build upstream rather than this fork.
Add NOTICE recording the upstream project, author, license, and fork point,
and stating which license covers which files: MIT for the mox source and our
changes, MPL-2.0 for publicsuffix/public_suffix_list.txt alone, and the
vendored dependencies' own licenses under licenses/. Embed NOTICE so
"mail licenses" prints the lineage from the running binary. LICENSE.MIT,
LICENSE.MPLv2.0 and the licenses/ tree are preserved verbatim; no code is
relicensed.
The mox command name, config keys, data directory layout and website content
are unchanged. LLM.md records the fork point, the rename, what was left alone,
and the steps to stand the server up.
Co-authored-by: Hanzo Dev <[email protected]>
48 lines
1.7 KiB
Go
48 lines
1.7 KiB
Go
package webauth
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/hanzoai/mail/mlog"
|
|
"github.com/hanzoai/mail/store"
|
|
)
|
|
|
|
// AccountAuth is for user accounts, with username/password, and sessions stored in
|
|
// memory and in the database with lifetimes that are automatically extended.
|
|
var Accounts SessionAuth = accountSessionAuth{}
|
|
|
|
type accountSessionAuth struct{}
|
|
|
|
func (accountSessionAuth) login(ctx context.Context, log mlog.Log, username, password string) (valid, disabled bool, accName string, rerr error) {
|
|
acc, accName, err := store.OpenEmailAuth(log, username, password, true)
|
|
if err != nil && errors.Is(err, store.ErrUnknownCredentials) {
|
|
return false, false, accName, nil
|
|
} else if err != nil && errors.Is(err, store.ErrLoginDisabled) {
|
|
return false, true, accName, err // Returning error, for its message.
|
|
} else if err != nil {
|
|
return false, false, accName, err
|
|
}
|
|
defer func() {
|
|
err := acc.Close()
|
|
log.Check(err, "closing account")
|
|
}()
|
|
return true, false, accName, nil
|
|
}
|
|
|
|
func (accountSessionAuth) add(ctx context.Context, log mlog.Log, accountName string, loginAddress string) (sessionToken store.SessionToken, csrfToken store.CSRFToken, rerr error) {
|
|
return store.SessionAdd(ctx, log, accountName, loginAddress)
|
|
}
|
|
|
|
func (accountSessionAuth) use(ctx context.Context, log mlog.Log, accountName string, sessionToken store.SessionToken, csrfToken store.CSRFToken) (loginAddress string, rerr error) {
|
|
ls, err := store.SessionUse(ctx, log, accountName, sessionToken, csrfToken)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return ls.LoginAddress, nil
|
|
}
|
|
|
|
func (accountSessionAuth) remove(ctx context.Context, log mlog.Log, accountName string, sessionToken store.SessionToken) error {
|
|
return store.SessionRemove(ctx, log, accountName, sessionToken)
|
|
}
|