[server] Allow not sending email for invite and password reset

This commit is contained in:
Abhishek Shroff
2025-05-26 10:03:38 +05:30
parent 4e91d350ee
commit 134d32a39f
2 changed files with 18 additions and 8 deletions

View File

@@ -2,6 +2,7 @@ package user
import (
"context"
"errors"
"fmt"
"os"
"strings"
@@ -72,21 +73,22 @@ func setupInviteCommand() *cobra.Command {
}
}
if b, _ := cmd.Flags().GetBool("no-email"); !b {
if err := mail.SendWelcomeEmail(u); err != nil {
return errors.New("unable to send welcome email: " + err.Error())
}
}
return nil
})
if err != nil {
fmt.Println("unable to create user: " + err.Error())
os.Exit(1)
}
fmt.Println("User created")
if mail.SendWelcomeEmail(u) != nil {
fmt.Println("unable to send email: " + err.Error())
os.Exit(1)
}
},
}
cmd.Flags().StringP("name", "n", "", "Full Name")
cmd.Flags().StringP("base-dir", "b", "/home", "Base directory for home")
cmd.Flags().BoolP("no-create-home", "M", false, "Do not make home directory")
cmd.Flags().Bool("no-email", false, "Do not send email")
return cmd
}

View File

@@ -25,11 +25,19 @@ func setupPasswordResetCommand() *cobra.Command {
} else if token, err := manager.CreateResetToken(user); err != nil {
fmt.Println("unable to create reset token: " + err.Error())
os.Exit(1)
} else if err := mail.SendPasswordResetEmail(user, token); err != nil {
fmt.Println("unable to send email: " + err.Error())
os.Exit(1)
} else {
if b, _ := cmd.Flags().GetBool("no-email"); b {
fmt.Println("Created password reset token: " + token)
} else {
if err := mail.SendPasswordResetEmail(user, token); err != nil {
fmt.Println("unable to send email: " + err.Error())
fmt.Println("Use --no-email print the reset token instead instad of sending it by email")
os.Exit(1)
}
}
}
},
}
cmd.Flags().Bool("no-email", false, "Do not send email")
return cmd
}