9 5e70998a 2022-04-12 o type User struct {
11 5e70998a 2022-04-12 o password Password
14 5e70998a 2022-04-12 o type Password []byte
16 5e70998a 2022-04-12 o // A UserStore provides storage and authentication of users.
17 5e70998a 2022-04-12 o type UserStore interface {
18 5e70998a 2022-04-12 o // Change creates or updates the named user with the new password.
19 5e70998a 2022-04-12 o Change(name string, new Password) error
20 5e70998a 2022-04-12 o // Lookup returns the User with name.
21 5e70998a 2022-04-12 o // The error should be ErrUnknownUser if the user is not found.
22 5e70998a 2022-04-12 o Lookup(name string) (User, error)
23 5e70998a 2022-04-12 o // Delete removes the user from the store.
24 5e70998a 2022-04-12 o Delete(name string) error
25 5e70998a 2022-04-12 o //Authenticate(username, password string) (ticket string, err error)
28 5e70998a 2022-04-12 o type ticket []byte
30 5e70998a 2022-04-12 o var testTicket = []byte(`TEST NOT REAL`)
33 5e70998a 2022-04-12 o ErrUserExist = errors.New("user already exists")
34 5e70998a 2022-04-12 o ErrUnknownUser = errors.New("unknown user")
37 5e70998a 2022-04-12 o // verified checks whether ownership of username's address has
38 5e70998a 2022-04-12 o // been confirmed.
39 5e70998a 2022-04-12 o // func (store *astore) verified(username string) (bool, error) {
40 5e70998a 2022-04-12 o // _, err := store.Lookup(username)
41 5e70998a 2022-04-12 o // if errors.Is(err, ErrUnknownUser) {
42 5e70998a 2022-04-12 o // return false, err
45 5e70998a 2022-04-12 o // _, err = os.Stat(path.Join(store.confirmDir, username))
46 5e70998a 2022-04-12 o // if err == nil {
47 5e70998a 2022-04-12 o // return false, nil
49 5e70998a 2022-04-12 o // if errors.Is(err, fs.ErrNotExist) {
50 5e70998a 2022-04-12 o // return true, nil
52 5e70998a 2022-04-12 o // return false, fmt.Errorf("check confirm file: %w", err)
55 5e70998a 2022-04-12 o // verify attempts to verify the username using the given token.
56 5e70998a 2022-04-12 o // func (store *astore) verify(username string, tok token) error {
57 5e70998a 2022-04-12 o // f, err := os.Open(path.Join(store.confirmDir, username))
58 5e70998a 2022-04-12 o // if errors.Is(err, fs.ErrNotExist) {
59 5e70998a 2022-04-12 o // return ErrUnknownUser
60 5e70998a 2022-04-12 o // } else if err != nil {
63 5e70998a 2022-04-12 o // defer f.Close()
64 5e70998a 2022-04-12 o // b, err := io.ReadAll(f)
65 5e70998a 2022-04-12 o // if err != nil {
68 5e70998a 2022-04-12 o // if bytes.Equal(b, []byte(tok)) {
69 5e70998a 2022-04-12 o // return os.Remove(path.Join(store.confirmDir, username))
71 5e70998a 2022-04-12 o // return errors.New("mismatched token")
74 5e70998a 2022-04-12 o func SendConfirmationMail(from, to string, tik ticket) error {
78 5e70998a 2022-04-12 o // Subject: Confirm address ownership
80 5e70998a 2022-04-12 o // Thanks for signing up to mailmux.net!
81 5e70998a 2022-04-12 o // Confirm ownership of $address by accessing the following link:
82 5e70998a 2022-04-12 o // https://mailmux.net/confirm?username=test@example.com&token=abcd12345
83 5e70998a 2022-04-12 o // Alternatively, go to https://mailmux.net/confirm
84 5e70998a 2022-04-12 o // enter your email address and your token:
87 5e70998a 2022-04-12 o // If you have not signed up for mailmux.net, please
88 5e70998a 2022-04-12 o // let us know by forwarding this mail to abuse@mailmux.net.
89 5e70998a 2022-04-12 o // Thank you for helping us fight spam!