Make IMAP and SMTP sessions check for passwords
This commit is contained in:
@@ -2,6 +2,7 @@ package imap
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"sync/atomic"
|
||||
@@ -70,14 +71,21 @@ func (c *concrete) Run() {
|
||||
|
||||
// backend implementation for go-imap
|
||||
func (c *concrete) Login(user, pass string) (imapbackend.User, error) {
|
||||
// FIXME: TODO: Check for account existence and correct password(!)
|
||||
account, err := c.store.FindAccountWithPassword(user, pass)
|
||||
if err != nil {
|
||||
// Lo the real error, but don't show it to the end user
|
||||
log.Printf("Opening %s session for %s failed: %s", c.name, user, err)
|
||||
return nil, fmt.Errorf("Login failed")
|
||||
}
|
||||
|
||||
session := &Session{
|
||||
ID: atomic.AddUint64(&c.sid, uint64(1)),
|
||||
AccountName: user,
|
||||
Account: account,
|
||||
ServiceName: c.name,
|
||||
}
|
||||
|
||||
log.Printf("Beginning %s session %d for %s", c.name, session.ID, user)
|
||||
// FIXME: TODO: Track ongoing sessions for termination or notifications
|
||||
|
||||
return session, nil
|
||||
}
|
||||
|
@@ -5,6 +5,8 @@ import (
|
||||
"log"
|
||||
|
||||
imapbackend "github.com/emersion/go-imap/backend"
|
||||
|
||||
"ur.gs/crockery/internal/store"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -14,12 +16,12 @@ var (
|
||||
// type Session implements the User interface for emersion/go-imap
|
||||
type Session struct {
|
||||
ID uint64
|
||||
AccountName string
|
||||
Account *store.Account
|
||||
ServiceName string
|
||||
}
|
||||
|
||||
func (s *Session) Username() string {
|
||||
return s.AccountName
|
||||
return s.Account.Username
|
||||
}
|
||||
|
||||
func (s *Session) ListMailboxes(subscribed bool) ([]imapbackend.Mailbox, error) {
|
||||
@@ -43,7 +45,7 @@ func (s *Session) RenameMailbox(existingName, newName string) error {
|
||||
}
|
||||
|
||||
func (s *Session) Logout() error {
|
||||
log.Printf("Ending %s session %d for %s", s.ServiceName, s.ID, s.AccountName)
|
||||
log.Printf("Ending %s session %d for %s", s.ServiceName, s.ID, s.Username())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user